Browse Source

enable zero-hops inbound tunnel

pull/401/head
orignal 9 years ago
parent
commit
d541572882
  1. 32
      Tunnel.cpp
  2. 13
      Tunnel.h
  3. 7
      TunnelConfig.h

32
Tunnel.cpp

@ -200,15 +200,25 @@ namespace tunnel @@ -200,15 +200,25 @@ namespace tunnel
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);
}
void InboundTunnel::Print (std::stringstream& s) const
void ZeroHopsInboundTunnel::Print (std::stringstream& s) const
{
PrintHops (s);
s << "" << GetTunnelID () << ":me";
}
@ -771,11 +781,21 @@ namespace tunnel @@ -771,11 +781,21 @@ namespace tunnel
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> >
{
i2p::context.GetIdentity ()
}));
}, inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()));
}
int Tunnels::GetTransitTunnelsExpirationTimeout ()

13
Tunnel.h

@ -73,6 +73,8 @@ namespace tunnel @@ -73,6 +73,8 @@ namespace tunnel
bool HandleTunnelBuildResponse (uint8_t * msg, size_t len);
virtual void Print (std::stringstream& s) const {};
// implements TunnelBase
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out);
@ -119,15 +121,22 @@ namespace tunnel @@ -119,15 +121,22 @@ namespace tunnel
InboundTunnel (std::shared_ptr<const TunnelConfig> config): Tunnel (config), m_Endpoint (true) {};
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 (); };
void Print (std::stringstream& s) const;
private:
protected:
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
{

7
TunnelConfig.h

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

Loading…
Cancel
Save