diff --git a/Tunnel.cpp b/Tunnel.cpp index b4cd41a0..76f05a62 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -353,7 +353,10 @@ namespace tunnel { LogPrint ("Creating one hop outbound tunnel..."); CreateTunnel ( - new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (), + new TunnelConfig (std::vector + { + i2p::data::netdb.GetRandomNTCPRouter () + }, inboundTunnel->GetTunnelConfig ())); } else @@ -361,8 +364,11 @@ namespace tunnel //OutboundTunnel * outboundTunnel = GetNextOutboundTunnel (); LogPrint ("Creating two hops outbound tunnel..."); CreateTunnel ( - new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (), - i2p::data::netdb.GetRandomNTCPRouter (), + new TunnelConfig (std::vector + { + i2p::data::netdb.GetRandomNTCPRouter (), + i2p::data::netdb.GetRandomNTCPRouter () + }, inboundTunnel->GetTunnelConfig ())/*, outboundTunnel*/); } @@ -396,7 +402,11 @@ namespace tunnel if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3) { LogPrint ("Creating one hop inbound tunnel..."); - CreateTunnel (new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter ())); + CreateTunnel ( + new TunnelConfig (std::vector + { + i2p::data::netdb.GetRandomNTCPRouter () + })); } else { @@ -404,9 +414,12 @@ namespace tunnel LogPrint ("Creating two hops inbound tunnel..."); auto router = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router; CreateTunnel ( - new TunnelConfig (i2p::data::netdb.GetRandomNTCPRouter (), - router != &i2p::context.GetRouterInfo () ? router : i2p::data::netdb.GetRandomNTCPRouter ()), - outboundTunnel); + new TunnelConfig (std::vector + { + i2p::data::netdb.GetRandomNTCPRouter (), + router != &i2p::context.GetRouterInfo () ? router : i2p::data::netdb.GetRandomNTCPRouter () + }), + outboundTunnel); } } } @@ -457,7 +470,10 @@ namespace tunnel void Tunnels::CreateZeroHopsInboundTunnel () { CreateTunnel ( - new TunnelConfig (&i2p::context.GetRouterInfo ())); + new TunnelConfig (std::vector + { + &i2p::context.GetRouterInfo () + })); } OutboundTunnel * Tunnels::CreateOneHopOutboundTestTunnel (InboundTunnel * replyTunnel) @@ -471,7 +487,9 @@ namespace tunnel if (peer) { const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo (); - return CreateTunnel (new TunnelConfig (&router), outboundTunnel); + return CreateTunnel ( + new TunnelConfig (std::vector{&router}), + outboundTunnel); } else LogPrint ("No established peers"); @@ -490,7 +508,11 @@ namespace tunnel { const i2p::data::RouterInfo& router = peer->GetRemoteRouterInfo (); return CreateTunnel ( - new TunnelConfig (&router, &i2p::context.GetRouterInfo ()), + new TunnelConfig (std::vector + { + &router, + &i2p::context.GetRouterInfo () + }), outboundTunnel); } else diff --git a/TunnelConfig.h b/TunnelConfig.h index 653fe56d..29fb8575 100644 --- a/TunnelConfig.h +++ b/TunnelConfig.h @@ -3,6 +3,7 @@ #include #include +#include #include "RouterInfo.h" #include "RouterContext.h" @@ -83,34 +84,30 @@ namespace tunnel { public: - TunnelConfig (const i2p::data::RouterInfo * peer, TunnelConfig * replyTunnelConfig = 0) // one hop - { - m_FirstHop = new TunnelHopConfig (peer); - m_LastHop = m_FirstHop; - - if (replyTunnelConfig) // outbound - { - m_FirstHop->isGateway = false; - m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ()); - } - else - m_FirstHop->SetNextRouter (&i2p::context.GetRouterInfo ()); - } - TunnelConfig (const i2p::data::RouterInfo * peer1, const i2p::data::RouterInfo * peer2, TunnelConfig * replyTunnelConfig = 0) // two hops + TunnelConfig (std::vector peers, + TunnelConfig * replyTunnelConfig = 0) // replyTunnelConfig=0 means inbound { - m_FirstHop = new TunnelHopConfig (peer1); - m_LastHop = new TunnelHopConfig (peer2); - m_FirstHop->SetNext (m_LastHop); + TunnelHopConfig * prev = nullptr; + for (auto it: peers) + { + auto hop = new TunnelHopConfig (it); + if (prev) + prev->SetNext (hop); + else + m_FirstHop = hop; + prev = hop; + } + m_LastHop = prev; - if (replyTunnelConfig) + if (replyTunnelConfig) // outbound { m_FirstHop->isGateway = false; m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ()); } - else + else // inbound m_LastHop->SetNextRouter (&i2p::context.GetRouterInfo ()); - } + } ~TunnelConfig () {