Browse Source

common HandleTunnelData for own and transit tunnels

pull/151/head
orignal 10 years ago
parent
commit
89dead79c4
  1. 2
      TransitTunnel.h
  2. 23
      Tunnel.cpp
  3. 1
      Tunnel.h
  4. 1
      TunnelBase.h

2
TransitTunnel.h

@ -21,13 +21,13 @@ namespace tunnel
const uint8_t * nextIdent, uint32_t nextTunnelID, const uint8_t * nextIdent, uint32_t nextTunnelID,
const uint8_t * layerKey,const uint8_t * ivKey); const uint8_t * layerKey,const uint8_t * ivKey);
virtual void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg);
virtual void SendTunnelDataMsg (i2p::I2NPMessage * msg); virtual void SendTunnelDataMsg (i2p::I2NPMessage * msg);
virtual size_t GetNumTransmittedBytes () const { return m_NumTransmittedBytes; }; virtual size_t GetNumTransmittedBytes () const { return m_NumTransmittedBytes; };
uint32_t GetTunnelID () const { return m_TunnelID; }; uint32_t GetTunnelID () const { return m_TunnelID; };
// implements TunnelBase // implements TunnelBase
void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg);
void EncryptTunnelMsg (I2NPMessage * tunnelMsg); void EncryptTunnelMsg (I2NPMessage * tunnelMsg);
uint32_t GetNextTunnelID () const { return m_NextTunnelID; }; uint32_t GetNextTunnelID () const { return m_NextTunnelID; };
const i2p::data::IdentHash& GetNextIdentHash () const { return m_NextIdent; }; const i2p::data::IdentHash& GetNextIdentHash () const { return m_NextIdent; };

23
Tunnel.cpp

@ -189,6 +189,12 @@ namespace tunnel
m_Gateway.SendBuffer (); m_Gateway.SendBuffer ();
} }
void OutboundTunnel::HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg)
{
LogPrint (eLogError, "Incoming message for outbound tunnel ", GetTunnelID ());
DeleteI2NPMessage (tunnelMsg);
}
Tunnels tunnels; Tunnels tunnels;
Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr) Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr)
@ -344,20 +350,17 @@ namespace tunnel
while (msg) while (msg)
{ {
uint32_t tunnelID = bufbe32toh (msg->GetPayload ()); uint32_t tunnelID = bufbe32toh (msg->GetPayload ());
InboundTunnel * tunnel = GetInboundTunnel (tunnelID); TunnelBase * tunnel = GetInboundTunnel (tunnelID);
if (!tunnel)
tunnel = GetTransitTunnel (tunnelID);
if (tunnel) if (tunnel)
tunnel->HandleTunnelDataMsg (msg); tunnel->HandleTunnelDataMsg (msg);
else else
{ {
TransitTunnel * transitTunnel = GetTransitTunnel (tunnelID); LogPrint ("Tunnel ", tunnelID, " not found");
if (transitTunnel) DeleteI2NPMessage (msg);
transitTunnel->HandleTunnelDataMsg (msg);
else
{
LogPrint ("Tunnel ", tunnelID, " not found");
i2p::DeleteI2NPMessage (msg);
}
} }
msg = m_Queue.Get (); msg = m_Queue.Get ();
} }

1
Tunnel.h

@ -85,6 +85,7 @@ namespace tunnel
size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); }; size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); };
// implements TunnelBase // implements TunnelBase
void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg);
uint32_t GetTunnelID () const { return GetNextTunnelID (); }; uint32_t GetTunnelID () const { return GetNextTunnelID (); };
private: private:

1
TunnelBase.h

@ -36,6 +36,7 @@ namespace tunnel
TunnelBase (): m_CreationTime (i2p::util::GetSecondsSinceEpoch ()) {}; TunnelBase (): m_CreationTime (i2p::util::GetSecondsSinceEpoch ()) {};
virtual ~TunnelBase () {}; virtual ~TunnelBase () {};
virtual void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg) = 0;
virtual void EncryptTunnelMsg (I2NPMessage * tunnelMsg) = 0; virtual void EncryptTunnelMsg (I2NPMessage * tunnelMsg) = 0;
virtual uint32_t GetNextTunnelID () const = 0; virtual uint32_t GetNextTunnelID () const = 0;
virtual const i2p::data::IdentHash& GetNextIdentHash () const = 0; virtual const i2p::data::IdentHash& GetNextIdentHash () const = 0;

Loading…
Cancel
Save