1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-02-02 02:44:15 +00:00

terminate duplcated session properly

This commit is contained in:
orignal 2022-12-28 16:47:12 -05:00
parent 5a167316cb
commit 099d9d977f

View File

@ -1313,19 +1313,31 @@ namespace transport
if (!session) return false; if (!session) return false;
if (incoming) if (incoming)
m_PendingIncomingSessions.erase (session->GetRemoteEndpoint ().address ()); m_PendingIncomingSessions.erase (session->GetRemoteEndpoint ().address ());
if (!session->GetRemoteIdentity ()) return false; if (!session->GetRemoteIdentity ())
{
LogPrint (eLogWarning, "NTCP2: Unknown identity for ", session->GetRemoteEndpoint ());
session->Terminate ();
return false;
}
auto& ident = session->GetRemoteIdentity ()->GetIdentHash (); auto& ident = session->GetRemoteIdentity ()->GetIdentHash ();
auto it = m_NTCP2Sessions.find (ident); auto it = m_NTCP2Sessions.find (ident);
if (it != m_NTCP2Sessions.end ()) if (it != m_NTCP2Sessions.end ())
{ {
LogPrint (eLogWarning, "NTCP2: Session to ", ident.ToBase64 (), " already exists"); LogPrint (eLogWarning, "NTCP2: Session with ", ident.ToBase64 (), " already exists. ", incoming ? "Replaced" : "Dropped");
if (incoming) if (incoming)
{
// replace by new session // replace by new session
it->second->Terminate (); auto s = it->second;
m_NTCP2Sessions.erase (it);
s->Terminate ();
}
else else
{
session->Terminate ();
return false; return false;
}
} }
m_NTCP2Sessions.insert (std::make_pair (ident, session)); m_NTCP2Sessions.emplace (ident, session);
return true; return true;
} }