Skip to content

Commit

Permalink
[core] Annotating CUDT::m_pCryptoControl locking behavior (#2070)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko authored Aug 3, 2021
1 parent 8f169a9 commit 1a85c02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
11 changes: 4 additions & 7 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,14 +1497,11 @@ bool srt::CUDT::createSrtHandshake(
w_hs.m_iType |= CHandShake::HS_EXT_HSREQ;

bool have_sid = false;
if (srths_cmd == SRT_CMD_HSREQ)
if (srths_cmd == SRT_CMD_HSREQ && !m_config.sStreamName.empty())
{
if (!m_config.sStreamName.empty())
{
have_sid = true;
w_hs.m_iType |= CHandShake::HS_EXT_CONFIG;
logext << ",SID";
}
have_sid = true;
w_hs.m_iType |= CHandShake::HS_EXT_CONFIG;
logext << ",SID";
}

// If this is a response, we have also information
Expand Down
22 changes: 16 additions & 6 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ class CUDT
static std::vector<SRTSOCKET> existingSockets();

void addressAndSend(CPacket& pkt);

SRT_ATTR_REQUIRES(m_ConnectionLock)
void sendSrtMsg(int cmd, uint32_t *srtdata_in = NULL, size_t srtlen_in = 0);

bool isOPT_TsbPd() const { return m_config.bTSBPD; }
Expand Down Expand Up @@ -457,7 +459,8 @@ class CUDT
/// @retval 1 Connection in progress (m_ConnReq turned into RESPONSE)
/// @retval -1 Connection failed

SRT_ATR_NODISCARD EConnectStatus processConnectResponse(const CPacket& pkt, CUDTException* eout) ATR_NOEXCEPT;
SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock)
EConnectStatus processConnectResponse(const CPacket& pkt, CUDTException* eout) ATR_NOEXCEPT;

// This function works in case of HSv5 rendezvous. It changes the state
// according to the present state and received message type, as well as the
Expand All @@ -476,9 +479,15 @@ class CUDT
/// @param response incoming handshake response packet to be interpreted
/// @param serv_addr incoming packet's address
/// @param rst Current read status to know if the HS packet was freshly received from the peer, or this is only a periodic update (RST_AGAIN)
SRT_ATR_NODISCARD EConnectStatus processRendezvous(const CPacket* response, const sockaddr_any& serv_addr, EReadStatus, CPacket& reqpkt);
SRT_ATR_NODISCARD bool prepareConnectionObjects(const CHandShake &hs, HandshakeSide hsd, CUDTException *eout);
SRT_ATR_NODISCARD EConnectStatus postConnect(const CPacket* response, bool rendezvous, CUDTException* eout) ATR_NOEXCEPT;
SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock)
EConnectStatus processRendezvous(const CPacket* response, const sockaddr_any& serv_addr, EReadStatus, CPacket& reqpkt);

SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock)
bool prepareConnectionObjects(const CHandShake &hs, HandshakeSide hsd, CUDTException *eout);

SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock)
EConnectStatus postConnect(const CPacket* response, bool rendezvous, CUDTException* eout) ATR_NOEXCEPT;

SRT_ATR_NODISCARD bool applyResponseSettings() ATR_NOEXCEPT;
SRT_ATR_NODISCARD EConnectStatus processAsyncConnectResponse(const CPacket& pkt) ATR_NOEXCEPT;
SRT_ATR_NODISCARD bool processAsyncConnectRequest(EReadStatus rst, EConnectStatus cst, const CPacket* response, const sockaddr_any& serv_addr);
Expand Down Expand Up @@ -708,7 +717,8 @@ class CUDT
int m_iTsbPdDelay_ms; // Rx delay to absorb burst, in milliseconds
int m_iPeerTsbPdDelay_ms; // Tx delay that the peer uses to absorb burst, in milliseconds
bool m_bTLPktDrop; // Enable Too-late Packet Drop
UniquePtr<CCryptoControl> m_pCryptoControl; // Congestion control SRT class (small data extension)
SRT_ATTR_PT_GUARDED_BY(m_ConnectionLock)
UniquePtr<CCryptoControl> m_pCryptoControl; // Crypto control module
CCache<CInfoBlock>* m_pCache; // Network information cache

// Congestion control
Expand Down Expand Up @@ -932,7 +942,7 @@ class CUDT

// Failure to create the crypter means that an encrypted
// connection should be rejected if ENFORCEDENCRYPTION is on.
SRT_ATR_NODISCARD
SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock)
bool createCrypter(HandshakeSide side, bool bidi);

private: // Generation and processing of packets
Expand Down
2 changes: 1 addition & 1 deletion srtcore/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ class SRT_ATTR_SCOPED_CAPABILITY UniqueLock

inline void enterCS(Mutex& m) SRT_ATTR_EXCLUDES(m) SRT_ATTR_ACQUIRE(m) { m.lock(); }

inline bool tryEnterCS(Mutex& m) SRT_ATTR_TRY_ACQUIRE(true, m) { return m.try_lock(); }
inline bool tryEnterCS(Mutex& m) SRT_ATTR_EXCLUDES(m) SRT_ATTR_TRY_ACQUIRE(true, m) { return m.try_lock(); }

inline void leaveCS(Mutex& m) SRT_ATTR_REQUIRES(m) SRT_ATTR_RELEASE(m) { m.unlock(); }

Expand Down

0 comments on commit 1a85c02

Please sign in to comment.