mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Send protocol version to verify handshake.
This commit is contained in:
parent
db1d7d2c92
commit
984a711666
@ -9,6 +9,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "../../common/TracyProtocol.hpp"
|
||||||
#include "../../server/TracyFileWrite.hpp"
|
#include "../../server/TracyFileWrite.hpp"
|
||||||
#include "../../server/TracyMemory.hpp"
|
#include "../../server/TracyMemory.hpp"
|
||||||
#include "../../server/TracyWorker.hpp"
|
#include "../../server/TracyWorker.hpp"
|
||||||
@ -137,6 +138,16 @@ int main( int argc, char** argv )
|
|||||||
printf( "Connecting to %s...", address );
|
printf( "Connecting to %s...", address );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
tracy::Worker worker( address );
|
tracy::Worker worker( address );
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
const auto handshake = worker.GetHandshakeStatus();
|
||||||
|
if( handshake == tracy::HandshakeWelcome ) break;
|
||||||
|
if( handshake == tracy::HandshakeProtocolMismatch )
|
||||||
|
{
|
||||||
|
printf( "\nThe client you are trying to connect to uses incompatible protocol version.\nMake sure you are using the same Tracy version on both client and server.\n" );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
while( !worker.HasData() ) std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
while( !worker.HasData() ) std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
||||||
printf( "\nQueue delay: %s\nTimer resolution: %s\n", TimeToString( worker.GetDelay() ), TimeToString( worker.GetResolution() ) );
|
printf( "\nQueue delay: %s\nTimer resolution: %s\n", TimeToString( worker.GetDelay() ), TimeToString( worker.GetResolution() ) );
|
||||||
|
|
||||||
|
@ -919,13 +919,31 @@ void Profiler::Worker()
|
|||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
char shibboleth[HandshakeShibbolethSize];
|
char shibboleth[HandshakeShibbolethSize];
|
||||||
const auto res = m_sock->ReadRaw( shibboleth, HandshakeShibbolethSize, &tv );
|
auto res = m_sock->ReadRaw( shibboleth, HandshakeShibbolethSize, &tv );
|
||||||
if( !res || memcmp( shibboleth, HandshakeShibboleth, HandshakeShibbolethSize ) != 0 )
|
if( !res || memcmp( shibboleth, HandshakeShibboleth, HandshakeShibbolethSize ) != 0 )
|
||||||
{
|
{
|
||||||
m_sock->~Socket();
|
m_sock->~Socket();
|
||||||
tracy_free( m_sock );
|
tracy_free( m_sock );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t protocolVersion;
|
||||||
|
res = m_sock->ReadRaw( &protocolVersion, sizeof( protocolVersion ), &tv );
|
||||||
|
if( !res )
|
||||||
|
{
|
||||||
|
m_sock->~Socket();
|
||||||
|
tracy_free( m_sock );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( protocolVersion != ProtocolVersion )
|
||||||
|
{
|
||||||
|
HandshakeStatus status = HandshakeProtocolMismatch;
|
||||||
|
m_sock->Send( &status, sizeof( status ) );
|
||||||
|
m_sock->~Socket();
|
||||||
|
tracy_free( m_sock );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TRACY_ON_DEMAND
|
#ifdef TRACY_ON_DEMAND
|
||||||
@ -933,6 +951,9 @@ void Profiler::Worker()
|
|||||||
m_isConnected.store( true, std::memory_order_relaxed );
|
m_isConnected.store( true, std::memory_order_relaxed );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
HandshakeStatus handshake = HandshakeWelcome;
|
||||||
|
m_sock->Send( &handshake, sizeof( handshake ) );
|
||||||
|
|
||||||
LZ4_resetStream( m_stream );
|
LZ4_resetStream( m_stream );
|
||||||
m_sock->Send( &welcome, sizeof( welcome ) );
|
m_sock->Send( &welcome, sizeof( welcome ) );
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum : uint32_t { ProtocolVersion = 0 };
|
||||||
|
|
||||||
using lz4sz_t = uint32_t;
|
using lz4sz_t = uint32_t;
|
||||||
|
|
||||||
enum { TargetFrameSize = 256 * 1024 };
|
enum { TargetFrameSize = 256 * 1024 };
|
||||||
@ -30,6 +32,13 @@ enum ServerQuery : uint8_t
|
|||||||
enum { HandshakeShibbolethSize = 8 };
|
enum { HandshakeShibbolethSize = 8 };
|
||||||
static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' };
|
static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' };
|
||||||
|
|
||||||
|
enum HandshakeStatus : uint8_t
|
||||||
|
{
|
||||||
|
HandshakePending,
|
||||||
|
HandshakeWelcome,
|
||||||
|
HandshakeProtocolMismatch,
|
||||||
|
};
|
||||||
|
|
||||||
enum { WelcomeMessageProgramNameSize = 64 };
|
enum { WelcomeMessageProgramNameSize = 64 };
|
||||||
enum { WelcomeMessageHostInfoSize = 1024 };
|
enum { WelcomeMessageHostInfoSize = 1024 };
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "../common/TracyMutex.hpp"
|
#include "../common/TracyMutex.hpp"
|
||||||
|
#include "../common/TracyProtocol.hpp"
|
||||||
#include "../common/TracySystem.hpp"
|
#include "../common/TracySystem.hpp"
|
||||||
#include "tracy_pdqsort.h"
|
#include "tracy_pdqsort.h"
|
||||||
#include "TracyBadVersion.hpp"
|
#include "TracyBadVersion.hpp"
|
||||||
@ -454,6 +455,28 @@ void View::DrawTextContrast( ImDrawList* draw, const ImVec2& pos, uint32_t color
|
|||||||
|
|
||||||
bool View::Draw()
|
bool View::Draw()
|
||||||
{
|
{
|
||||||
|
HandshakeStatus status = (HandshakeStatus)s_instance->m_worker.GetHandshakeStatus();
|
||||||
|
if( status == HandshakeProtocolMismatch )
|
||||||
|
{
|
||||||
|
ImGui::OpenPopup( "Protocol mismatch" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ImGui::BeginPopupModal( "Protocol mismatch", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||||
|
{
|
||||||
|
#ifdef TRACY_EXTENDED_FONT
|
||||||
|
TextCentered( ICON_FA_EXCLAMATION_TRIANGLE );
|
||||||
|
#endif
|
||||||
|
ImGui::Text( "The client you are trying to connect to uses incompatible protocol version.\nMake sure you are using the same Tracy version on both client and server." );
|
||||||
|
ImGui::Separator();
|
||||||
|
if( ImGui::Button( "My bad" ) )
|
||||||
|
{
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
ImGui::EndPopup();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
return s_instance->DrawImpl();
|
return s_instance->DrawImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +201,7 @@ Worker::Worker( const char* addr )
|
|||||||
, m_pendingSourceLocation( 0 )
|
, m_pendingSourceLocation( 0 )
|
||||||
, m_pendingCallstackFrames( 0 )
|
, m_pendingCallstackFrames( 0 )
|
||||||
, m_traceVersion( CurrentVersion )
|
, m_traceVersion( CurrentVersion )
|
||||||
|
, m_handshake( 0 )
|
||||||
{
|
{
|
||||||
m_data.sourceLocationExpand.push_back( 0 );
|
m_data.sourceLocationExpand.push_back( 0 );
|
||||||
m_data.threadExpand.push_back( 0 );
|
m_data.threadExpand.push_back( 0 );
|
||||||
@ -224,6 +225,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
|||||||
, m_crashed( false )
|
, m_crashed( false )
|
||||||
, m_stream( nullptr )
|
, m_stream( nullptr )
|
||||||
, m_buffer( nullptr )
|
, m_buffer( nullptr )
|
||||||
|
, m_handshake( 0 )
|
||||||
{
|
{
|
||||||
m_data.threadExpand.push_back( 0 );
|
m_data.threadExpand.push_back( 0 );
|
||||||
m_data.callstackPayload.push_back( nullptr );
|
m_data.callstackPayload.push_back( nullptr );
|
||||||
@ -1279,14 +1281,28 @@ void Worker::Exec()
|
|||||||
if( m_sock.Connect( m_addr.c_str(), "8086" ) ) break;
|
if( m_sock.Connect( m_addr.c_str(), "8086" ) ) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sock.Send( HandshakeShibboleth, HandshakeShibbolethSize );
|
|
||||||
|
|
||||||
auto lz4buf = std::make_unique<char[]>( LZ4Size );
|
auto lz4buf = std::make_unique<char[]>( LZ4Size );
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> t0;
|
std::chrono::time_point<std::chrono::high_resolution_clock> t0;
|
||||||
|
|
||||||
uint64_t bytes = 0;
|
uint64_t bytes = 0;
|
||||||
uint64_t decBytes = 0;
|
uint64_t decBytes = 0;
|
||||||
|
|
||||||
|
m_sock.Send( HandshakeShibboleth, HandshakeShibbolethSize );
|
||||||
|
uint32_t protocolVersion = ProtocolVersion;
|
||||||
|
m_sock.Send( &protocolVersion, sizeof( protocolVersion ) );
|
||||||
|
HandshakeStatus handshake;
|
||||||
|
if( !m_sock.Read( &handshake, sizeof( handshake ), &tv, ShouldExit ) ) goto close;
|
||||||
|
m_handshake.store( handshake, std::memory_order_relaxed );
|
||||||
|
switch( handshake )
|
||||||
|
{
|
||||||
|
case HandshakeWelcome:
|
||||||
|
break;
|
||||||
|
case HandshakeProtocolMismatch:
|
||||||
|
default:
|
||||||
|
goto close;
|
||||||
|
}
|
||||||
|
|
||||||
m_data.framesBase = m_data.frames.Retrieve( 0, [this] ( uint64_t name ) {
|
m_data.framesBase = m_data.frames.Retrieve( 0, [this] ( uint64_t name ) {
|
||||||
auto fd = m_slab.AllocInit<FrameData>();
|
auto fd = m_slab.AllocInit<FrameData>();
|
||||||
fd->name = name;
|
fd->name = name;
|
||||||
|
@ -264,6 +264,7 @@ public:
|
|||||||
|
|
||||||
void Write( FileWrite& f );
|
void Write( FileWrite& f );
|
||||||
int GetTraceVersion() const { return m_traceVersion; }
|
int GetTraceVersion() const { return m_traceVersion; }
|
||||||
|
uint8_t GetHandshakeStatus() const { return m_handshake.load( std::memory_order_relaxed ); }
|
||||||
|
|
||||||
static const LoadProgress& GetLoadProgress() { return s_loadProgress; }
|
static const LoadProgress& GetLoadProgress() { return s_loadProgress; }
|
||||||
|
|
||||||
@ -415,6 +416,7 @@ private:
|
|||||||
MbpsBlock m_mbpsData;
|
MbpsBlock m_mbpsData;
|
||||||
|
|
||||||
int m_traceVersion;
|
int m_traceVersion;
|
||||||
|
std::atomic<uint8_t> m_handshake;
|
||||||
|
|
||||||
static LoadProgress s_loadProgress;
|
static LoadProgress s_loadProgress;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user