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

19
libi2pd/SSUData.cpp

@ -33,7 +33,6 @@ namespace transport @@ -33,7 +33,6 @@ namespace transport
SSUData::SSUData (SSUSession& session):
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_PacketSize (m_MaxPacketSize), m_LastMessageReceivedTime (0)
{
@ -45,13 +44,11 @@ namespace transport @@ -45,13 +44,11 @@ namespace transport
void SSUData::Start ()
{
ScheduleIncompleteMessagesCleanup ();
}
void SSUData::Stop ()
{
m_ResendTimer.cancel ();
m_IncompleteMessagesCleanupTimer.cancel ();
m_IncompleteMessages.clear ();
m_SentMessages.clear ();
m_ReceivedMessages.clear ();
@ -487,18 +484,7 @@ namespace transport @@ -487,18 +484,7 @@ namespace transport
}
}
void SSUData::ScheduleIncompleteMessagesCleanup ()
{
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)
void SSUData::CleanUp ()
{
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();)
@ -526,9 +512,6 @@ namespace transport @@ -526,9 +512,6 @@ namespace transport
++it;
}
}
ScheduleIncompleteMessagesCleanup ();
}
}
}
}

8
libi2pd/SSUData.h

@ -13,7 +13,6 @@ @@ -13,7 +13,6 @@
#include <string.h>
#include <unordered_map>
#include <vector>
#include <unordered_set>
#include <memory>
#include <boost/asio.hpp>
#include "I2NPProtocol.h"
@ -101,6 +100,7 @@ namespace transport @@ -101,6 +100,7 @@ namespace transport
void Start ();
void Stop ();
void CleanUp ();
void ProcessMessage (uint8_t * buf, size_t len);
void FlushReceivedMessage ();
@ -120,17 +120,13 @@ namespace transport @@ -120,17 +120,13 @@ namespace transport
void ScheduleResend ();
void HandleResendTimer (const boost::system::error_code& ecode);
void ScheduleIncompleteMessagesCleanup ();
void HandleIncompleteMessagesCleanupTimer (const boost::system::error_code& ecode);
private:
SSUSession& m_Session;
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, 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;
i2p::I2NPMessagesHandler m_Handler;
uint32_t m_LastMessageReceivedTime; // in second

6
libi2pd/SSUSession.cpp

@ -1004,6 +1004,12 @@ namespace transport @@ -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)
{
uint32_t nonce = bufbe32toh (buf); // 4 bytes

3
libi2pd/SSUSession.h

@ -1,5 +1,5 @@ @@ -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
*
@ -106,6 +106,7 @@ namespace transport @@ -106,6 +106,7 @@ namespace transport
void SetCreationTime (uint32_t ts) { m_CreationTime = ts; }; // for introducers
void FlushData ();
void CleanUp ();
private:

Loading…
Cancel
Save