From 72d52d61bc9ce4810a8a74ac41d20c1393bccebe Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 26 Aug 2014 10:31:32 -0400 Subject: [PATCH] expiring status for tunnels --- Tunnel.cpp | 12 ++++++++++-- Tunnel.h | 4 +++- TunnelPool.h | 1 - 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Tunnel.cpp b/Tunnel.cpp index 369e2bba..e90994ab 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -256,7 +256,7 @@ namespace tunnel size_t minReceived = 0; for (auto it : m_InboundTunnels) { - if (it.second->IsFailed ()) continue; + if (!it.second->IsEstablished ()) continue; if (!tunnel || it.second->GetNumReceivedBytes () < minReceived) { tunnel = it.second; @@ -274,7 +274,7 @@ namespace tunnel for (auto it: m_OutboundTunnels) { if (i >= ind) return it; - if (!it->IsFailed ()) + if (it->IsEstablished ()) { tunnel = it; i++; @@ -408,7 +408,11 @@ namespace tunnel it = m_OutboundTunnels.erase (it); } else + { + if (ts + TUNNEL_EXPIRATION_THRESHOLD > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) + (*it)->SetState (eTunnelStateExpiring); it++; + } } if (m_OutboundTunnels.size () < 5) @@ -441,7 +445,11 @@ namespace tunnel it = m_InboundTunnels.erase (it); } else + { + if (ts + TUNNEL_EXPIRATION_THRESHOLD > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) + it->second->SetState (eTunnelStateExpiring); it++; + } } if (m_InboundTunnels.empty ()) diff --git a/Tunnel.h b/Tunnel.h index 67e0a098..705eebca 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -22,6 +22,7 @@ namespace i2p namespace tunnel { const int TUNNEL_EXPIRATION_TIMEOUT = 660; // 11 minutes + const int TUNNEL_EXPIRATION_THRESHOLD = 60; // 1 minute const int TUNNEL_CREATION_TIMEOUT = 20; // 20 seconds const int STANDARD_NUM_RECORDS = 5; // in VariableTunnelBuild message @@ -30,7 +31,8 @@ namespace tunnel eTunnelStatePending, eTunnelStateEstablished, eTunnelStateTestFailed, - eTunnelStateFailed + eTunnelStateFailed, + eTunnelStateExpiring }; class OutboundTunnel; diff --git a/TunnelPool.h b/TunnelPool.h index daf9d892..855b0409 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -19,7 +19,6 @@ namespace tunnel class InboundTunnel; class OutboundTunnel; - const int TUNNEL_EXPIRATION_THRESHOLD = 60; // 1 minute class TunnelPool // per local destination { public: