mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-25 23:44:18 +00:00
check I2NP messages fro expiration
This commit is contained in:
parent
eb2d68fc28
commit
9611f80a39
@ -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);
|
||||||
|
@ -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>
|
||||||
|
@ -579,8 +579,13 @@ namespace transport
|
|||||||
// we have a complete I2NP message
|
// we have a complete I2NP message
|
||||||
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))
|
||||||
m_Handler.PutNextMessage (m_NextMessage);
|
{
|
||||||
|
if (!m_NextMessage->IsExpired ())
|
||||||
|
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;
|
||||||
|
@ -238,7 +238,10 @@ namespace transport
|
|||||||
else
|
else
|
||||||
ScheduleDecay ();
|
ScheduleDecay ();
|
||||||
m_ReceivedMessages.insert (msgID);
|
m_ReceivedMessages.insert (msgID);
|
||||||
m_Handler.PutNextMessage (msg);
|
if (!msg->IsExpired ())
|
||||||
|
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");
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user