Skip to content

Commit ac854f2

Browse files
committed
[core] Fixed setting the peer rexmit flag on the RCV buffer
1 parent 5b7ac45 commit ac854f2

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

srtcore/buffer_rcv.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace {
7070
* m_iMaxPosInc: none? (modified on add and ack
7171
*/
7272

73-
CRcvBufferNew::CRcvBufferNew(int initSeqNo, size_t size, CUnitQueue* unitqueue, bool peerRexmit, bool bMessageAPI)
73+
CRcvBufferNew::CRcvBufferNew(int initSeqNo, size_t size, CUnitQueue* unitqueue, bool bMessageAPI)
7474
: m_entries(size)
7575
, m_szSize(size) // TODO: maybe just use m_entries.size()
7676
, m_pUnitQueue(unitqueue)
@@ -81,7 +81,7 @@ CRcvBufferNew::CRcvBufferNew(int initSeqNo, size_t size, CUnitQueue* unitqueue,
8181
, m_iNotch(0)
8282
, m_numOutOfOrderPackets(0)
8383
, m_iFirstReadableOutOfOrder(-1)
84-
, m_bPeerRexmitFlag(peerRexmit)
84+
, m_bPeerRexmitFlag(true)
8585
, m_bMessageAPI(bMessageAPI)
8686
, m_iBytesCount(0)
8787
, m_iPktsCount(0)

srtcore/buffer_rcv.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CRcvBufferNew
5151
typedef sync::steady_clock::duration duration;
5252

5353
public:
54-
CRcvBufferNew(int initSeqNo, size_t size, CUnitQueue* unitqueue, bool peerRexmit, bool bMessageAPI);
54+
CRcvBufferNew(int initSeqNo, size_t size, CUnitQueue* unitqueue, bool bMessageAPI);
5555

5656
~CRcvBufferNew();
5757

@@ -308,7 +308,7 @@ class CRcvBufferNew
308308
size_t m_numOutOfOrderPackets; // The number of stored packets with "inorder" flag set to false
309309
int m_iFirstReadableOutOfOrder; // In case of out ouf order packet, points to a position of the first such packet to
310310
// read
311-
const bool m_bPeerRexmitFlag; // Needed to read message number correctly
311+
bool m_bPeerRexmitFlag; // Needed to read message number correctly
312312
const bool m_bMessageAPI; // Operation mode flag: message or stream.
313313

314314
public: // TSBPD public functions
@@ -320,6 +320,8 @@ class CRcvBufferNew
320320
/// @return 0
321321
void setTsbPdMode(const time_point& timebase, bool wrap, duration delay);
322322

323+
void setPeerRexmitFlag(bool flag) { m_bPeerRexmitFlag = flag; }
324+
323325
void applyGroupTime(const time_point& timebase, bool wrp, uint32_t delay, const duration& udrift);
324326

325327
void applyGroupDrift(const time_point& timebase, bool wrp, const duration& udrift);

srtcore/core.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ bool srt::CUDT::interpretSrtHandshake(const CHandShake& hs,
24142414
}
24152415

24162416
// We still believe it should work, let's check the flags.
2417-
int ext_flags = SrtHSRequest::SRT_HSTYPE_HSFLAGS::unwrap(hs.m_iType);
2417+
const int ext_flags = SrtHSRequest::SRT_HSTYPE_HSFLAGS::unwrap(hs.m_iType);
24182418
if (ext_flags == 0)
24192419
{
24202420
m_RejectReason = SRT_REJ_ROGUE;
@@ -4019,15 +4019,16 @@ EConnectStatus srt::CUDT::processRendezvous(
40194019
m_ConnReq.m_iReqType = rsp_type;
40204020
m_ConnReq.m_extension = needs_extension;
40214021

4022-
// This must be done before prepareConnectionObjects().
4022+
// This must be done before prepareConnectionObjects(), because it sets ISN and m_iMaxSRTPayloadSize needed to create buffers.
40234023
if (!applyResponseSettings())
40244024
{
40254025
LOGC(cnlog.Error, log << "processRendezvous: rogue peer");
40264026
return CONN_REJECT;
40274027
}
40284028

4029-
// This must be done before interpreting and creating HSv5 extensions.
4030-
if (!prepareConnectionObjects(m_ConnRes, m_SrtHsSide, 0))
4029+
// The CryptoControl must be created by the prepareConnectionObjects() before interpreting and creating HSv5 extensions
4030+
// because the it will be used there.
4031+
if (!prepareConnectionObjects(m_ConnRes, m_SrtHsSide, NULL))
40314032
{
40324033
// m_RejectReason already handled
40334034
HLOGC(cnlog.Debug, log << "processRendezvous: rejecting due to problems in prepareConnectionObjects.");
@@ -4536,6 +4537,7 @@ EConnectStatus srt::CUDT::postConnect(const CPacket* pResponse, bool rendezvous,
45364537
// however in this case the HSREQ extension will not be attached,
45374538
// so it will simply go the "old way".
45384539
// (&&: skip if failed already)
4540+
// Must be called before interpretSrtHandshake() to create the CryptoControl.
45394541
ok = ok && prepareConnectionObjects(m_ConnRes, m_SrtHsSide, eout);
45404542

45414543
// May happen that 'response' contains a data packet that was sent in rendezvous mode.
@@ -5568,11 +5570,8 @@ bool srt::CUDT::prepareConnectionObjects(const CHandShake &hs, HandshakeSide hsd
55685570
return true;
55695571
}
55705572

5571-
bool bidirectional = false;
5572-
if (hs.m_iVersion > HS_VERSION_UDT4)
5573-
{
5574-
bidirectional = true; // HSv5 is always bidirectional
5575-
}
5573+
// HSv5 is always bidirectional
5574+
const bool bidirectional = (hs.m_iVersion > HS_VERSION_UDT4);
55765575

55775576
// HSD_DRAW is received only if this side is listener.
55785577
// If this side is caller with HSv5, HSD_INITIATOR should be passed.
@@ -5595,7 +5594,7 @@ bool srt::CUDT::prepareConnectionObjects(const CHandShake &hs, HandshakeSide hsd
55955594
m_pSndBuffer = new CSndBuffer(32, m_iMaxSRTPayloadSize);
55965595
#if ENABLE_NEW_RCVBUFFER
55975596
SRT_ASSERT(m_iISN != -1);
5598-
m_pRcvBuffer = new srt::CRcvBufferNew(m_iISN, m_config.iRcvBufSize, &(m_pRcvQueue->m_UnitQueue), m_bPeerRexmitFlag, m_config.bMessageAPI);
5597+
m_pRcvBuffer = new srt::CRcvBufferNew(m_iISN, m_config.iRcvBufSize, &(m_pRcvQueue->m_UnitQueue), m_config.bMessageAPI);
55995598
#else
56005599
m_pRcvBuffer = new CRcvBuffer(&(m_pRcvQueue->m_UnitQueue), m_config.iRcvBufSize);
56015600
#endif
@@ -8982,6 +8981,7 @@ void srt::CUDT::updateSrtRcvSettings()
89828981
enterCS(m_RecvLock);
89838982
#if ENABLE_NEW_RCVBUFFER
89848983
m_pRcvBuffer->setTsbPdMode(m_tsRcvPeerStartTime, false, milliseconds_from(m_iTsbPdDelay_ms));
8984+
m_pRcvBuffer->setPeerRexmitFlag(m_bPeerRexmitFlag);
89858985
#else
89868986
m_pRcvBuffer->setRcvTsbPdMode(m_tsRcvPeerStartTime, milliseconds_from(m_iTsbPdDelay_ms));
89878987
#endif

srtcore/core.h

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ class CUDT
489489
SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock)
490490
EConnectStatus processRendezvous(const CPacket* response, const sockaddr_any& serv_addr, EReadStatus, CPacket& reqpkt);
491491

492+
/// Create the CryptoControl object based on the HS packet. Allocates sender and receiver buffers and loss lists.
492493
SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock)
493494
bool prepareConnectionObjects(const CHandShake &hs, HandshakeSide hsd, CUDTException *eout);
494495

test/test_buffer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class CRcvBufferReadMsg
3434
#if ENABLE_NEW_RCVBUFFER
3535
const bool enable_msg_api = m_use_message_api;
3636
const bool enable_peer_rexmit = true;
37-
m_rcv_buffer = unique_ptr<CRcvBufferNew>(new CRcvBufferNew(m_init_seqno, m_buff_size_pkts, m_unit_queue.get(), enable_peer_rexmit, enable_msg_api));
37+
m_rcv_buffer = unique_ptr<CRcvBufferNew>(new CRcvBufferNew(m_init_seqno, m_buff_size_pkts, m_unit_queue.get(), enable_msg_api));
38+
m_rcv_buffer->setPeerRexmitFlag(enable_peer_rexmit);
3839
#else
3940
m_rcv_buffer = unique_ptr<CRcvBuffer>(new CRcvBuffer(m_unit_queue.get(), m_buff_size_pkts));
4041
#endif

0 commit comments

Comments
 (0)