Add k_ESteamNetworkingConfig_PacketTraceMaxBytes

P4:6378208
This commit is contained in:
Fletcher Dunn
2021-02-19 13:43:48 -08:00
parent 895f1821a8
commit 2103db35ad
4 changed files with 70 additions and 7 deletions
+5
View File
@@ -1114,6 +1114,11 @@ enum ESteamNetworkingConfigValue
/// (We chose a random delay between 0 and this value)
k_ESteamNetworkingConfig_FakePacketDup_TimeMax = 28,
/// [global int32] Trace every UDP packet, similar to Wireshark or tcpdump.
/// Value is max number of bytes to dump. -1 disables tracing.
// 0 only traces the info but no actual data bytes
k_ESteamNetworkingConfig_PacketTraceMaxBytes = 41,
//
// Connection configuration
//
@@ -46,6 +46,7 @@ DEFINE_GLOBAL_CONFIGVAL( int32, FakePacketReorder_Time, 15, 0, 5000 );
DEFINE_GLOBAL_CONFIGVAL( float, FakePacketDup_Send, 0.0f, 0.0f, 100.0f );
DEFINE_GLOBAL_CONFIGVAL( float, FakePacketDup_Recv, 0.0f, 0.0f, 100.0f );
DEFINE_GLOBAL_CONFIGVAL( int32, FakePacketDup_TimeMax, 10, 0, 5000 );
DEFINE_GLOBAL_CONFIGVAL( int32, PacketTraceMaxBytes, -1, -1, 99999 );
DEFINE_GLOBAL_CONFIGVAL( int32, EnumerateDevVars, 0, 0, 1 );
DEFINE_GLOBAL_CONFIGVAL( void *, Callback_AuthStatusChanged, nullptr );
@@ -702,9 +702,8 @@ public:
}
#endif
//const uint8 *pbPkt = (const uint8 *)pPkt;
//Log_Detailed( LOG_STEAMDATAGRAM_CLIENT, "%4db -> %s %02x %02x %02x %02x %02x ...\n",
// cbPkt, CUtlNetAdrRender( adrTo ).String(), pbPkt[0], pbPkt[1], pbPkt[2], pbPkt[3], pbPkt[4] );
if ( g_Config_PacketTraceMaxBytes.Get() >= 0 )
TracePkt( true, adrTo, nChunks, pChunks );
#ifdef STEAMNETWORKINGSOCKETS_LOWLEVEL_TIME_SOCKET_CALLS
SteamNetworkingMicroseconds usecSendStart = SteamNetworkingSockets_GetLocalTimestamp();
@@ -759,6 +758,58 @@ public:
return bResult;
}
void TracePkt( bool bSend, const netadr_t &adrRemote, int nChunks, const iovec *pChunks ) const
{
int cbTotal = 0;
for ( int i = 0 ; i < nChunks ; ++i )
cbTotal += pChunks[i].iov_len;
if ( bSend )
{
ReallySpewTypeFmt( k_ESteamNetworkingSocketsDebugOutputType_Msg, "[Trace Send] %s -> %s | %d bytes\n",
SteamNetworkingIPAddrRender( m_boundAddr ).c_str(), CUtlNetAdrRender( adrRemote ).String(), cbTotal );
}
else
{
ReallySpewTypeFmt( k_ESteamNetworkingSocketsDebugOutputType_Msg, "[Trace Recv] %s <- %s | %d bytes\n",
SteamNetworkingIPAddrRender( m_boundAddr ).c_str(), CUtlNetAdrRender( adrRemote ).String(), cbTotal );
}
int l = std::min( cbTotal, g_Config_PacketTraceMaxBytes.Get() );
const uint8 *p = (const uint8 *)pChunks->iov_base;
int cbChunkLeft = pChunks->iov_len;
while ( l > 0 )
{
// How many bytes to print on thie row?
int row = std::min( 16, l );
l -= row;
char buf[256], *d = buf;
do {
// Check for end of this chunk
while ( cbChunkLeft == 0 )
{
++pChunks;
p = (const uint8 *)pChunks->iov_base;
cbChunkLeft = pChunks->iov_len;
}
// print the byte
static const char hexdigit[] = "0123456789abcdef";
*(d++) = ' ';
*(d++) = hexdigit[ *p >> 4 ];
*(d++) = hexdigit[ *p & 0xf ];
// Advance to next byte
++p;
--cbChunkLeft;
} while (--row > 0 );
*d = '\0';
// Emit the row
ReallySpewTypeFmt( k_ESteamNetworkingSocketsDebugOutputType_Msg, " %s\n", buf );
}
}
private:
void InternalAddToCleanupQueue();
@@ -1518,6 +1569,15 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
if ( pSock->m_nAddressFamilies == k_nAddressFamily_DualStack )
info.m_adrFrom.BConvertMappedToIPv4();
// Check for tracing
if ( g_Config_PacketTraceMaxBytes.Get() >= 0 )
{
iovec tmp;
tmp.iov_base = buf;
tmp.iov_len = ret;
pSock->TracePkt( false, info.m_adrFrom, 1, &tmp );
}
int32 nPacketFakeLagTotal = g_Config_FakePacketLag_Recv.Get();
// Check for simulating random packet reordering
@@ -1549,10 +1609,6 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
{
ETW_UDPRecvPacket( info.m_adrFrom, ret );
//const uint8 *pbPkt = (const uint8 *)buf;
//Log_Detailed( LOG_STEAMDATAGRAM_CLIENT, "%s -> %4db %02x %02x %02x %02x %02x ...\n",
// CUtlNetAdrRender( adr ).String(), ret, pbPkt[0], pbPkt[1], pbPkt[2], pbPkt[3], pbPkt[4] );
info.m_pPkt = buf;
info.m_cbPkt = ret;
info.m_pSock = pSock;
@@ -766,6 +766,7 @@ extern GlobalConfigValue<int32> g_Config_FakePacketReorder_Time;
extern GlobalConfigValue<float> g_Config_FakePacketDup_Send;
extern GlobalConfigValue<float> g_Config_FakePacketDup_Recv;
extern GlobalConfigValue<int32> g_Config_FakePacketDup_TimeMax;
extern GlobalConfigValue<int32> g_Config_PacketTraceMaxBytes;
extern GlobalConfigValue<int32> g_Config_EnumerateDevVars;
extern GlobalConfigValue<void*> g_Config_Callback_CreateConnectionSignaling;