Browse Source

don't send expired I2NP messages

pull/2010/head
orignal 11 months ago
parent
commit
9f217f8a11
  1. 10
      libi2pd/I2NPProtocol.cpp
  2. 3
      libi2pd/I2NPProtocol.h
  3. 7
      libi2pd/NTCP2.cpp
  4. 3
      libi2pd/SSU2Session.cpp

10
libi2pd/I2NPProtocol.cpp

@ -1,5 +1,5 @@ @@ -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
*
@ -72,11 +72,15 @@ namespace i2p @@ -72,11 +72,15 @@ namespace i2p
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 ();
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)

3
libi2pd/I2NPProtocol.h

@ -1,5 +1,5 @@ @@ -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
*
@ -252,6 +252,7 @@ namespace tunnel @@ -252,6 +252,7 @@ namespace tunnel
void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0, bool checksum = true);
void RenewI2NPMessageHeader ();
bool IsExpired () const;
bool IsExpired (uint64_t ts) const; // in milliseconds
};
template<int sz>

7
libi2pd/NTCP2.cpp

@ -1132,10 +1132,17 @@ namespace transport @@ -1132,10 +1132,17 @@ namespace transport
if (!m_SendQueue.empty ())
{
std::vector<std::shared_ptr<I2NPMessage> > msgs;
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
size_t s = 0;
while (!m_SendQueue.empty ())
{
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 ();
if (s + len + 3 <= NTCP2_UNENCRYPTED_FRAME_MAX_SIZE) // 3 bytes block header
{

3
libi2pd/SSU2Session.cpp

@ -379,8 +379,9 @@ namespace transport @@ -379,8 +379,9 @@ namespace transport
while (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize)
{
auto msg = m_SendQueue.front ();
if (!msg)
if (!msg || msg->IsExpired (ts))
{
// drop null or expired message
m_SendQueue.pop_front ();
continue;
}

Loading…
Cancel
Save