mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
eliminate decay timer
This commit is contained in:
parent
0d88b8012b
commit
d5075d706c
30
SSUData.cpp
30
SSUData.cpp
@ -25,10 +25,10 @@ namespace transport
|
|||||||
}
|
}
|
||||||
|
|
||||||
SSUData::SSUData (SSUSession& session):
|
SSUData::SSUData (SSUSession& session):
|
||||||
m_Session (session), m_ResendTimer (session.GetService ()), m_DecayTimer (session.GetService ()),
|
m_Session (session), m_ResendTimer (session.GetService ()),
|
||||||
m_IncompleteMessagesCleanupTimer (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_PacketSize (m_MaxPacketSize), m_LastMessageReceivedTime (0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,6 @@ namespace transport
|
|||||||
void SSUData::Stop ()
|
void SSUData::Stop ()
|
||||||
{
|
{
|
||||||
m_ResendTimer.cancel ();
|
m_ResendTimer.cancel ();
|
||||||
m_DecayTimer.cancel ();
|
|
||||||
m_IncompleteMessagesCleanupTimer.cancel ();
|
m_IncompleteMessagesCleanupTimer.cancel ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,11 +232,8 @@ namespace transport
|
|||||||
{
|
{
|
||||||
if (!m_ReceivedMessages.count (msgID))
|
if (!m_ReceivedMessages.count (msgID))
|
||||||
{
|
{
|
||||||
if (m_ReceivedMessages.size () > MAX_NUM_RECEIVED_MESSAGES)
|
|
||||||
m_ReceivedMessages.clear ();
|
|
||||||
else
|
|
||||||
ScheduleDecay ();
|
|
||||||
m_ReceivedMessages.insert (msgID);
|
m_ReceivedMessages.insert (msgID);
|
||||||
|
m_LastMessageReceivedTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
if (!msg->IsExpired ())
|
if (!msg->IsExpired ())
|
||||||
m_Handler.PutNextMessage (msg);
|
m_Handler.PutNextMessage (msg);
|
||||||
else
|
else
|
||||||
@ -469,21 +465,6 @@ namespace transport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSUData::ScheduleDecay ()
|
|
||||||
{
|
|
||||||
m_DecayTimer.cancel ();
|
|
||||||
m_DecayTimer.expires_from_now (boost::posix_time::seconds(DECAY_INTERVAL));
|
|
||||||
auto s = m_Session.shared_from_this();
|
|
||||||
m_ResendTimer.async_wait ([s](const boost::system::error_code& ecode)
|
|
||||||
{ s->m_Data.HandleDecayTimer (ecode); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void SSUData::HandleDecayTimer (const boost::system::error_code& ecode)
|
|
||||||
{
|
|
||||||
if (ecode != boost::asio::error::operation_aborted)
|
|
||||||
m_ReceivedMessages.clear ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SSUData::ScheduleIncompleteMessagesCleanup ()
|
void SSUData::ScheduleIncompleteMessagesCleanup ()
|
||||||
{
|
{
|
||||||
m_IncompleteMessagesCleanupTimer.cancel ();
|
m_IncompleteMessagesCleanupTimer.cancel ();
|
||||||
@ -508,6 +489,11 @@ namespace transport
|
|||||||
else
|
else
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
// decay
|
||||||
|
if (m_ReceivedMessages.size () > MAX_NUM_RECEIVED_MESSAGES ||
|
||||||
|
i2p::util::GetSecondsSinceEpoch () > m_LastMessageReceivedTime + DECAY_INTERVAL)
|
||||||
|
m_ReceivedMessages.clear ();
|
||||||
|
|
||||||
ScheduleIncompleteMessagesCleanup ();
|
ScheduleIncompleteMessagesCleanup ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
SSUData.h
10
SSUData.h
@ -5,7 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <unordered_set>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
@ -109,9 +109,6 @@ namespace transport
|
|||||||
void ScheduleResend ();
|
void ScheduleResend ();
|
||||||
void HandleResendTimer (const boost::system::error_code& ecode);
|
void HandleResendTimer (const boost::system::error_code& ecode);
|
||||||
|
|
||||||
void ScheduleDecay ();
|
|
||||||
void HandleDecayTimer (const boost::system::error_code& ecode);
|
|
||||||
|
|
||||||
void ScheduleIncompleteMessagesCleanup ();
|
void ScheduleIncompleteMessagesCleanup ();
|
||||||
void HandleIncompleteMessagesCleanupTimer (const boost::system::error_code& ecode);
|
void HandleIncompleteMessagesCleanupTimer (const boost::system::error_code& ecode);
|
||||||
|
|
||||||
@ -121,10 +118,11 @@ namespace transport
|
|||||||
SSUSession& m_Session;
|
SSUSession& m_Session;
|
||||||
std::map<uint32_t, std::unique_ptr<IncompleteMessage> > m_IncompleteMessages;
|
std::map<uint32_t, std::unique_ptr<IncompleteMessage> > m_IncompleteMessages;
|
||||||
std::map<uint32_t, std::unique_ptr<SentMessage> > m_SentMessages;
|
std::map<uint32_t, std::unique_ptr<SentMessage> > m_SentMessages;
|
||||||
std::set<uint32_t> m_ReceivedMessages;
|
std::unordered_set<uint32_t> m_ReceivedMessages;
|
||||||
boost::asio::deadline_timer m_ResendTimer, m_DecayTimer, m_IncompleteMessagesCleanupTimer;
|
boost::asio::deadline_timer m_ResendTimer, m_IncompleteMessagesCleanupTimer;
|
||||||
int m_MaxPacketSize, m_PacketSize;
|
int m_MaxPacketSize, m_PacketSize;
|
||||||
i2p::I2NPMessagesHandler m_Handler;
|
i2p::I2NPMessagesHandler m_Handler;
|
||||||
|
uint32_t m_LastMessageReceivedTime; // in second
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user