mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-18 16:49:58 +00:00
don't send expired I2NP messages
This commit is contained in:
parent
5e19e361e7
commit
9f217f8a11
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, 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
|
||||||
*
|
*
|
||||||
@ -72,13 +72,17 @@ namespace i2p
|
|||||||
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + I2NP_MESSAGE_EXPIRATION_TIMEOUT);
|
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + I2NP_MESSAGE_EXPIRATION_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2NPMessage::IsExpired () const
|
bool I2NPMessage::IsExpired (uint64_t ts) const
|
||||||
{
|
{
|
||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
|
||||||
auto exp = GetExpiration ();
|
auto exp = GetExpiration ();
|
||||||
return (ts > exp + I2NP_MESSAGE_CLOCK_SKEW) || (ts < exp - 3*I2NP_MESSAGE_CLOCK_SKEW); // check if expired or too far in future
|
return (ts > exp + I2NP_MESSAGE_CLOCK_SKEW) || (ts < exp - 3*I2NP_MESSAGE_CLOCK_SKEW); // check if expired or too far in future
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool I2NPMessage::IsExpired () const
|
||||||
|
{
|
||||||
|
return IsExpired (i2p::util::GetMillisecondsSinceEpoch ());
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID)
|
std::shared_ptr<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID)
|
||||||
{
|
{
|
||||||
auto msg = NewI2NPMessage (len);
|
auto msg = NewI2NPMessage (len);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, 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
|
||||||
*
|
*
|
||||||
@ -252,6 +252,7 @@ namespace tunnel
|
|||||||
void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0, bool checksum = true);
|
void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0, bool checksum = true);
|
||||||
void RenewI2NPMessageHeader ();
|
void RenewI2NPMessageHeader ();
|
||||||
bool IsExpired () const;
|
bool IsExpired () const;
|
||||||
|
bool IsExpired (uint64_t ts) const; // in milliseconds
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int sz>
|
template<int sz>
|
||||||
|
@ -1132,10 +1132,17 @@ namespace transport
|
|||||||
if (!m_SendQueue.empty ())
|
if (!m_SendQueue.empty ())
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<I2NPMessage> > msgs;
|
std::vector<std::shared_ptr<I2NPMessage> > msgs;
|
||||||
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
size_t s = 0;
|
size_t s = 0;
|
||||||
while (!m_SendQueue.empty ())
|
while (!m_SendQueue.empty ())
|
||||||
{
|
{
|
||||||
auto msg = m_SendQueue.front ();
|
auto msg = m_SendQueue.front ();
|
||||||
|
if (!msg || msg->IsExpired (ts))
|
||||||
|
{
|
||||||
|
// drop null or expired message
|
||||||
|
m_SendQueue.pop_front ();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
size_t len = msg->GetNTCP2Length ();
|
size_t len = msg->GetNTCP2Length ();
|
||||||
if (s + len + 3 <= NTCP2_UNENCRYPTED_FRAME_MAX_SIZE) // 3 bytes block header
|
if (s + len + 3 <= NTCP2_UNENCRYPTED_FRAME_MAX_SIZE) // 3 bytes block header
|
||||||
{
|
{
|
||||||
|
@ -379,8 +379,9 @@ namespace transport
|
|||||||
while (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize)
|
while (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize)
|
||||||
{
|
{
|
||||||
auto msg = m_SendQueue.front ();
|
auto msg = m_SendQueue.front ();
|
||||||
if (!msg)
|
if (!msg || msg->IsExpired (ts))
|
||||||
{
|
{
|
||||||
|
// drop null or expired message
|
||||||
m_SendQueue.pop_front ();
|
m_SendQueue.pop_front ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user