mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-21 23:54:14 +00:00
manage transit tunnels
This commit is contained in:
parent
5997cb80bd
commit
e1716bc05e
24
Tunnel.cpp
24
Tunnel.cpp
@ -13,8 +13,7 @@ namespace i2p
|
||||
namespace tunnel
|
||||
{
|
||||
|
||||
Tunnel::Tunnel (TunnelConfig * config): m_Config (config),
|
||||
m_CreationTime (i2p::util::GetSecondsSinceEpoch ()), m_IsEstablished (false)
|
||||
Tunnel::Tunnel (TunnelConfig * config): m_Config (config), m_IsEstablished (false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -320,6 +319,7 @@ namespace tunnel
|
||||
|
||||
ManageInboundTunnels ();
|
||||
ManageOutboundTunnels ();
|
||||
ManageTransitTunnels ();
|
||||
|
||||
/* if (!m_IsTunnelCreated)
|
||||
{
|
||||
@ -407,13 +407,29 @@ namespace tunnel
|
||||
{
|
||||
OutboundTunnel * outboundTunnel = GetNextOutboundTunnel ();
|
||||
LogPrint ("Creating two hops inbound tunnel...");
|
||||
auto router = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router;
|
||||
CreateTunnel<InboundTunnel> (
|
||||
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (),
|
||||
outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router),
|
||||
new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (),
|
||||
router != &i2p::context.GetRouterInfo () ? router : i2p::data::netdb.GetRandomNTCPRouter ()),
|
||||
outboundTunnel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tunnels::ManageTransitTunnels ()
|
||||
{
|
||||
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||
for (auto it = m_TransitTunnels.begin (); it != m_TransitTunnels.end ();)
|
||||
{
|
||||
if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||
{
|
||||
LogPrint ("Transit tunnel ", it->second->GetTunnelID (), " expired");
|
||||
it = m_TransitTunnels.erase (it);
|
||||
}
|
||||
else
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
void Tunnels::PostTunnelData (I2NPMessage * msg)
|
||||
{
|
||||
|
14
Tunnel.h
14
Tunnel.h
@ -33,9 +33,7 @@ namespace tunnel
|
||||
|
||||
void Build (uint32_t replyMsgID, OutboundTunnel * outboundTunnel = 0);
|
||||
|
||||
virtual uint32_t GetTunnelID () const = 0; // as known at our side
|
||||
TunnelConfig * GetTunnelConfig () const { return m_Config; }
|
||||
uint32_t GetCreationTime () const { return m_CreationTime; };
|
||||
bool IsEstablished () const { return m_IsEstablished; };
|
||||
|
||||
bool HandleTunnelBuildResponse (uint8_t * msg, size_t len);
|
||||
@ -54,7 +52,6 @@ namespace tunnel
|
||||
private:
|
||||
|
||||
TunnelConfig * m_Config;
|
||||
uint32_t m_CreationTime; // seconds since epoch
|
||||
bool m_IsEstablished;
|
||||
|
||||
CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption m_ECBDecryption;
|
||||
@ -70,9 +67,11 @@ namespace tunnel
|
||||
void SendTunnelDataMsg (i2p::I2NPMessage * msg); //local
|
||||
void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg);
|
||||
|
||||
uint32_t GetTunnelID () const { return GetNextTunnelID (); };
|
||||
TunnelGateway& GetTunnelGateway () { return m_Gateway; };
|
||||
size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); };
|
||||
|
||||
// implements TunnelBase
|
||||
uint32_t GetTunnelID () const { return GetNextTunnelID (); };
|
||||
|
||||
private:
|
||||
|
||||
@ -85,10 +84,10 @@ namespace tunnel
|
||||
|
||||
InboundTunnel (TunnelConfig * config): Tunnel (config) {};
|
||||
void HandleTunnelDataMsg (I2NPMessage * msg);
|
||||
|
||||
uint32_t GetTunnelID () const { return GetTunnelConfig ()->GetLastHop ()->nextTunnelID; };
|
||||
size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); };
|
||||
|
||||
|
||||
// implements TunnelBase
|
||||
uint32_t GetTunnelID () const { return GetTunnelConfig ()->GetLastHop ()->nextTunnelID; };
|
||||
private:
|
||||
|
||||
TunnelEndpoint m_Endpoint;
|
||||
@ -128,6 +127,7 @@ namespace tunnel
|
||||
void ManageTunnels ();
|
||||
void ManageOutboundTunnels ();
|
||||
void ManageInboundTunnels ();
|
||||
void ManageTransitTunnels ();
|
||||
|
||||
void CreateZeroHopsInboundTunnel ();
|
||||
|
||||
|
10
TunnelBase.h
10
TunnelBase.h
@ -2,6 +2,7 @@
|
||||
#define TUNNEL_BASE_H__
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "Timestamp.h"
|
||||
#include "I2NPProtocol.h"
|
||||
|
||||
namespace i2p
|
||||
@ -30,11 +31,20 @@ namespace tunnel
|
||||
{
|
||||
public:
|
||||
|
||||
TunnelBase (): m_CreationTime (i2p::util::GetSecondsSinceEpoch ()) {};
|
||||
virtual ~TunnelBase () {};
|
||||
|
||||
virtual void EncryptTunnelMsg (I2NPMessage * tunnelMsg) = 0;
|
||||
virtual uint32_t GetNextTunnelID () const = 0;
|
||||
virtual const i2p::data::IdentHash& GetNextIdentHash () const = 0;
|
||||
virtual uint32_t GetTunnelID () const = 0; // as known at our side
|
||||
|
||||
uint32_t GetCreationTime () const { return m_CreationTime; };
|
||||
void SetCreationTime (uint32_t t) { m_CreationTime = t; };
|
||||
|
||||
private:
|
||||
|
||||
uint32_t m_CreationTime; // seconds since epoch
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user