Browse Source

inbound zero-hops tunnel

pull/401/head
orignal 9 years ago
parent
commit
fa67e90767
  1. 6
      Tunnel.cpp
  2. 1
      Tunnel.h
  3. 35
      TunnelConfig.h

6
Tunnel.cpp

@ -200,6 +200,12 @@ namespace tunnel
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg); m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
} }
void InboundTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
{
// assume zero-hops tunnel
m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
}
void InboundTunnel::Print (std::stringstream& s) const void InboundTunnel::Print (std::stringstream& s) const
{ {
PrintHops (s); PrintHops (s);

1
Tunnel.h

@ -119,6 +119,7 @@ namespace tunnel
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;

35
TunnelConfig.h

@ -108,7 +108,7 @@ namespace tunnel
} }
}; };
class TunnelConfig: public std::enable_shared_from_this<TunnelConfig> class TunnelConfig
{ {
public: public:
@ -160,26 +160,26 @@ namespace tunnel
return num; return num;
} }
bool IsInbound () const { return m_FirstHop->isGateway; } virtual bool IsInbound () const { return m_FirstHop->isGateway; }
uint32_t GetTunnelID () const virtual uint32_t GetTunnelID () const
{ {
if (!m_FirstHop) return 0; if (!m_FirstHop) return 0;
return IsInbound () ? m_LastHop->nextTunnelID : m_FirstHop->tunnelID; return IsInbound () ? m_LastHop->nextTunnelID : m_FirstHop->tunnelID;
} }
uint32_t GetNextTunnelID () const virtual uint32_t GetNextTunnelID () const
{ {
if (!m_FirstHop) return 0; if (!m_FirstHop) return 0;
return m_FirstHop->tunnelID; return m_FirstHop->tunnelID;
} }
const i2p::data::IdentHash& GetNextIdentHash () const virtual const i2p::data::IdentHash& GetNextIdentHash () const
{ {
return m_FirstHop->ident->GetIdentHash (); return m_FirstHop->ident->GetIdentHash ();
} }
const i2p::data::IdentHash& GetLastIdentHash () const virtual const i2p::data::IdentHash& GetLastIdentHash () const
{ {
return m_LastHop->ident->GetIdentHash (); return m_LastHop->ident->GetIdentHash ();
} }
@ -196,13 +196,15 @@ namespace tunnel
return peers; return peers;
} }
private: protected:
// this constructor can't be called from outside // this constructor can't be called from outside
TunnelConfig (): m_FirstHop (nullptr), m_LastHop (nullptr) TunnelConfig (): m_FirstHop (nullptr), m_LastHop (nullptr)
{ {
} }
private:
template<class Peers> template<class Peers>
void CreatePeers (const Peers& peers) void CreatePeers (const Peers& peers)
{ {
@ -223,6 +225,25 @@ namespace tunnel
TunnelHopConfig * m_FirstHop, * m_LastHop; TunnelHopConfig * m_FirstHop, * m_LastHop;
}; };
class ZeroHopTunnelConfig: public TunnelConfig
{
public:
ZeroHopTunnelConfig (uint32_t tunnelID = 0): // 0 means outbound
m_TunnelID (tunnelID) {};
bool IsInbound () const { return m_TunnelID; };
uint32_t GetTunnelID () 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& GetLastIdentHash () const { return i2p::context.GetIdentHash (); };
private:
uint32_t m_TunnelID;
};
} }
} }

Loading…
Cancel
Save