From 51cbffd097f6d3c55e40c4faabd89cbe108339db Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 7 Apr 2022 10:57:57 -0400 Subject: [PATCH] don't lookup session for every sinle packet --- libi2pd/SSU2.cpp | 19 ++++++++++++++----- libi2pd/SSU2.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libi2pd/SSU2.cpp b/libi2pd/SSU2.cpp index a27cf063..433a3afb 100644 --- a/libi2pd/SSU2.cpp +++ b/libi2pd/SSU2.cpp @@ -1282,13 +1282,20 @@ namespace transport uint64_t connID; memcpy (&connID, buf, 8); connID ^= CreateHeaderMask (i2p::context.GetSSU2IntroKey (), buf + (len - 24)); - auto it = m_Sessions.find (connID); - if (it != m_Sessions.end ()) + if (!m_LastSession || m_LastSession->GetConnID () != connID) { - if (it->second->IsEstablished ()) - it->second->ProcessData (buf, len); + auto it = m_Sessions.find (connID); + if (it != m_Sessions.end ()) + m_LastSession = it->second; + else + m_LastSession = nullptr; + } + if (m_LastSession) + { + if (m_LastSession->IsEstablished ()) + m_LastSession->ProcessData (buf, len); else - it->second->ProcessSessionConfirmed (buf, len); + m_LastSession->ProcessSessionConfirmed (buf, len); } else { @@ -1388,6 +1395,8 @@ namespace transport { if (it->second->IsEstablished ()) it->second->TerminateByTimeout (); + if (it->second == m_LastSession) + m_LastSession = nullptr; it = m_Sessions.erase (it); } else diff --git a/libi2pd/SSU2.h b/libi2pd/SSU2.h index 43bc35f3..f9d0f848 100644 --- a/libi2pd/SSU2.h +++ b/libi2pd/SSU2.h @@ -269,6 +269,7 @@ namespace transport std::map > m_IncomingTokens, m_OutgoingTokens; // remote endpoint -> (token, expires in seconds) i2p::util::MemoryPoolMt m_PacketsPool; boost::asio::deadline_timer m_TerminationTimer, m_ResendTimer; + std::shared_ptr m_LastSession; public: