Browse Source

don't lookup session for every sinle packet

pull/1752/head
orignal 3 years ago
parent
commit
51cbffd097
  1. 15
      libi2pd/SSU2.cpp
  2. 1
      libi2pd/SSU2.h

15
libi2pd/SSU2.cpp

@ -1282,13 +1282,20 @@ namespace transport
uint64_t connID; uint64_t connID;
memcpy (&connID, buf, 8); memcpy (&connID, buf, 8);
connID ^= CreateHeaderMask (i2p::context.GetSSU2IntroKey (), buf + (len - 24)); connID ^= CreateHeaderMask (i2p::context.GetSSU2IntroKey (), buf + (len - 24));
if (!m_LastSession || m_LastSession->GetConnID () != connID)
{
auto it = m_Sessions.find (connID); auto it = m_Sessions.find (connID);
if (it != m_Sessions.end ()) if (it != m_Sessions.end ())
m_LastSession = it->second;
else
m_LastSession = nullptr;
}
if (m_LastSession)
{ {
if (it->second->IsEstablished ()) if (m_LastSession->IsEstablished ())
it->second->ProcessData (buf, len); m_LastSession->ProcessData (buf, len);
else else
it->second->ProcessSessionConfirmed (buf, len); m_LastSession->ProcessSessionConfirmed (buf, len);
} }
else else
{ {
@ -1388,6 +1395,8 @@ namespace transport
{ {
if (it->second->IsEstablished ()) if (it->second->IsEstablished ())
it->second->TerminateByTimeout (); it->second->TerminateByTimeout ();
if (it->second == m_LastSession)
m_LastSession = nullptr;
it = m_Sessions.erase (it); it = m_Sessions.erase (it);
} }
else else

1
libi2pd/SSU2.h

@ -269,6 +269,7 @@ namespace transport
std::map<boost::asio::ip::udp::endpoint, std::pair<uint64_t, uint32_t> > m_IncomingTokens, m_OutgoingTokens; // remote endpoint -> (token, expires in seconds) std::map<boost::asio::ip::udp::endpoint, std::pair<uint64_t, uint32_t> > m_IncomingTokens, m_OutgoingTokens; // remote endpoint -> (token, expires in seconds)
i2p::util::MemoryPoolMt<Packet> m_PacketsPool; i2p::util::MemoryPoolMt<Packet> m_PacketsPool;
boost::asio::deadline_timer m_TerminationTimer, m_ResendTimer; boost::asio::deadline_timer m_TerminationTimer, m_ResendTimer;
std::shared_ptr<SSU2Session> m_LastSession;
public: public:

Loading…
Cancel
Save