diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 854f258c..862e9ec7 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -51,6 +51,11 @@ namespace i2p SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000); } + bool I2NPMessage::IsExpired () const + { + return i2p::util::GetMillisecondsSinceEpoch () > GetExpiration (); + } + std::shared_ptr CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID) { auto msg = NewI2NPMessage (len); diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 9c41a06b..83c72463 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -196,6 +196,7 @@ namespace tunnel void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0); void RenewI2NPMessageHeader (); + bool IsExpired () const; }; template diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 24bc21e5..8515d1a9 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -579,8 +579,13 @@ namespace transport // we have a complete I2NP message uint8_t checksum[4]; htobe32buf (checksum, adler32 (adler32 (0, Z_NULL, 0), m_NextMessage->buf, m_NextMessageOffset - 4)); - if (!memcmp (m_NextMessage->buf + m_NextMessageOffset - 4, checksum, 4)) - m_Handler.PutNextMessage (m_NextMessage); + if (!memcmp (m_NextMessage->buf + m_NextMessageOffset - 4, checksum, 4)) + { + if (!m_NextMessage->IsExpired ()) + m_Handler.PutNextMessage (m_NextMessage); + else + LogPrint (eLogInfo, "NTCP: message expired"); + } else LogPrint (eLogWarning, "NTCP: Incorrect adler checksum of message, dropped"); m_NextMessage = nullptr; diff --git a/SSUData.cpp b/SSUData.cpp index cb9d1015..f57b25e2 100644 --- a/SSUData.cpp +++ b/SSUData.cpp @@ -238,7 +238,10 @@ namespace transport else ScheduleDecay (); m_ReceivedMessages.insert (msgID); - m_Handler.PutNextMessage (msg); + if (!msg->IsExpired ()) + m_Handler.PutNextMessage (msg); + else + LogPrint (eLogInfo, "SSU: message expired"); } else LogPrint (eLogWarning, "SSU: Message ", msgID, " already received"); diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 024bb36d..326036a6 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -225,6 +225,11 @@ namespace tunnel void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg) { + if (msg.data->IsExpired ()) + { + LogPrint (eLogInfo, "TunnelMessage: message expired"); + return; + } auto typeID = msg.data->GetTypeID (); LogPrint (eLogDebug, "TunnelMessage: handle fragment of ", msg.data->GetLength (), " bytes, msg type ", (int)typeID); switch (msg.deliveryType)