Browse Source

separate class TransitTunnelBuildMsgHandler for tunnel build messages

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

6
libi2pd/TransitTunnel.cpp

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

16
libi2pd/TransitTunnel.h

@ -109,8 +109,20 @@ namespace tunnel @@ -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<I2NPMessage> msg);
void HandleVariableTransitTunnelBuildMsg (std::shared_ptr<I2NPMessage> msg);
class TransitTunnelBuildMsgHandler
{
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 @@ -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 @@ -654,7 +656,7 @@ namespace tunnel
return;
}
else
i2p::tunnel::HandleShortTransitTunnelBuildMsg (msg);
m_TransitTunnelBuildMsgHandler.HandleShortTransitTunnelBuildMsg (std::move (msg));
}
void Tunnels::HandleVariableTunnelBuildMsg (std::shared_ptr<I2NPMessage> msg)
@ -677,7 +679,7 @@ namespace tunnel @@ -677,7 +679,7 @@ namespace tunnel
}
}
else
i2p::tunnel::HandleVariableTransitTunnelBuildMsg (msg);
m_TransitTunnelBuildMsgHandler.HandleVariableTransitTunnelBuildMsg (std::move (msg));
}
void Tunnels::HandleTunnelBuildReplyMsg (std::shared_ptr<I2NPMessage> msg, bool isShort)

3
libi2pd/Tunnel.h

@ -314,7 +314,8 @@ namespace tunnel @@ -314,7 +314,8 @@ namespace tunnel
double m_TunnelCreationSuccessRate;
int m_TunnelCreationAttemptsNum;
std::mt19937 m_Rng;
TransitTunnelBuildMsgHandler m_TransitTunnelBuildMsgHandler;
public:
// for HTTP only

Loading…
Cancel
Save