Browse Source

pick established tunnels only

pull/93/head
orignal 10 years ago
parent
commit
c025bcfdfc
  1. 4
      Tunnel.cpp
  2. 20
      TunnelPool.cpp

4
Tunnel.cpp

@ -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++;
} }

20
TunnelPool.cpp

@ -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);

Loading…
Cancel
Save