mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 17:37:53 +00:00
add clock skew to expiration
This commit is contained in:
parent
18914978d5
commit
5482a57c45
@ -38,7 +38,7 @@ namespace i2p
|
|||||||
SetTypeID (msgType);
|
SetTypeID (msgType);
|
||||||
if (!replyMsgID) RAND_bytes ((uint8_t *)&replyMsgID, 4);
|
if (!replyMsgID) RAND_bytes ((uint8_t *)&replyMsgID, 4);
|
||||||
SetMsgID (replyMsgID);
|
SetMsgID (replyMsgID);
|
||||||
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000); // 8 secs means initial RTT
|
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + I2NP_MESSAGE_EXPIRATION_TIMEOUT);
|
||||||
UpdateSize ();
|
UpdateSize ();
|
||||||
UpdateChks ();
|
UpdateChks ();
|
||||||
}
|
}
|
||||||
@ -48,12 +48,14 @@ namespace i2p
|
|||||||
uint32_t msgID;
|
uint32_t msgID;
|
||||||
RAND_bytes ((uint8_t *)&msgID, 4);
|
RAND_bytes ((uint8_t *)&msgID, 4);
|
||||||
SetMsgID (msgID);
|
SetMsgID (msgID);
|
||||||
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 8000);
|
SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + I2NP_MESSAGE_EXPIRATION_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2NPMessage::IsExpired () const
|
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)
|
std::shared_ptr<I2NPMessage> CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID)
|
||||||
|
@ -107,6 +107,9 @@ namespace tunnel
|
|||||||
|
|
||||||
const size_t I2NP_MAX_MESSAGE_SIZE = 32768;
|
const size_t I2NP_MAX_MESSAGE_SIZE = 32768;
|
||||||
const size_t I2NP_MAX_SHORT_MESSAGE_SIZE = 4096;
|
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
|
struct I2NPMessage
|
||||||
{
|
{
|
||||||
uint8_t * buf;
|
uint8_t * buf;
|
||||||
|
@ -225,7 +225,7 @@ namespace tunnel
|
|||||||
|
|
||||||
void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg)
|
void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg)
|
||||||
{
|
{
|
||||||
if (msg.data->IsExpired ())
|
if (!m_IsInbound && msg.data->IsExpired ())
|
||||||
{
|
{
|
||||||
LogPrint (eLogInfo, "TunnelMessage: message expired");
|
LogPrint (eLogInfo, "TunnelMessage: message expired");
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user