Add compatibility with previous broadcast versions.

This commit is contained in:
Bartosz Taudul 2022-10-26 23:21:17 +02:00
parent 544caef850
commit 86f88714ae
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 92 additions and 10 deletions

View File

@ -293,18 +293,71 @@ static void DrawContents()
auto msg = broadcastListen->Read( len, addr, 0 ); auto msg = broadcastListen->Read( len, addr, 0 );
if( !msg ) break; if( !msg ) break;
if( len > sizeof( tracy::BroadcastMessage ) ) continue; if( len > sizeof( tracy::BroadcastMessage ) ) continue;
tracy::BroadcastMessage bm; uint16_t broadcastVersion;
memcpy( &bm, msg, len ); memcpy( &broadcastVersion, msg, sizeof( uint16_t ) );
if( broadcastVersion <= tracy::BroadcastVersion )
if( bm.broadcastVersion == tracy::BroadcastVersion )
{ {
const uint32_t protoVer = bm.protocolVersion; uint32_t protoVer;
const auto procname = bm.programName; char procname[tracy::WelcomeMessageProgramNameSize];
const auto activeTime = bm.activeTime; int32_t activeTime;
const auto listenPort = bm.listenPort; uint16_t listenPort;
const auto pid = bm.pid; uint64_t pid;
auto address = addr.GetText();
switch( broadcastVersion )
{
case 3:
{
tracy::BroadcastMessage bm;
memcpy( &bm, msg, len );
protoVer = bm.protocolVersion;
strcpy( procname, bm.programName );
activeTime = bm.activeTime;
listenPort = bm.listenPort;
pid = bm.pid;
break;
}
case 2:
{
if( len > sizeof( tracy::BroadcastMessage_v2 ) ) continue;
tracy::BroadcastMessage_v2 bm;
memcpy( &bm, msg, len );
protoVer = bm.protocolVersion;
strcpy( procname, bm.programName );
activeTime = bm.activeTime;
listenPort = bm.listenPort;
pid = 0;
break;
}
case 1:
{
if( len > sizeof( tracy::BroadcastMessage_v1 ) ) continue;
tracy::BroadcastMessage_v1 bm;
memcpy( &bm, msg, len );
protoVer = bm.protocolVersion;
strcpy( procname, bm.programName );
activeTime = bm.activeTime;
listenPort = bm.listenPort;
pid = 0;
break;
}
case 0:
{
if( len > sizeof( tracy::BroadcastMessage_v0 ) ) continue;
tracy::BroadcastMessage_v0 bm;
memcpy( &bm, msg, len );
protoVer = bm.protocolVersion;
strcpy( procname, bm.programName );
activeTime = bm.activeTime;
listenPort = 8086;
pid = 0;
break;
}
default:
assert( false );
break;
}
auto address = addr.GetText();
const auto ipNumerical = addr.GetNumber(); const auto ipNumerical = addr.GetNumber();
const auto clientId = uint64_t( ipNumerical ) | ( uint64_t( listenPort ) << 32 ); const auto clientId = uint64_t( ipNumerical ) | ( uint64_t( listenPort ) << 32 );
auto it = clients.find( clientId ); auto it = clients.find( clientId );

View File

@ -131,7 +131,36 @@ struct BroadcastMessage
char programName[WelcomeMessageProgramNameSize]; char programName[WelcomeMessageProgramNameSize];
}; };
struct BroadcastMessage_v2
{
uint16_t broadcastVersion;
uint16_t listenPort;
uint32_t protocolVersion;
int32_t activeTime;
char programName[WelcomeMessageProgramNameSize];
};
struct BroadcastMessage_v1
{
uint32_t broadcastVersion;
uint32_t protocolVersion;
uint32_t listenPort;
uint32_t activeTime;
char programName[WelcomeMessageProgramNameSize];
};
struct BroadcastMessage_v0
{
uint32_t broadcastVersion;
uint32_t protocolVersion;
uint32_t activeTime;
char programName[WelcomeMessageProgramNameSize];
};
enum { BroadcastMessageSize = sizeof( BroadcastMessage ) }; enum { BroadcastMessageSize = sizeof( BroadcastMessage ) };
enum { BroadcastMessageSize_v2 = sizeof( BroadcastMessage_v2 ) };
enum { BroadcastMessageSize_v1 = sizeof( BroadcastMessage_v1 ) };
enum { BroadcastMessageSize_v0 = sizeof( BroadcastMessage_v0 ) };
#pragma pack( pop ) #pragma pack( pop )