From 98669eff4fe0a59b8e2c12651b9d5410d1c4a80e Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 25 Sep 2024 11:13:01 -0400 Subject: [PATCH] delete session by hash from table if expired or terminated --- libi2pd/SSU2.cpp | 12 ++++++++++-- libi2pd/SSU2.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libi2pd/SSU2.cpp b/libi2pd/SSU2.cpp index cdc127b11fb..17bc1912cdc 100644 --- a/libi2pd/SSU2.cpp +++ b/libi2pd/SSU2.cpp @@ -515,11 +515,19 @@ namespace transport return m_PendingOutgoingSessions.emplace (session->GetRemoteEndpoint (), session).second; } - std::shared_ptr SSU2Server::FindSession (const i2p::data::IdentHash& ident) const + std::shared_ptr SSU2Server::FindSession (const i2p::data::IdentHash& ident) { auto it = m_SessionsByRouterHash.find (ident); if (it != m_SessionsByRouterHash.end ()) - return it->second.lock (); + { + if (!it->second.expired ()) + { + auto s = it->second.lock (); + if (s && s->GetState () != eSSU2SessionStateTerminated) + return s; + } + m_SessionsByRouterHash.erase (it); + } return nullptr; } diff --git a/libi2pd/SSU2.h b/libi2pd/SSU2.h index 84a1307515c..2c5e8cc6fae 100644 --- a/libi2pd/SSU2.h +++ b/libi2pd/SSU2.h @@ -86,7 +86,7 @@ namespace transport void AddSessionByRouterHash (std::shared_ptr session); bool AddPendingOutgoingSession (std::shared_ptr session); void RemovePendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep); - std::shared_ptr FindSession (const i2p::data::IdentHash& ident) const; + std::shared_ptr FindSession (const i2p::data::IdentHash& ident); std::shared_ptr FindPendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep) const; std::shared_ptr GetRandomPeerTestSession (i2p::data::RouterInfo::CompatibleTransports remoteTransports, const i2p::data::IdentHash& excluded);