From 27bd19370864244543f585cf5adbcb925789fc12 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 14 Apr 2015 21:37:21 -0400 Subject: [PATCH] re-create tunnel before expiration --- Tunnel.cpp | 26 ++++++++++++++++---------- TunnelPool.cpp | 2 -- TunnelPool.h | 4 ++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Tunnel.cpp b/Tunnel.cpp index 29c494f2..f189f5c3 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -535,17 +535,20 @@ namespace tunnel if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) { LogPrint ("Tunnel ", tunnel->GetTunnelID (), " expired"); - { - auto pool = tunnel->GetTunnelPool (); - if (pool) - pool->TunnelExpired (tunnel); - } + auto pool = tunnel->GetTunnelPool (); + if (pool) + pool->TunnelExpired (tunnel); it = m_OutboundTunnels.erase (it); } else { if (tunnel->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) + { tunnel->SetState (eTunnelStateExpiring); + auto pool = tunnel->GetTunnelPool (); + if (pool) + pool->RecreateOutboundTunnel (tunnel); + } it++; } } @@ -575,17 +578,20 @@ namespace tunnel if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) { LogPrint ("Tunnel ", tunnel->GetTunnelID (), " expired"); - { - auto pool = tunnel->GetTunnelPool (); - if (pool) - pool->TunnelExpired (tunnel); - } + auto pool = tunnel->GetTunnelPool (); + if (pool) + pool->TunnelExpired (tunnel); it = m_InboundTunnels.erase (it); } else { if (tunnel->IsEstablished () && ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) + { tunnel->SetState (eTunnelStateExpiring); + auto pool = tunnel->GetTunnelPool (); + if (pool) + pool->RecreateInboundTunnel (tunnel); + } it++; } } diff --git a/TunnelPool.cpp b/TunnelPool.cpp index e412d09c..fd40565a 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -56,7 +56,6 @@ namespace tunnel expiredTunnel->SetTunnelPool (nullptr); for (auto it: m_Tests) if (it.second.second == expiredTunnel) it.second.second = nullptr; - RecreateInboundTunnel (expiredTunnel); std::unique_lock l(m_InboundTunnelsMutex); m_InboundTunnels.erase (expiredTunnel); @@ -77,7 +76,6 @@ namespace tunnel expiredTunnel->SetTunnelPool (nullptr); for (auto it: m_Tests) if (it.second.first == expiredTunnel) it.second.first = nullptr; - RecreateOutboundTunnel (expiredTunnel); std::unique_lock l(m_OutboundTunnelsMutex); m_OutboundTunnels.erase (expiredTunnel); diff --git a/TunnelPool.h b/TunnelPool.h index ee0687cc..fa7b1c16 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -38,6 +38,8 @@ namespace tunnel void TunnelExpired (std::shared_ptr expiredTunnel); void TunnelCreated (std::shared_ptr createdTunnel); void TunnelExpired (std::shared_ptr expiredTunnel); + void RecreateInboundTunnel (std::shared_ptr tunnel); + void RecreateOutboundTunnel (std::shared_ptr tunnel); std::vector > GetInboundTunnels (int num) const; std::shared_ptr GetNextOutboundTunnel (std::shared_ptr excluded = nullptr) const; std::shared_ptr GetNextInboundTunnel (std::shared_ptr excluded = nullptr) const; @@ -54,8 +56,6 @@ namespace tunnel void CreateInboundTunnel (); void CreateOutboundTunnel (); - void RecreateInboundTunnel (std::shared_ptr tunnel); - void RecreateOutboundTunnel (std::shared_ptr tunnel); template typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels, typename TTunnels::value_type excluded) const; std::shared_ptr SelectNextHop (std::shared_ptr prevHop) const;