mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
specify number of hops for inbound tunnels
This commit is contained in:
parent
ad65e52ce0
commit
6ce3e41a70
@ -167,17 +167,28 @@ namespace tunnel
|
||||
OutboundTunnel * outboundTunnel = m_OutboundTunnels.size () > 0 ?
|
||||
*m_OutboundTunnels.begin () : tunnels.GetNextOutboundTunnel ();
|
||||
LogPrint ("Creating destination inbound tunnel...");
|
||||
auto firstHop = i2p::data::netdb.GetRandomRouter (outboundTunnel ? outboundTunnel->GetEndpointRouter () : nullptr);
|
||||
auto secondHop = outboundTunnel ? outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router : nullptr;
|
||||
if (!secondHop || secondHop->GetIdentHash () == i2p::context.GetIdentHash ())
|
||||
secondHop = i2p::data::netdb.GetRandomRouter (firstHop);
|
||||
auto * tunnel = tunnels.CreateTunnel<InboundTunnel> (
|
||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||
{
|
||||
firstHop,
|
||||
secondHop
|
||||
}),
|
||||
outboundTunnel);
|
||||
const i2p::data::RouterInfo * prevHop = &i2p::context.GetRouterInfo ();
|
||||
std::vector<const i2p::data::RouterInfo *> hops;
|
||||
int numHops = m_NumHops;
|
||||
if (outboundTunnel)
|
||||
{
|
||||
// last hop
|
||||
auto hop = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router;
|
||||
if (hop->GetIdentHash () != i2p::context.GetIdentHash ()) // outbound shouldn't be zero-hop tunnel
|
||||
{
|
||||
prevHop = hop;
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user