Browse Source

delete session by hash from table if expired or terminated

pull/2101/head
orignal 2 months ago
parent
commit
98669eff4f
  1. 12
      libi2pd/SSU2.cpp
  2. 2
      libi2pd/SSU2.h

12
libi2pd/SSU2.cpp

@ -515,11 +515,19 @@ namespace transport
return m_PendingOutgoingSessions.emplace (session->GetRemoteEndpoint (), session).second; return m_PendingOutgoingSessions.emplace (session->GetRemoteEndpoint (), session).second;
} }
std::shared_ptr<SSU2Session> SSU2Server::FindSession (const i2p::data::IdentHash& ident) const std::shared_ptr<SSU2Session> SSU2Server::FindSession (const i2p::data::IdentHash& ident)
{ {
auto it = m_SessionsByRouterHash.find (ident); auto it = m_SessionsByRouterHash.find (ident);
if (it != m_SessionsByRouterHash.end ()) 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; return nullptr;
} }

2
libi2pd/SSU2.h

@ -86,7 +86,7 @@ namespace transport
void AddSessionByRouterHash (std::shared_ptr<SSU2Session> session); void AddSessionByRouterHash (std::shared_ptr<SSU2Session> session);
bool AddPendingOutgoingSession (std::shared_ptr<SSU2Session> session); bool AddPendingOutgoingSession (std::shared_ptr<SSU2Session> session);
void RemovePendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep); void RemovePendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep);
std::shared_ptr<SSU2Session> FindSession (const i2p::data::IdentHash& ident) const; std::shared_ptr<SSU2Session> FindSession (const i2p::data::IdentHash& ident);
std::shared_ptr<SSU2Session> FindPendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep) const; std::shared_ptr<SSU2Session> FindPendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep) const;
std::shared_ptr<SSU2Session> GetRandomPeerTestSession (i2p::data::RouterInfo::CompatibleTransports remoteTransports, std::shared_ptr<SSU2Session> GetRandomPeerTestSession (i2p::data::RouterInfo::CompatibleTransports remoteTransports,
const i2p::data::IdentHash& excluded); const i2p::data::IdentHash& excluded);

Loading…
Cancel
Save