diff --git a/Tunnel.cpp b/Tunnel.cpp index 37dd6d67..4e3d2275 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -244,8 +244,7 @@ namespace tunnel block.deliveryType = eDeliveryTypeLocal; block.data = msg; - std::unique_lock l(m_SendMutex); - m_Gateway.SendTunnelDataMsg (block); + SendTunnelDataMsg ({block}); } void OutboundTunnel::SendTunnelDataMsg (const std::vector& msgs) @@ -268,6 +267,38 @@ namespace tunnel s << " ⇒ "; } + ZeroHopsOutboundTunnel::ZeroHopsOutboundTunnel (): + OutboundTunnel (std::make_shared ()), + m_NumSentBytes (0) + { + } + + void ZeroHopsOutboundTunnel::SendTunnelDataMsg (const std::vector& msgs) + { + for (auto& msg : msgs) + { + switch (msg.deliveryType) + { + case eDeliveryTypeLocal: + i2p::HandleI2NPMessage (msg.data); + break; + case eDeliveryTypeTunnel: + i2p::transport::transports.SendMessage (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data)); + break; + case eDeliveryTypeRouter: + i2p::transport::transports.SendMessage (msg.hash, msg.data); + break; + default: + LogPrint (eLogError, "Tunnel: Unknown delivery type ", (int)msg.deliveryType); + } + } + } + + void ZeroHopsOutboundTunnel::Print (std::stringstream& s) const + { + s << GetTunnelID () << ":me ⇒ "; + } + Tunnels tunnels; Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr), @@ -661,6 +692,7 @@ namespace tunnel { LogPrint (eLogDebug, "Tunnel: Creating zero hops inbound tunnel"); CreateZeroHopsInboundTunnel (); + CreateZeroHopsOutboundTunnel (); if (!m_ExploratoryPool) { m_ExploratoryPool = CreateTunnelPool (2, 2, 5, 5); // 2-hop exploratory, 5 tunnels @@ -785,23 +817,17 @@ namespace tunnel void Tunnels::CreateZeroHopsInboundTunnel () { - /*CreateTunnel ( - std::make_shared (std::vector > - { - i2p::context.GetIdentity () - }));*/ auto inboundTunnel = std::make_shared (); m_InboundTunnels.push_back (inboundTunnel); m_Tunnels[inboundTunnel->GetTunnelID ()] = inboundTunnel; - - // create paired outbound tunnel, TODO: move to separate function - CreateTunnel ( - std::make_shared (std::vector > - { - i2p::context.GetIdentity () - }, inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ())); } + void Tunnels::CreateZeroHopsOutboundTunnel () + { + m_OutboundTunnels.push_back (std::make_shared ()); + // we don't insert into m_Tunnels + } + int Tunnels::GetTransitTunnelsExpirationTimeout () { int timeout = 0; diff --git a/Tunnel.h b/Tunnel.h index 34d0a0ab..fe6022ac 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -100,9 +100,9 @@ namespace tunnel Tunnel (config), m_Gateway (this), m_EndpointIdentHash (config->GetLastIdentHash ()) {}; void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr msg); - void SendTunnelDataMsg (const std::vector& msgs); // multiple messages + virtual void SendTunnelDataMsg (const std::vector& msgs); // multiple messages const i2p::data::IdentHash& GetEndpointIdentHash () const { return m_EndpointIdentHash; }; - size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); }; + virtual size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); }; void Print (std::stringstream& s) const; // implements TunnelBase @@ -143,6 +143,20 @@ namespace tunnel size_t m_NumReceivedBytes; }; + class ZeroHopsOutboundTunnel: public OutboundTunnel + { + public: + + ZeroHopsOutboundTunnel (); + void SendTunnelDataMsg (const std::vector& msgs); + void Print (std::stringstream& s) const; + size_t GetNumSentBytes () const { return m_NumSentBytes; }; + + private: + + size_t m_NumSentBytes; + }; + class Tunnels { public: @@ -191,7 +205,8 @@ namespace tunnel void ManageTunnelPools (); void CreateZeroHopsInboundTunnel (); - + void CreateZeroHopsOutboundTunnel (); + private: bool m_IsRunning;