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. 7
      NTCPSession.cpp
  4. 5
      SSUData.cpp
  5. 5
      TunnelEndpoint.cpp

5
I2NPProtocol.cpp

@ -51,6 +51,11 @@ namespace i2p @@ -51,6 +51,11 @@ namespace i2p
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)
{
auto msg = NewI2NPMessage (len);

1
I2NPProtocol.h

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

7
NTCPSession.cpp

@ -580,7 +580,12 @@ namespace transport @@ -580,7 +580,12 @@ namespace transport
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 (!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;

5
SSUData.cpp

@ -238,7 +238,10 @@ namespace transport @@ -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");

5
TunnelEndpoint.cpp

@ -225,6 +225,11 @@ namespace tunnel @@ -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)

Loading…
Cancel
Save