Browse Source

specify number of hops for inbound tunnels

pull/81/head
orignal 11 years ago
parent
commit
6ce3e41a70
  1. 33
      TunnelPool.cpp

33
TunnelPool.cpp

@ -167,17 +167,28 @@ namespace tunnel
OutboundTunnel * outboundTunnel = m_OutboundTunnels.size () > 0 ? OutboundTunnel * outboundTunnel = m_OutboundTunnels.size () > 0 ?
*m_OutboundTunnels.begin () : tunnels.GetNextOutboundTunnel (); *m_OutboundTunnels.begin () : tunnels.GetNextOutboundTunnel ();
LogPrint ("Creating destination inbound tunnel..."); LogPrint ("Creating destination inbound tunnel...");
auto firstHop = i2p::data::netdb.GetRandomRouter (outboundTunnel ? outboundTunnel->GetEndpointRouter () : nullptr); const i2p::data::RouterInfo * prevHop = &i2p::context.GetRouterInfo ();
auto secondHop = outboundTunnel ? outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router : nullptr; std::vector<const i2p::data::RouterInfo *> hops;
if (!secondHop || secondHop->GetIdentHash () == i2p::context.GetIdentHash ()) int numHops = m_NumHops;
secondHop = i2p::data::netdb.GetRandomRouter (firstHop); if (outboundTunnel)
auto * tunnel = tunnels.CreateTunnel<InboundTunnel> ( {
new TunnelConfig (std::vector<const i2p::data::RouterInfo *> // last hop
{ auto hop = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router;
firstHop, if (hop->GetIdentHash () != i2p::context.GetIdentHash ()) // outbound shouldn't be zero-hop tunnel
secondHop {
}), prevHop = hop;
outboundTunnel); hops.push_back (prevHop);
numHops--;
}
}
for (int i = 0; i < numHops; i++)
{
auto hop = i2p::data::netdb.GetRandomRouter (prevHop);
prevHop = hop;
hops.push_back (hop);
}
std::reverse (hops.begin (), hops.end ());
auto * tunnel = tunnels.CreateTunnel<InboundTunnel> (new TunnelConfig (hops));
tunnel->SetTunnelPool (this); tunnel->SetTunnelPool (this);
} }

Loading…
Cancel
Save