diff --git a/Destination.cpp b/Destination.cpp index 233946ad..f2dac631 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -664,7 +664,7 @@ namespace client { if (ecode != boost::asio::error::operation_aborted) { - CleanupRoutingSessions (); + CleanupExpiredTags (); CleanupRemoteLeaseSets (); m_CleanupTimer.expires_from_now (boost::posix_time::minutes (DESTINATION_CLEANUP_TIMEOUT)); m_CleanupTimer.async_wait (std::bind (&ClientDestination::HandleCleanupTimer, diff --git a/Garlic.cpp b/Garlic.cpp index d62b6fe3..88e255ff 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -409,28 +409,6 @@ namespace garlic else LogPrint (eLogError, "Garlic: Failed to decrypt message"); } - - // cleanup expired tags - uint32_t ts = i2p::util::GetSecondsSinceEpoch (); - if (ts > m_LastTagsCleanupTime + INCOMING_TAGS_EXPIRATION_TIMEOUT) - { - if (m_LastTagsCleanupTime) - { - int numExpiredTags = 0; - for (auto it = m_Tags.begin (); it != m_Tags.end ();) - { - if (ts > it->first.creationTime + INCOMING_TAGS_EXPIRATION_TIMEOUT) - { - numExpiredTags++; - it = m_Tags.erase (it); - } - else - it++; - } - LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " tags expired for ", GetIdentHash().ToBase64 ()); - } - m_LastTagsCleanupTime = ts; - } } void GarlicDestination::HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr decryption, @@ -570,8 +548,25 @@ namespace garlic return session; } - void GarlicDestination::CleanupRoutingSessions () + void GarlicDestination::CleanupExpiredTags () { + // incoming + uint32_t ts = i2p::util::GetSecondsSinceEpoch (); + int numExpiredTags = 0; + for (auto it = m_Tags.begin (); it != m_Tags.end ();) + { + if (ts > it->first.creationTime + INCOMING_TAGS_EXPIRATION_TIMEOUT) + { + numExpiredTags++; + it = m_Tags.erase (it); + } + else + it++; + } + if (numExpiredTags > 0) + LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " tags expired for ", GetIdentHash().ToBase64 ()); + + // outgoing std::unique_lock l(m_SessionsMutex); for (auto it = m_Sessions.begin (); it != m_Sessions.end ();) { diff --git a/Garlic.h b/Garlic.h index 73231d10..b42f92cf 100644 --- a/Garlic.h +++ b/Garlic.h @@ -126,12 +126,12 @@ namespace garlic { public: - GarlicDestination (): m_NumTags (32), m_LastTagsCleanupTime (0) {}; // 32 tags by default + GarlicDestination (): m_NumTags (32) {}; // 32 tags by default ~GarlicDestination (); void SetNumTags (int numTags) { m_NumTags = numTags; }; std::shared_ptr GetRoutingSession (std::shared_ptr destination, bool attachLeaseSet); - void CleanupRoutingSessions (); + void CleanupExpiredTags (); void RemoveDeliveryStatusSession (uint32_t msgID); std::shared_ptr WrapMessage (std::shared_ptr destination, std::shared_ptr msg, bool attachLeaseSet = false); @@ -167,7 +167,6 @@ namespace garlic std::map m_Sessions; // incoming std::map> m_Tags; - uint32_t m_LastTagsCleanupTime; // DeliveryStatus std::map m_DeliveryStatusSessions; // msgID -> session