Browse Source

separate class TransitTunnelBuildMsgHandler for tunnel build messages

pull/2125/head
orignal 1 week ago
parent
commit
0c5f39ad81
  1. 6
      libi2pd/TransitTunnel.cpp
  2. 16
      libi2pd/TransitTunnel.h
  3. 6
      libi2pd/Tunnel.cpp
  4. 1
      libi2pd/Tunnel.h

6
libi2pd/TransitTunnel.cpp

@ -122,7 +122,7 @@ namespace tunnel
} }
} }
void HandleShortTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage> msg) void TransitTunnelBuildMsgHandler::HandleShortTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage>&& msg)
{ {
if (!msg) return; if (!msg) return;
uint8_t * buf = msg->GetPayload(); 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++) for (int i = 0; i < num; i++)
{ {
@ -362,7 +362,7 @@ namespace tunnel
return false; return false;
} }
void HandleVariableTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage> msg) void TransitTunnelBuildMsgHandler::HandleVariableTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage>&& msg)
{ {
if (!msg) return; if (!msg) return;
uint8_t * buf = msg->GetPayload(); uint8_t * buf = msg->GetPayload();

16
libi2pd/TransitTunnel.h

@ -109,8 +109,20 @@ namespace tunnel
const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey, const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey,
bool isGateway, bool isEndpoint); bool isGateway, bool isEndpoint);
void HandleShortTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage> msg); class TransitTunnelBuildMsgHandler
void HandleVariableTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage> msg); {
public:
void Start () {};
void Stop () {};
void HandleShortTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage>&& msg);
void HandleVariableTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage>&& msg);
private:
bool HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText);
};
} }
} }

6
libi2pd/Tunnel.cpp

@ -482,10 +482,12 @@ namespace tunnel
{ {
m_IsRunning = true; m_IsRunning = true;
m_Thread = new std::thread (std::bind (&Tunnels::Run, this)); m_Thread = new std::thread (std::bind (&Tunnels::Run, this));
m_TransitTunnelBuildMsgHandler.Start ();
} }
void Tunnels::Stop () void Tunnels::Stop ()
{ {
m_TransitTunnelBuildMsgHandler.Stop ();
m_IsRunning = false; m_IsRunning = false;
m_Queue.WakeUp (); m_Queue.WakeUp ();
if (m_Thread) if (m_Thread)
@ -654,7 +656,7 @@ namespace tunnel
return; return;
} }
else else
i2p::tunnel::HandleShortTransitTunnelBuildMsg (msg); m_TransitTunnelBuildMsgHandler.HandleShortTransitTunnelBuildMsg (std::move (msg));
} }
void Tunnels::HandleVariableTunnelBuildMsg (std::shared_ptr<I2NPMessage> msg) void Tunnels::HandleVariableTunnelBuildMsg (std::shared_ptr<I2NPMessage> msg)
@ -677,7 +679,7 @@ namespace tunnel
} }
} }
else else
i2p::tunnel::HandleVariableTransitTunnelBuildMsg (msg); m_TransitTunnelBuildMsgHandler.HandleVariableTransitTunnelBuildMsg (std::move (msg));
} }
void Tunnels::HandleTunnelBuildReplyMsg (std::shared_ptr<I2NPMessage> msg, bool isShort) void Tunnels::HandleTunnelBuildReplyMsg (std::shared_ptr<I2NPMessage> msg, bool isShort)

1
libi2pd/Tunnel.h

@ -314,6 +314,7 @@ namespace tunnel
double m_TunnelCreationSuccessRate; double m_TunnelCreationSuccessRate;
int m_TunnelCreationAttemptsNum; int m_TunnelCreationAttemptsNum;
std::mt19937 m_Rng; std::mt19937 m_Rng;
TransitTunnelBuildMsgHandler m_TransitTunnelBuildMsgHandler;
public: public:

Loading…
Cancel
Save