Browse Source

use common cleanup timer for all SSU sessions

pull/1696/head
orignal 3 years ago
parent
commit
8debdc264c
  1. 4
      libi2pd/SSU.cpp
  2. 19
      libi2pd/SSUData.cpp
  3. 8
      libi2pd/SSUData.h
  4. 6
      libi2pd/SSUSession.cpp
  5. 3
      libi2pd/SSUSession.h

4
libi2pd/SSU.cpp

@ -952,6 +952,8 @@ namespace transport
session->Failed (); session->Failed ();
}); });
} }
else
it.second->CleanUp ();
ScheduleTermination (); ScheduleTermination ();
} }
} }
@ -980,6 +982,8 @@ namespace transport
session->Failed (); session->Failed ();
}); });
} }
else
it.second->CleanUp ();
ScheduleTerminationV6 (); ScheduleTerminationV6 ();
} }
} }

19
libi2pd/SSUData.cpp

@ -33,7 +33,6 @@ namespace transport
SSUData::SSUData (SSUSession& session): SSUData::SSUData (SSUSession& session):
m_Session (session), m_ResendTimer (session.GetService ()), m_Session (session), m_ResendTimer (session.GetService ()),
m_IncompleteMessagesCleanupTimer (session.GetService ()),
m_MaxPacketSize (session.IsV6 () ? SSU_V6_MAX_PACKET_SIZE : SSU_V4_MAX_PACKET_SIZE), m_MaxPacketSize (session.IsV6 () ? SSU_V6_MAX_PACKET_SIZE : SSU_V4_MAX_PACKET_SIZE),
m_PacketSize (m_MaxPacketSize), m_LastMessageReceivedTime (0) m_PacketSize (m_MaxPacketSize), m_LastMessageReceivedTime (0)
{ {
@ -45,13 +44,11 @@ namespace transport
void SSUData::Start () void SSUData::Start ()
{ {
ScheduleIncompleteMessagesCleanup ();
} }
void SSUData::Stop () void SSUData::Stop ()
{ {
m_ResendTimer.cancel (); m_ResendTimer.cancel ();
m_IncompleteMessagesCleanupTimer.cancel ();
m_IncompleteMessages.clear (); m_IncompleteMessages.clear ();
m_SentMessages.clear (); m_SentMessages.clear ();
m_ReceivedMessages.clear (); m_ReceivedMessages.clear ();
@ -487,18 +484,7 @@ namespace transport
} }
} }
void SSUData::ScheduleIncompleteMessagesCleanup () void SSUData::CleanUp ()
{
m_IncompleteMessagesCleanupTimer.cancel ();
m_IncompleteMessagesCleanupTimer.expires_from_now (boost::posix_time::seconds(INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT));
auto s = m_Session.shared_from_this();
m_IncompleteMessagesCleanupTimer.async_wait ([s](const boost::system::error_code& ecode)
{ s->m_Data.HandleIncompleteMessagesCleanupTimer (ecode); });
}
void SSUData::HandleIncompleteMessagesCleanupTimer (const boost::system::error_code& ecode)
{
if (ecode != boost::asio::error::operation_aborted)
{ {
uint32_t ts = i2p::util::GetSecondsSinceEpoch (); uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();) for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();)
@ -526,9 +512,6 @@ namespace transport
++it; ++it;
} }
} }
ScheduleIncompleteMessagesCleanup ();
}
} }
} }
} }

8
libi2pd/SSUData.h

@ -13,7 +13,6 @@
#include <string.h> #include <string.h>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <unordered_set>
#include <memory> #include <memory>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
@ -101,6 +100,7 @@ namespace transport
void Start (); void Start ();
void Stop (); void Stop ();
void CleanUp ();
void ProcessMessage (uint8_t * buf, size_t len); void ProcessMessage (uint8_t * buf, size_t len);
void FlushReceivedMessage (); void FlushReceivedMessage ();
@ -120,17 +120,13 @@ namespace transport
void ScheduleResend (); void ScheduleResend ();
void HandleResendTimer (const boost::system::error_code& ecode); void HandleResendTimer (const boost::system::error_code& ecode);
void ScheduleIncompleteMessagesCleanup ();
void HandleIncompleteMessagesCleanupTimer (const boost::system::error_code& ecode);
private: private:
SSUSession& m_Session; SSUSession& m_Session;
std::unordered_map<uint32_t, std::shared_ptr<IncompleteMessage> > m_IncompleteMessages; std::unordered_map<uint32_t, std::shared_ptr<IncompleteMessage> > m_IncompleteMessages;
std::unordered_map<uint32_t, std::shared_ptr<SentMessage> > m_SentMessages; std::unordered_map<uint32_t, std::shared_ptr<SentMessage> > m_SentMessages;
std::unordered_map<uint32_t, uint64_t> m_ReceivedMessages; // msgID -> timestamp in seconds std::unordered_map<uint32_t, uint64_t> m_ReceivedMessages; // msgID -> timestamp in seconds
boost::asio::deadline_timer m_ResendTimer, m_IncompleteMessagesCleanupTimer; boost::asio::deadline_timer m_ResendTimer;
int m_MaxPacketSize, m_PacketSize; int m_MaxPacketSize, m_PacketSize;
i2p::I2NPMessagesHandler m_Handler; i2p::I2NPMessagesHandler m_Handler;
uint32_t m_LastMessageReceivedTime; // in second uint32_t m_LastMessageReceivedTime; // in second

6
libi2pd/SSUSession.cpp

@ -1004,6 +1004,12 @@ namespace transport
} }
} }
void SSUSession::CleanUp ()
{
m_Data.CleanUp ();
// TODO: clean up m_RelayRequests
}
void SSUSession::ProcessPeerTest (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint) void SSUSession::ProcessPeerTest (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
{ {
uint32_t nonce = bufbe32toh (buf); // 4 bytes uint32_t nonce = bufbe32toh (buf); // 4 bytes

3
libi2pd/SSUSession.h

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2020, The PurpleI2P Project * Copyright (c) 2013-2021, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -106,6 +106,7 @@ namespace transport
void SetCreationTime (uint32_t ts) { m_CreationTime = ts; }; // for introducers void SetCreationTime (uint32_t ts) { m_CreationTime = ts; }; // for introducers
void FlushData (); void FlushData ();
void CleanUp ();
private: private:

Loading…
Cancel
Save