diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 862e9ec7..8f528f3c 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -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 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 CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID) diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 83c72463..898396d0 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -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; diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 326036a6..e63ea948 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -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;