diff --git a/srtcore/buffer_snd.cpp b/srtcore/buffer_snd.cpp index b59284545..3d4e01fa3 100644 --- a/srtcore/buffer_snd.cpp +++ b/srtcore/buffer_snd.cpp @@ -162,7 +162,7 @@ void CRateEstimator::updateInputRate(const time_point& time, int pkts, int bytes } } -CSndBuffer::CSndBuffer(int size, int maxpld) +CSndBuffer::CSndBuffer(int size, int maxpld, int authtag) : m_BufLock() , m_pBlock(NULL) , m_pFirstBlock(NULL) @@ -172,6 +172,7 @@ CSndBuffer::CSndBuffer(int size, int maxpld) , m_iNextMsgNo(1) , m_iSize(size) , m_iBlockLen(maxpld) + , m_iAuthTagSize(authtag) , m_iCount(0) , m_iBytesCount(0) { @@ -233,7 +234,7 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl) int32_t& w_seqno = w_mctrl.pktseq; int64_t& w_srctime = w_mctrl.srctime; const int& ttl = w_mctrl.msgttl; - const int iPktLen = m_iBlockLen; // Payload length per packet. + const int iPktLen = m_iBlockLen - m_iAuthTagSize; // Payload length per packet. int iNumBlocks = len / iPktLen; if ((len % m_iBlockLen) != 0) ++iNumBlocks; @@ -336,7 +337,7 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl) int CSndBuffer::addBufferFromFile(fstream& ifs, int len) { - const int iPktLen = m_iBlockLen; // Payload length per packet. + const int iPktLen = m_iBlockLen - m_iAuthTagSize; // Payload length per packet. int iNumBlocks = len / iPktLen; if ((len % m_iBlockLen) != 0) ++iNumBlocks; @@ -416,7 +417,7 @@ int CSndBuffer::readData(CPacket& w_packet, steady_clock::time_point& w_srctime, // Make the packet REFLECT the data stored in the buffer. w_packet.m_pcData = m_pCurrBlock->m_pcData; readlen = m_pCurrBlock->m_iLength; - w_packet.setLength(readlen); + w_packet.setLength(readlen, m_iBlockLen); w_packet.m_iSeqNo = m_pCurrBlock->m_iSeqNo; // 1. On submission (addBuffer), the KK flag is set to EK_NOENC (0). @@ -589,7 +590,7 @@ int CSndBuffer::readData(const int offset, CPacket& w_packet, steady_clock::time w_packet.m_pcData = p->m_pcData; const int readlen = p->m_iLength; - w_packet.setLength(readlen); + w_packet.setLength(readlen, m_iBlockLen); // XXX Here the value predicted to be applied to PH_MSGNO field is extracted. // As this function is predicted to extract the data to send as a rexmited packet, diff --git a/srtcore/buffer_snd.h b/srtcore/buffer_snd.h index ac4e85b3d..d462bbd8d 100644 --- a/srtcore/buffer_snd.h +++ b/srtcore/buffer_snd.h @@ -157,8 +157,9 @@ class CSndBuffer /// @brief CSndBuffer constructor. /// @param size initial number of blocks (each block to store one packet payload). - /// @param maxpld maximum packet payload. - CSndBuffer(int size = 32, int maxpld = 1500); + /// @param maxpld maximum packet payload (including auth tag). + /// @param authtag auth tag length in bytes (16 for GCM, 0 otherwise). + CSndBuffer(int size = 32, int maxpld = 1500, int authtag = 0); ~CSndBuffer(); public: @@ -259,7 +260,7 @@ class CSndBuffer struct Block { char* m_pcData; // pointer to the data block - int m_iLength; // payload length of the block. + int m_iLength; // payload length of the block (excluding auth tag). int32_t m_iMsgNoBitset; // message number int32_t m_iSeqNo; // sequence number for scheduling @@ -295,7 +296,8 @@ class CSndBuffer int32_t m_iNextMsgNo; // next message number int m_iSize; // buffer size (number of packets) - const int m_iBlockLen; // maximum length of a block holding packet payload (excluding packet header). + const int m_iBlockLen; // maximum length of a block holding packet payload and AUTH tag (excluding packet header). + const int m_iAuthTagSize; // Authentication tag size (if GCM is enabled). int m_iCount; // number of used blocks int m_iBytesCount; // number of payload bytes in queue