Browse Source

enable zero-hops inbound tunnel

pull/401/head
orignal 8 years ago
parent
commit
d541572882
  1. 34
      Tunnel.cpp
  2. 15
      Tunnel.h
  3. 7
      TunnelConfig.h

34
Tunnel.cpp

@ -200,15 +200,25 @@ namespace tunnel
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg); m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
} }
void InboundTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) void InboundTunnel::Print (std::stringstream& s) const
{
PrintHops (s);
s << "" << GetTunnelID () << ":me";
}
ZeroHopsInboundTunnel::ZeroHopsInboundTunnel ():
InboundTunnel (std::make_shared<ZeroHopsTunnelConfig> ())
{
}
void ZeroHopsInboundTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
{ {
// assume zero-hops tunnel msg->from = shared_from_this ();
m_Endpoint.HandleDecryptedTunnelDataMsg (msg); m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
} }
void InboundTunnel::Print (std::stringstream& s) const void ZeroHopsInboundTunnel::Print (std::stringstream& s) const
{ {
PrintHops (s);
s << "" << GetTunnelID () << ":me"; s << "" << GetTunnelID () << ":me";
} }
@ -771,11 +781,21 @@ namespace tunnel
void Tunnels::CreateZeroHopsInboundTunnel () void Tunnels::CreateZeroHopsInboundTunnel ()
{ {
CreateTunnel<InboundTunnel> ( /*CreateTunnel<InboundTunnel> (
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >
{
i2p::context.GetIdentity ()
}));*/
auto inboundTunnel = std::make_shared<ZeroHopsInboundTunnel> ();
m_InboundTunnels.push_back (inboundTunnel);
m_Tunnels[inboundTunnel->GetTunnelID ()] = inboundTunnel;
// create paired outbound tunnel, TODO: move to separate function
CreateTunnel<OutboundTunnel> (
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >
{ {
i2p::context.GetIdentity () i2p::context.GetIdentity ()
})); }, inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()));
} }
int Tunnels::GetTransitTunnelsExpirationTimeout () int Tunnels::GetTransitTunnelsExpirationTimeout ()

15
Tunnel.h

@ -72,6 +72,8 @@ namespace tunnel
void SetTunnelPool (std::shared_ptr<TunnelPool> pool) { m_Pool = pool; }; void SetTunnelPool (std::shared_ptr<TunnelPool> pool) { m_Pool = pool; };
bool HandleTunnelBuildResponse (uint8_t * msg, size_t len); bool HandleTunnelBuildResponse (uint8_t * msg, size_t len);
virtual void Print (std::stringstream& s) const {};
// implements TunnelBase // implements TunnelBase
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg); void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
@ -112,22 +114,29 @@ namespace tunnel
TunnelGateway m_Gateway; TunnelGateway m_Gateway;
i2p::data::IdentHash m_EndpointIdentHash; i2p::data::IdentHash m_EndpointIdentHash;
}; };
class InboundTunnel: public Tunnel, public std::enable_shared_from_this<InboundTunnel> class InboundTunnel: public Tunnel, public std::enable_shared_from_this<InboundTunnel>
{ {
public: public:
InboundTunnel (std::shared_ptr<const TunnelConfig> config): Tunnel (config), m_Endpoint (true) {}; InboundTunnel (std::shared_ptr<const TunnelConfig> config): Tunnel (config), m_Endpoint (true) {};
void HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg); void HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg);
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg); // for zero-hops only
size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); }; size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); };
void Print (std::stringstream& s) const; void Print (std::stringstream& s) const;
private: protected:
TunnelEndpoint m_Endpoint; TunnelEndpoint m_Endpoint;
}; };
class ZeroHopsInboundTunnel: public InboundTunnel
{
public:
ZeroHopsInboundTunnel ();
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
void Print (std::stringstream& s) const;
};
class Tunnels class Tunnels
{ {

7
TunnelConfig.h

@ -226,14 +226,13 @@ namespace tunnel
TunnelHopConfig * m_FirstHop, * m_LastHop; TunnelHopConfig * m_FirstHop, * m_LastHop;
}; };
class ZeroHopTunnelConfig: public TunnelConfig class ZeroHopsTunnelConfig: public TunnelConfig
{ {
public: public:
ZeroHopTunnelConfig (uint32_t tunnelID = 0): // 0 means outbound ZeroHopsTunnelConfig () { RAND_bytes ((uint8_t *)&m_TunnelID, 4);};
m_TunnelID (tunnelID) {};
bool IsInbound () const { return m_TunnelID; }; bool IsInbound () const { return true; }; // TODO:
uint32_t GetTunnelID () const { return m_TunnelID; }; uint32_t GetTunnelID () const { return m_TunnelID; };
uint32_t GetNextTunnelID () const { return m_TunnelID; }; uint32_t GetNextTunnelID () const { return m_TunnelID; };
const i2p::data::IdentHash& GetNextIdentHash () const { return i2p::context.GetIdentHash (); }; const i2p::data::IdentHash& GetNextIdentHash () const { return i2p::context.GetIdentHash (); };

Loading…
Cancel
Save