From 24c00b09857233771b7615ca47a716e40f42c658 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 23 Jan 2015 12:48:25 -0500 Subject: [PATCH] schedule routing session cleanup --- Destination.cpp | 18 +++++++++++++++++- Destination.h | 4 +++- Garlic.cpp | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index a27ddba1..23567817 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -17,7 +17,7 @@ namespace client const std::map * params): m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service), m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic), m_PublishReplyToken (0), - m_DatagramDestination (nullptr), m_PublishConfirmationTimer (m_Service) + m_DatagramDestination (nullptr), m_PublishConfirmationTimer (m_Service), m_CleanupTimer (m_Service) { i2p::crypto::GenerateElGamalKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); int inboundTunnelLen = DEFAULT_INBOUND_TUNNEL_LENGTH; @@ -91,6 +91,10 @@ namespace client m_Pool->SetActive (true); m_Thread = new std::thread (std::bind (&ClientDestination::Run, this)); m_StreamingDestination->Start (); + + m_CleanupTimer.expires_from_now (boost::posix_time::minutes (DESTINATION_CLEANUP_TIMEOUT)); + m_CleanupTimer.async_wait (std::bind (&ClientDestination::HandleCleanupTimer, + this, std::placeholders::_1)); } } @@ -98,6 +102,7 @@ namespace client { if (m_IsRunning) { + m_CleanupTimer.cancel (); m_IsRunning = false; m_StreamingDestination->Stop (); if (m_DatagramDestination) @@ -556,6 +561,17 @@ namespace client } } } + } + + void ClientDestination::HandleCleanupTimer (const boost::system::error_code& ecode) + { + if (ecode != boost::asio::error::operation_aborted) + { + CleanupRoutingSessions (); + m_CleanupTimer.expires_from_now (boost::posix_time::minutes (DESTINATION_CLEANUP_TIMEOUT)); + m_CleanupTimer.async_wait (std::bind (&ClientDestination::HandleCleanupTimer, + this, std::placeholders::_1)); + } } } } diff --git a/Destination.h b/Destination.h index ffb96d2a..4104c426 100644 --- a/Destination.h +++ b/Destination.h @@ -29,6 +29,7 @@ namespace client const int LEASESET_REQUEST_TIMEOUT = 5; // in seconds const int MAX_LEASESET_REQUEST_TIMEOUT = 40; // in seconds const int MAX_NUM_FLOODFILLS_PER_REQUEST = 7; + const int DESTINATION_CLEANUP_TIMEOUT = 20; // in minutes // I2CP const char I2CP_PARAM_INBOUND_TUNNEL_LENGTH[] = "inbound.length"; @@ -109,6 +110,7 @@ namespace client void RequestLeaseSet (const i2p::data::IdentHash& dest, RequestComplete requestComplete); bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr nextFloodfill, LeaseSetRequest * request); void HandleRequestTimoutTimer (const boost::system::error_code& ecode, const i2p::data::IdentHash& dest); + void HandleCleanupTimer (const boost::system::error_code& ecode); private: @@ -130,7 +132,7 @@ namespace client i2p::stream::StreamingDestination * m_StreamingDestination; i2p::datagram::DatagramDestination * m_DatagramDestination; - boost::asio::deadline_timer m_PublishConfirmationTimer; + boost::asio::deadline_timer m_PublishConfirmationTimer, m_CleanupTimer; public: diff --git a/Garlic.cpp b/Garlic.cpp index fea0b5af..a4ca69cd 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -538,7 +538,10 @@ namespace garlic for (auto it = m_Sessions.begin (); it != m_Sessions.end ();) { if (!it->second->CleanupExpiredTags ()) + { + LogPrint (eLogInfo, "Routing session to ", it->first.ToBase32 (), " deleted"); it = m_Sessions.erase (it); + } else it++; }