1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Send protocol version to verify handshake.

This commit is contained in:
Bartosz Taudul
2018-09-09 19:28:53 +02:00
parent db1d7d2c92
commit 984a711666
6 changed files with 85 additions and 3 deletions
+23
View File
@@ -11,6 +11,7 @@
#include <time.h>
#include "../common/TracyMutex.hpp"
#include "../common/TracyProtocol.hpp"
#include "../common/TracySystem.hpp"
#include "tracy_pdqsort.h"
#include "TracyBadVersion.hpp"
@@ -454,6 +455,28 @@ void View::DrawTextContrast( ImDrawList* draw, const ImVec2& pos, uint32_t color
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();
}
+18 -2
View File
@@ -201,6 +201,7 @@ Worker::Worker( const char* addr )
, m_pendingSourceLocation( 0 )
, m_pendingCallstackFrames( 0 )
, m_traceVersion( CurrentVersion )
, m_handshake( 0 )
{
m_data.sourceLocationExpand.push_back( 0 );
m_data.threadExpand.push_back( 0 );
@@ -224,6 +225,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
, m_crashed( false )
, m_stream( nullptr )
, m_buffer( nullptr )
, m_handshake( 0 )
{
m_data.threadExpand.push_back( 0 );
m_data.callstackPayload.push_back( nullptr );
@@ -1279,14 +1281,28 @@ void Worker::Exec()
if( m_sock.Connect( m_addr.c_str(), "8086" ) ) break;
}
m_sock.Send( HandshakeShibboleth, HandshakeShibbolethSize );
auto lz4buf = std::make_unique<char[]>( LZ4Size );
std::chrono::time_point<std::chrono::high_resolution_clock> t0;
uint64_t bytes = 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 ) {
auto fd = m_slab.AllocInit<FrameData>();
fd->name = name;
+2
View File
@@ -264,6 +264,7 @@ public:
void Write( FileWrite& f );
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; }
@@ -415,6 +416,7 @@ private:
MbpsBlock m_mbpsData;
int m_traceVersion;
std::atomic<uint8_t> m_handshake;
static LoadProgress s_loadProgress;
};