|
|
@ -65,7 +65,7 @@ namespace tunnel |
|
|
|
for (auto it : m_InboundTunnels) |
|
|
|
for (auto it : m_InboundTunnels) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (i >= num) break; |
|
|
|
if (i >= num) break; |
|
|
|
if (!it->IsFailed ()) |
|
|
|
if (it->IsEstablished ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
v.push_back (it); |
|
|
|
v.push_back (it); |
|
|
|
i++; |
|
|
|
i++; |
|
|
@ -89,23 +89,25 @@ namespace tunnel |
|
|
|
typename TTunnels::value_type suggested) |
|
|
|
typename TTunnels::value_type suggested) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (tunnels.empty ()) return nullptr; |
|
|
|
if (tunnels.empty ()) return nullptr; |
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch (); |
|
|
|
if (suggested && tunnels.count (suggested) > 0 && suggested->IsEstablished ()) |
|
|
|
if (suggested && tunnels.count (suggested) > 0 && |
|
|
|
|
|
|
|
ts + TUNNEL_EXPIRATION_THRESHOLD <= suggested->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
|
|
|
|
return suggested; |
|
|
|
return suggested; |
|
|
|
for (auto it: tunnels) |
|
|
|
for (auto it: tunnels) |
|
|
|
if (!it->IsFailed () && ts + TUNNEL_EXPIRATION_THRESHOLD <= |
|
|
|
if (it->IsEstablished ()) |
|
|
|
it->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) |
|
|
|
|
|
|
|
return it; |
|
|
|
return it; |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TunnelPool::CreateTunnels () |
|
|
|
void TunnelPool::CreateTunnels () |
|
|
|
{ |
|
|
|
{ |
|
|
|
int num = m_InboundTunnels.size (); |
|
|
|
int num = 0; |
|
|
|
|
|
|
|
for (auto it : m_InboundTunnels) |
|
|
|
|
|
|
|
if (it->IsEstablished ()) num++; |
|
|
|
for (int i = num; i < m_NumTunnels; i++) |
|
|
|
for (int i = num; i < m_NumTunnels; i++) |
|
|
|
CreateInboundTunnel (); |
|
|
|
CreateInboundTunnel (); |
|
|
|
num = m_OutboundTunnels.size (); |
|
|
|
|
|
|
|
|
|
|
|
num = 0; |
|
|
|
|
|
|
|
for (auto it : m_OutboundTunnels) |
|
|
|
|
|
|
|
if (it->IsEstablished ()) num++; |
|
|
|
for (int i = num; i < m_NumTunnels; i++) |
|
|
|
for (int i = num; i < m_NumTunnels; i++) |
|
|
|
CreateOutboundTunnel (); |
|
|
|
CreateOutboundTunnel (); |
|
|
|
} |
|
|
|
} |
|
|
@ -173,7 +175,9 @@ namespace tunnel |
|
|
|
if (it != m_Tests.end ()) |
|
|
|
if (it != m_Tests.end ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// restore from test failed state if any
|
|
|
|
// restore from test failed state if any
|
|
|
|
|
|
|
|
if (it->second.first->GetState () == eTunnelStateTestFailed) |
|
|
|
it->second.first->SetState (eTunnelStateEstablished); |
|
|
|
it->second.first->SetState (eTunnelStateEstablished); |
|
|
|
|
|
|
|
if (it->second.second->GetState () == eTunnelStateTestFailed) |
|
|
|
it->second.second->SetState (eTunnelStateEstablished); |
|
|
|
it->second.second->SetState (eTunnelStateEstablished); |
|
|
|
LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - be64toh (deliveryStatus->timestamp), " milliseconds"); |
|
|
|
LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - be64toh (deliveryStatus->timestamp), " milliseconds"); |
|
|
|
m_Tests.erase (it); |
|
|
|
m_Tests.erase (it); |
|
|
|