Browse Source

add clock skew to expiration

pull/326/head
orignal 9 years ago
parent
commit
5482a57c45
  1. 8
      I2NPProtocol.cpp
  2. 3
      I2NPProtocol.h
  3. 2
      TunnelEndpoint.cpp

8
I2NPProtocol.cpp

@ -38,7 +38,7 @@ namespace i2p @@ -38,7 +38,7 @@ namespace i2p
SetTypeID (msgType);
if (!replyMsgID) RAND_bytes ((uint8_t *)&replyMsgID, 4);
SetMsgID (replyMsgID);
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000); // 8 secs means initial RTT
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + I2NP_MESSAGE_EXPIRATION_TIMEOUT);
UpdateSize ();
UpdateChks ();
}
@ -48,12 +48,14 @@ namespace i2p @@ -48,12 +48,14 @@ namespace i2p
uint32_t msgID;
RAND_bytes ((uint8_t *)&msgID, 4);
SetMsgID (msgID);
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000);
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + I2NP_MESSAGE_EXPIRATION_TIMEOUT);
}
bool I2NPMessage::IsExpired () const
{
return i2p::util::GetMillisecondsSinceEpoch () > GetExpiration ();
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
}
std::shared_ptr<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID)

3
I2NPProtocol.h

@ -107,6 +107,9 @@ namespace tunnel @@ -107,6 +107,9 @@ namespace tunnel
const size_t I2NP_MAX_MESSAGE_SIZE = 32768;
const size_t I2NP_MAX_SHORT_MESSAGE_SIZE = 4096;
const unsigned int I2NP_MESSAGE_EXPIRATION_TIMEOUT = 8000; // in milliseconds (as initial RTT)
const unsigned int I2NP_MESSAGE_CLOCK_SKEW = 60*1000; // 1 minute in milliseconds
struct I2NPMessage
{
uint8_t * buf;

2
TunnelEndpoint.cpp

@ -225,7 +225,7 @@ namespace tunnel @@ -225,7 +225,7 @@ namespace tunnel
void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg)
{
if (msg.data->IsExpired ())
if (!m_IsInbound && msg.data->IsExpired ())
{
LogPrint (eLogInfo, "TunnelMessage: message expired");
return;

Loading…
Cancel
Save