Skip to content

Commit

Permalink
[core] Fixed uninitialized DST socket ID in SHUTDOWN ctrl message
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Aug 6, 2021
1 parent 6dcbaf0 commit 896cc92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
11 changes: 9 additions & 2 deletions srtcore/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,21 @@ friend class CRendezvousQueue;
CEPoll& epoll_ref() { return m_EPoll; }

private:
// void init();

/// Generates a new socket ID. This function starts from a randomly
/// generated value (at initialization time) and goes backward with
/// with next calls. The possible values come from the range without
/// the SRTGROUP_MASK bit, and the group bit is set when the ID is
/// generated for groups. It is also internally checked if the
/// newly generated ID isn't already used by an existing socket or group.
///
/// Socket ID value range.
/// - [0]: reserved for handshake procedure. If the destination Socket ID is 0
/// (destination Socket ID unknown) the packet will be sent to the listening socket
/// or to a socket that is in the rendezvous connection phase.
/// - [1; 2 ^ 30): single socket ID range.
/// - (2 ^ 30; 2 ^ 31): group socket ID range. Effectively any positive number
/// from [1; 2 ^ 30) with bit 30 set to 1. Bit 31 is zero.
/// The most significant bit 31 (sign bit) is left unused so that checking for a value <= 0 identifies an invalid socket ID.
///
/// @param group The socket id should be for socket group.
/// @return The new socket ID.
Expand Down
9 changes: 6 additions & 3 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ void srt::CUDT::construct()
// Will be reset to 0 for HSv5, this value is important for HSv4.
m_iSndHsRetryCnt = SRT_MAX_HSRETRY + 1;

m_PeerID = 0;
m_bOpened = false;
m_bListening = false;
m_bConnecting = false;
Expand Down Expand Up @@ -3784,9 +3785,9 @@ bool srt::CUDT::processAsyncConnectRequest(EReadStatus rst,
{
// m_RejectReason already set at worker_ProcessAddressedPacket.
LOGC(cnlog.Warn,
log << "processAsyncConnectRequest: REJECT reported from HS processing:"
log << "processAsyncConnectRequest: REJECT reported from HS processing: "
<< srt_rejectreason_str(m_RejectReason)
<< "- not processing further"); //; REQ-TIME LOW"); XXX ?
<< " - not processing further");
// m_tsLastReqTime = steady_clock::time_point(); XXX ?
return false;
}
Expand Down Expand Up @@ -5957,7 +5958,7 @@ bool srt::CUDT::closeInternal()
{
if (!m_bShutdown)
{
HLOGC(smlog.Debug, log << CONID() << "CLOSING - sending SHUTDOWN to the peer");
HLOGC(smlog.Debug, log << CONID() << "CLOSING - sending SHUTDOWN to the peer @" << m_PeerID);
sendCtrl(UMSG_SHUTDOWN);
}

Expand Down Expand Up @@ -7615,6 +7616,8 @@ void srt::CUDT::sendCtrl(UDTMessageType pkttype, const int32_t* lparam, void* rp
break;

case UMSG_SHUTDOWN: // 101 - Shutdown
if (m_PeerID == 0) // Dont't send SHUTDOWN if we don't know peer ID.
break;
ctrlpkt.pack(pkttype);
ctrlpkt.m_iID = m_PeerID;
nbsent = m_pSndQueue->sendto(m_PeerAddr, ctrlpkt);
Expand Down
2 changes: 1 addition & 1 deletion srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ class CUDT
private: // Trace
struct CoreStats
{
time_point tsStartTime; // timestamp when the UDT entity is started
time_point tsStartTime; // timestamp when the UDT entity is started
int64_t sentTotal; // total number of sent data packets, including retransmissions
int64_t sentUniqTotal; // total number of sent data packets, excluding rexmit and filter control
int64_t recvTotal; // total number of received packets
Expand Down

0 comments on commit 896cc92

Please sign in to comment.