Skip to content

Commit ea76437

Browse files
committed
ICE client: refactor and tweak spew
Expand Cancel() inline at its only call site, when we time out. Remember message type and spew it in a few places to help with testing.
1 parent 8bd8184 commit ea76437

2 files changed

Lines changed: 20 additions & 24 deletions

File tree

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_ice_client.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ void CSteamNetworkingSocketsSTUNRequest::Queue( uint32 nMessageType, int nEncodi
915915
{
916916
m_remoteAddr = remoteAddr;
917917
m_nRetryCount = 0;
918+
m_nMessageType = nMessageType;
918919
// Retry schedule: 400ms initial interval, growing by 1.5x each attempt.
919920
// Send times (approximate): 0, 400ms, 1.0s, 1.9s, 3.25s -> give up at ~5.3s.
920921
// RFC 5389 uses 500ms initial RTO doubling each retry over 7+ attempts (~32-64s total),
@@ -939,22 +940,6 @@ void CSteamNetworkingSocketsSTUNRequest::Queue( uint32 nMessageType, int nEncodi
939940
}
940941

941942

942-
void CSteamNetworkingSocketsSTUNRequest::Cancel()
943-
{
944-
if ( m_callback )
945-
{
946-
RecvSTUNPktInfo_t subInfo;
947-
subInfo.m_pRequest = this;
948-
subInfo.m_pHeader = nullptr;
949-
subInfo.m_nAttributes = 0;
950-
subInfo.m_pAttributes = nullptr;
951-
subInfo.m_usecNow = SteamNetworkingSockets_GetLocalTimestamp();
952-
( m_pInterface->m_session.*m_callback )( subInfo );
953-
}
954-
955-
delete this;
956-
}
957-
958943
void CSteamNetworkingSocketsSTUNRequest::RetriggerNow()
959944
{
960945
m_nRetryCount = 0;
@@ -1005,14 +990,24 @@ void CSteamNetworkingSocketsSTUNRequest::Think( SteamNetworkingMicroseconds usec
1005990
}
1006991
else
1007992
{
1008-
SpewVerboseGroup( GlobalConfig::LogLevel_P2PRendezvous.Get(), "ICE: STUN request to %s timed out.\n",
1009-
SteamNetworkingIPAddrRender( m_remoteAddr ).c_str() );
993+
SpewVerboseGroup( GlobalConfig::LogLevel_P2PRendezvous.Get(), "ICE: STUN request 0x%x to %s timed out.\n",
994+
m_nMessageType, SteamNetworkingIPAddrRender( m_remoteAddr ).c_str() );
1010995
}
1011996

1012-
// Call the callback to notify that we've failed, and SELF DESTRUCT.
1013-
Cancel();
997+
// Call the callback to notify that we've failed
998+
if ( m_callback )
999+
{
1000+
RecvSTUNPktInfo_t subInfo;
1001+
subInfo.m_pRequest = this;
1002+
subInfo.m_pHeader = nullptr;
1003+
subInfo.m_nAttributes = 0;
1004+
subInfo.m_pAttributes = nullptr;
1005+
subInfo.m_usecNow = SteamNetworkingSockets_GetLocalTimestamp();
1006+
( m_pInterface->m_session.*m_callback )( subInfo );
1007+
}
10141008

1015-
// WARNING: We don't exist here!
1009+
// SELF DESTRUCT
1010+
delete this;
10161011
}
10171012

10181013
void CSteamNetworkingSocketsSTUNRequest::ReplyPacketReceived( const RecvPktInfo_t &info, const STUNHeader &header )
@@ -1021,8 +1016,9 @@ void CSteamNetworkingSocketsSTUNRequest::ReplyPacketReceived( const RecvPktInfo_
10211016
CUtlVector< STUNAttribute > vecAttributes;
10221017
if ( !ParseSTUNAttributes( info, (const byte*)m_strPassword.c_str(), (uint32)m_strPassword.size(), &vecAttributes ) )
10231018
{
1024-
SpewVerboseGroup( GlobalConfig::LogLevel_P2PRendezvous.Get(), "ICE: Dropping STUN response from %s: attribute parse or integrity failure.\n",
1025-
SteamNetworkingIPAddrRender( m_remoteAddr ).c_str() );
1019+
SpewVerboseGroup( GlobalConfig::LogLevel_P2PRendezvous.Get(),
1020+
"ICE: Dropping STUN response 0x%x from %s: attribute parse or integrity failure.\n",
1021+
m_nMessageType, SteamNetworkingIPAddrRender( m_remoteAddr ).c_str() );
10261022
return;
10271023
}
10281024

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_ice_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ namespace SteamNetworkingSocketsLib {
208208
uint32 m_nTransactionID[3]; // generated at construction
209209
SteamNetworkingIPAddr m_remoteAddr; // Address of the peer
210210
SteamNetworkingIPAddr m_addrRelay;
211+
uint32 m_nMessageType;
211212
int m_nRetryCount;
212213
int m_nMaxRetries;
213214
RecvSTUNPacketCallback_t m_callback = nullptr;
@@ -220,7 +221,6 @@ namespace SteamNetworkingSocketsLib {
220221

221222
// Serialize the packet and start the retry loop.
222223
void Queue( uint32 nMessageType, int nEncoding, SteamNetworkingIPAddr remoteAddr, RecvSTUNPacketCallback_t cb, STUNAttribute *pExtraAttrs = nullptr, int nExtraAttrs = 0 );
223-
void Cancel();
224224

225225
// Immediately retransmit and reset the exponential backoff schedule, as if
226226
// the request were freshly queued. The transaction ID is preserved, so any

0 commit comments

Comments
 (0)