|
|
@ -70,7 +70,7 @@ namespace tunnel |
|
|
|
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex); |
|
|
|
m_OutboundTunnels.insert (createdTunnel); |
|
|
|
m_OutboundTunnels.insert (createdTunnel); |
|
|
|
} |
|
|
|
} |
|
|
|
CreatePairedInboundTunnel (createdTunnel); |
|
|
|
//CreatePairedInboundTunnel (createdTunnel);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TunnelPool::TunnelExpired (std::shared_ptr<OutboundTunnel> expiredTunnel) |
|
|
|
void TunnelPool::TunnelExpired (std::shared_ptr<OutboundTunnel> expiredTunnel) |
|
|
@ -291,41 +291,51 @@ namespace tunnel |
|
|
|
return hop; |
|
|
|
return hop; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TunnelPool::CreateInboundTunnel () |
|
|
|
bool TunnelPool::SelectPeers (std::vector<std::shared_ptr<const i2p::data::RouterInfo> >& hops) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto outboundTunnel = GetNextOutboundTunnel (); |
|
|
|
|
|
|
|
if (!outboundTunnel) |
|
|
|
|
|
|
|
outboundTunnel = tunnels.GetNextOutboundTunnel (); |
|
|
|
|
|
|
|
LogPrint ("Creating destination inbound tunnel..."); |
|
|
|
|
|
|
|
auto prevHop = i2p::context.GetSharedRouterInfo (); |
|
|
|
auto prevHop = i2p::context.GetSharedRouterInfo (); |
|
|
|
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops; |
|
|
|
|
|
|
|
int numHops = m_NumInboundHops; |
|
|
|
int numHops = m_NumInboundHops; |
|
|
|
if (outboundTunnel) |
|
|
|
if (i2p::transport::transports.GetNumPeers () > 25) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// last hop
|
|
|
|
auto r = i2p::transport::transports.GetRandomPeer (); |
|
|
|
auto hop = outboundTunnel->GetTunnelConfig ()->GetFirstHop ()->router; |
|
|
|
if (r && !r->GetProfile ()->IsBad ()) |
|
|
|
if (hop->GetIdentHash () != i2p::context.GetIdentHash ()) // outbound shouldn't be zero-hop tunnel
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
prevHop = hop; |
|
|
|
prevHop = r; |
|
|
|
hops.push_back (prevHop); |
|
|
|
hops.push_back (r); |
|
|
|
numHops--; |
|
|
|
numHops--; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numHops; i++) |
|
|
|
for (int i = 0; i < numHops; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto hop = SelectNextHop (prevHop); |
|
|
|
auto hop = SelectNextHop (prevHop); |
|
|
|
if (!hop) |
|
|
|
if (!hop) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "Can't select next hop for inbound tunnel"); |
|
|
|
LogPrint (eLogError, "Can't select next hop"); |
|
|
|
return; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
prevHop = hop; |
|
|
|
prevHop = hop; |
|
|
|
hops.push_back (hop); |
|
|
|
hops.push_back (hop); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TunnelPool::CreateInboundTunnel () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto outboundTunnel = GetNextOutboundTunnel (); |
|
|
|
|
|
|
|
if (!outboundTunnel) |
|
|
|
|
|
|
|
outboundTunnel = tunnels.GetNextOutboundTunnel (); |
|
|
|
|
|
|
|
LogPrint ("Creating destination inbound tunnel..."); |
|
|
|
|
|
|
|
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops; |
|
|
|
|
|
|
|
if (SelectPeers (hops)) |
|
|
|
|
|
|
|
{ |
|
|
|
std::reverse (hops.begin (), hops.end ()); |
|
|
|
std::reverse (hops.begin (), hops.end ()); |
|
|
|
auto tunnel = tunnels.CreateTunnel<InboundTunnel> (std::make_shared<TunnelConfig> (hops), outboundTunnel); |
|
|
|
auto tunnel = tunnels.CreateTunnel<InboundTunnel> (std::make_shared<TunnelConfig> (hops), outboundTunnel); |
|
|
|
tunnel->SetTunnelPool (shared_from_this ()); |
|
|
|
tunnel->SetTunnelPool (shared_from_this ()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LogPrint (eLogError, "Can't create inbound tunnel. No peers available"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TunnelPool::RecreateInboundTunnel (std::shared_ptr<InboundTunnel> tunnel) |
|
|
|
void TunnelPool::RecreateInboundTunnel (std::shared_ptr<InboundTunnel> tunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -345,35 +355,16 @@ namespace tunnel |
|
|
|
if (inboundTunnel) |
|
|
|
if (inboundTunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Creating destination outbound tunnel..."); |
|
|
|
LogPrint ("Creating destination outbound tunnel..."); |
|
|
|
int numHops = m_NumOutboundHops; |
|
|
|
|
|
|
|
auto prevHop = i2p::context.GetSharedRouterInfo (); |
|
|
|
|
|
|
|
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops; |
|
|
|
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops; |
|
|
|
if (i2p::transport::transports.GetNumPeers () > 25) |
|
|
|
if (SelectPeers (hops)) |
|
|
|
{ |
|
|
|
|
|
|
|
auto r = i2p::transport::transports.GetRandomPeer (); |
|
|
|
|
|
|
|
if (r) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
prevHop = r; |
|
|
|
|
|
|
|
hops.push_back (r); |
|
|
|
|
|
|
|
numHops--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < numHops; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto hop = SelectNextHop (prevHop); |
|
|
|
|
|
|
|
if (!hop) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "Can't select next hop for outbound tunnel"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
prevHop = hop; |
|
|
|
|
|
|
|
hops.push_back (hop); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto tunnel = tunnels.CreateTunnel<OutboundTunnel> ( |
|
|
|
auto tunnel = tunnels.CreateTunnel<OutboundTunnel> ( |
|
|
|
std::make_shared<TunnelConfig> (hops, inboundTunnel->GetTunnelConfig ())); |
|
|
|
std::make_shared<TunnelConfig> (hops, inboundTunnel->GetTunnelConfig ())); |
|
|
|
tunnel->SetTunnelPool (shared_from_this ()); |
|
|
|
tunnel->SetTunnelPool (shared_from_this ()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LogPrint (eLogError, "Can't create outbound tunnel. No peers available"); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogError, "Can't create outbound tunnel. No inbound tunnels found"); |
|
|
|
LogPrint (eLogError, "Can't create outbound tunnel. No inbound tunnels found"); |
|
|
|
} |
|
|
|
} |
|
|
|