mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
pick established tunnels only
This commit is contained in:
parent
a096a3931d
commit
c025bcfdfc
@ -409,7 +409,7 @@ namespace tunnel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ts + TUNNEL_EXPIRATION_THRESHOLD > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
if ((*it)->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||||
(*it)->SetState (eTunnelStateExpiring);
|
(*it)->SetState (eTunnelStateExpiring);
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
@ -446,7 +446,7 @@ namespace tunnel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ts + TUNNEL_EXPIRATION_THRESHOLD > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
if (it->second->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||||
it->second->SetState (eTunnelStateExpiring);
|
it->second->SetState (eTunnelStateExpiring);
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
@ -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,8 +175,10 @@ 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
|
||||||
it->second.first->SetState (eTunnelStateEstablished);
|
if (it->second.first->GetState () == eTunnelStateTestFailed)
|
||||||
it->second.second->SetState (eTunnelStateEstablished);
|
it->second.first->SetState (eTunnelStateEstablished);
|
||||||
|
if (it->second.second->GetState () == eTunnelStateTestFailed)
|
||||||
|
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);
|
||||||
DeleteI2NPMessage (msg);
|
DeleteI2NPMessage (msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user