Browse Source

check I2NP messages fro expiration

pull/326/head
orignal 9 years ago
parent
commit
9611f80a39
  1. 5
      I2NPProtocol.cpp
  2. 1
      I2NPProtocol.h
  3. 5
      NTCPSession.cpp
  4. 3
      SSUData.cpp
  5. 5
      TunnelEndpoint.cpp

5
I2NPProtocol.cpp

@ -51,6 +51,11 @@ namespace i2p
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000); SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000);
} }
bool I2NPMessage::IsExpired () const
{
return i2p::util::GetMillisecondsSinceEpoch () > GetExpiration ();
}
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
I2NPProtocol.h

@ -196,6 +196,7 @@ namespace tunnel
void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0); void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0);
void RenewI2NPMessageHeader (); void RenewI2NPMessageHeader ();
bool IsExpired () const;
}; };
template<int sz> template<int sz>

5
NTCPSession.cpp

@ -580,7 +580,12 @@ namespace transport
uint8_t checksum[4]; uint8_t checksum[4];
htobe32buf (checksum, adler32 (adler32 (0, Z_NULL, 0), m_NextMessage->buf, m_NextMessageOffset - 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)) if (!memcmp (m_NextMessage->buf + m_NextMessageOffset - 4, checksum, 4))
{
if (!m_NextMessage->IsExpired ())
m_Handler.PutNextMessage (m_NextMessage); m_Handler.PutNextMessage (m_NextMessage);
else
LogPrint (eLogInfo, "NTCP: message expired");
}
else else
LogPrint (eLogWarning, "NTCP: Incorrect adler checksum of message, dropped"); LogPrint (eLogWarning, "NTCP: Incorrect adler checksum of message, dropped");
m_NextMessage = nullptr; m_NextMessage = nullptr;

3
SSUData.cpp

@ -238,7 +238,10 @@ namespace transport
else else
ScheduleDecay (); ScheduleDecay ();
m_ReceivedMessages.insert (msgID); m_ReceivedMessages.insert (msgID);
if (!msg->IsExpired ())
m_Handler.PutNextMessage (msg); m_Handler.PutNextMessage (msg);
else
LogPrint (eLogInfo, "SSU: message expired");
} }
else else
LogPrint (eLogWarning, "SSU: Message ", msgID, " already received"); LogPrint (eLogWarning, "SSU: Message ", msgID, " already received");

5
TunnelEndpoint.cpp

@ -225,6 +225,11 @@ namespace tunnel
void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg) void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg)
{ {
if (msg.data->IsExpired ())
{
LogPrint (eLogInfo, "TunnelMessage: message expired");
return;
}
auto typeID = msg.data->GetTypeID (); auto typeID = msg.data->GetTypeID ();
LogPrint (eLogDebug, "TunnelMessage: handle fragment of ", msg.data->GetLength (), " bytes, msg type ", (int)typeID); LogPrint (eLogDebug, "TunnelMessage: handle fragment of ", msg.data->GetLength (), " bytes, msg type ", (int)typeID);
switch (msg.deliveryType) switch (msg.deliveryType)

Loading…
Cancel
Save