diff --git a/libi2pd/TransitTunnel.cpp b/libi2pd/TransitTunnel.cpp index 3b016d95..62192e92 100644 --- a/libi2pd/TransitTunnel.cpp +++ b/libi2pd/TransitTunnel.cpp @@ -122,7 +122,7 @@ namespace tunnel } } - void HandleShortTransitTunnelBuildMsg (std::shared_ptr msg) + void TransitTunnelBuildMsgHandler::HandleShortTransitTunnelBuildMsg (std::shared_ptr&& msg) { if (!msg) return; uint8_t * buf = msg->GetPayload(); @@ -275,7 +275,7 @@ namespace tunnel } } - static bool HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText) + bool TransitTunnelBuildMsgHandler::HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText) { for (int i = 0; i < num; i++) { @@ -362,7 +362,7 @@ namespace tunnel return false; } - void HandleVariableTransitTunnelBuildMsg (std::shared_ptr msg) + void TransitTunnelBuildMsgHandler::HandleVariableTransitTunnelBuildMsg (std::shared_ptr&& msg) { if (!msg) return; uint8_t * buf = msg->GetPayload(); diff --git a/libi2pd/TransitTunnel.h b/libi2pd/TransitTunnel.h index 1a1b489b..fb5589dc 100644 --- a/libi2pd/TransitTunnel.h +++ b/libi2pd/TransitTunnel.h @@ -109,8 +109,20 @@ namespace tunnel const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey, bool isGateway, bool isEndpoint); - void HandleShortTransitTunnelBuildMsg (std::shared_ptr msg); - void HandleVariableTransitTunnelBuildMsg (std::shared_ptr msg); + class TransitTunnelBuildMsgHandler + { + public: + + void Start () {}; + void Stop () {}; + + void HandleShortTransitTunnelBuildMsg (std::shared_ptr&& msg); + void HandleVariableTransitTunnelBuildMsg (std::shared_ptr&& msg); + + private: + + bool HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText); + }; } } diff --git a/libi2pd/Tunnel.cpp b/libi2pd/Tunnel.cpp index 54e276ad..c743691e 100644 --- a/libi2pd/Tunnel.cpp +++ b/libi2pd/Tunnel.cpp @@ -482,10 +482,12 @@ namespace tunnel { m_IsRunning = true; m_Thread = new std::thread (std::bind (&Tunnels::Run, this)); + m_TransitTunnelBuildMsgHandler.Start (); } void Tunnels::Stop () { + m_TransitTunnelBuildMsgHandler.Stop (); m_IsRunning = false; m_Queue.WakeUp (); if (m_Thread) @@ -654,7 +656,7 @@ namespace tunnel return; } else - i2p::tunnel::HandleShortTransitTunnelBuildMsg (msg); + m_TransitTunnelBuildMsgHandler.HandleShortTransitTunnelBuildMsg (std::move (msg)); } void Tunnels::HandleVariableTunnelBuildMsg (std::shared_ptr msg) @@ -677,7 +679,7 @@ namespace tunnel } } else - i2p::tunnel::HandleVariableTransitTunnelBuildMsg (msg); + m_TransitTunnelBuildMsgHandler.HandleVariableTransitTunnelBuildMsg (std::move (msg)); } void Tunnels::HandleTunnelBuildReplyMsg (std::shared_ptr msg, bool isShort) diff --git a/libi2pd/Tunnel.h b/libi2pd/Tunnel.h index 291d1e6e..f4d94ba7 100644 --- a/libi2pd/Tunnel.h +++ b/libi2pd/Tunnel.h @@ -314,7 +314,8 @@ namespace tunnel double m_TunnelCreationSuccessRate; int m_TunnelCreationAttemptsNum; std::mt19937 m_Rng; - + TransitTunnelBuildMsgHandler m_TransitTunnelBuildMsgHandler; + public: // for HTTP only