|
|
|
@ -329,8 +329,9 @@ namespace tunnel
|
|
|
|
|
bool TunnelPool::SelectPeers (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers, bool isInbound)
|
|
|
|
|
{
|
|
|
|
|
if (m_ExplicitPeers) return SelectExplicitPeers (peers, isInbound);
|
|
|
|
|
auto prevHop = i2p::context.GetSharedRouterInfo ();
|
|
|
|
|
int numHops = isInbound ? m_NumInboundHops : m_NumOutboundHops;
|
|
|
|
|
if (numHops <= 0) return true; // peers is empty
|
|
|
|
|
auto prevHop = i2p::context.GetSharedRouterInfo ();
|
|
|
|
|
if (i2p::transport::transports.GetNumPeers () > 25)
|
|
|
|
|
{
|
|
|
|
|
auto r = i2p::transport::transports.GetRandomPeer ();
|
|
|
|
@ -390,8 +391,10 @@ namespace tunnel
|
|
|
|
|
if (SelectPeers (peers, true))
|
|
|
|
|
{
|
|
|
|
|
std::reverse (peers.begin (), peers.end ());
|
|
|
|
|
auto tunnel = tunnels.CreateTunnel<InboundTunnel> (std::make_shared<TunnelConfig> (peers), outboundTunnel);
|
|
|
|
|
auto tunnel = tunnels.CreateInboundTunnel (std::make_shared<TunnelConfig> (peers), outboundTunnel);
|
|
|
|
|
tunnel->SetTunnelPool (shared_from_this ());
|
|
|
|
|
if (tunnel->IsEstablished ()) // zero hops
|
|
|
|
|
TunnelCreated (tunnel);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
LogPrint (eLogError, "Tunnels: Can't create inbound tunnel, no peers available");
|
|
|
|
@ -403,8 +406,10 @@ namespace tunnel
|
|
|
|
|
if (!outboundTunnel)
|
|
|
|
|
outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
|
|
|
|
LogPrint (eLogDebug, "Tunnels: Re-creating destination inbound tunnel...");
|
|
|
|
|
auto newTunnel = tunnels.CreateTunnel<InboundTunnel> (std::make_shared<TunnelConfig>(tunnel->GetPeers ()), outboundTunnel);
|
|
|
|
|
auto newTunnel = tunnels.CreateInboundTunnel (std::make_shared<TunnelConfig>(tunnel->GetPeers ()), outboundTunnel);
|
|
|
|
|
newTunnel->SetTunnelPool (shared_from_this());
|
|
|
|
|
if (newTunnel->IsEstablished ()) // zero hops
|
|
|
|
|
TunnelCreated (newTunnel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TunnelPool::CreateOutboundTunnel ()
|
|
|
|
@ -418,9 +423,11 @@ namespace tunnel
|
|
|
|
|
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > peers;
|
|
|
|
|
if (SelectPeers (peers, false))
|
|
|
|
|
{
|
|
|
|
|
auto tunnel = tunnels.CreateTunnel<OutboundTunnel> (
|
|
|
|
|
auto tunnel = tunnels.CreateOutboundTunnel (
|
|
|
|
|
std::make_shared<TunnelConfig> (peers, inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()));
|
|
|
|
|
tunnel->SetTunnelPool (shared_from_this ());
|
|
|
|
|
if (tunnel->IsEstablished ()) // zero hops
|
|
|
|
|
TunnelCreated (tunnel);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
LogPrint (eLogError, "Tunnels: Can't create outbound tunnel, no peers available");
|
|
|
|
@ -437,10 +444,12 @@ namespace tunnel
|
|
|
|
|
if (inboundTunnel)
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogDebug, "Tunnels: Re-creating destination outbound tunnel...");
|
|
|
|
|
auto newTunnel = tunnels.CreateTunnel<OutboundTunnel> (
|
|
|
|
|
auto newTunnel = tunnels.CreateOutboundTunnel (
|
|
|
|
|
std::make_shared<TunnelConfig> (tunnel->GetPeers (),
|
|
|
|
|
inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()));
|
|
|
|
|
newTunnel->SetTunnelPool (shared_from_this ());
|
|
|
|
|
if (newTunnel->IsEstablished ()) // zero hops
|
|
|
|
|
TunnelCreated (newTunnel);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
LogPrint (eLogDebug, "Tunnels: Can't re-create outbound tunnel, no inbound tunnels found");
|
|
|
|
@ -449,7 +458,7 @@ namespace tunnel
|
|
|
|
|
void TunnelPool::CreatePairedInboundTunnel (std::shared_ptr<OutboundTunnel> outboundTunnel)
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogDebug, "Tunnels: Creating paired inbound tunnel...");
|
|
|
|
|
auto tunnel = tunnels.CreateTunnel<InboundTunnel> (std::make_shared<TunnelConfig>(outboundTunnel->GetInvertedPeers ()), outboundTunnel);
|
|
|
|
|
auto tunnel = tunnels.CreateInboundTunnel (std::make_shared<TunnelConfig>(outboundTunnel->GetInvertedPeers ()), outboundTunnel);
|
|
|
|
|
tunnel->SetTunnelPool (shared_from_this ());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|