From 6b100353ba444774a87546e4e43dbe8a182d9273 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 8 Aug 2026 14:38:11 -0400 Subject: [PATCH] generate msgid from instead RAND_bytes --- libi2pd/Datagram.cpp | 2 +- libi2pd/ECIESX25519AEADRatchetSession.cpp | 2 +- libi2pd/I2NPProtocol.cpp | 14 +++----------- libi2pd/I2NPProtocol.h | 3 +-- libi2pd/Streaming.cpp | 2 +- libi2pd_client/I2CP.cpp | 4 ++-- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/libi2pd/Datagram.cpp b/libi2pd/Datagram.cpp index e5560849..174fd993 100644 --- a/libi2pd/Datagram.cpp +++ b/libi2pd/Datagram.cpp @@ -474,7 +474,7 @@ namespace datagram htobe16buf (buf + 6, toPort); // destination port buf[9] = protocolType; // raw or datagram protocol msg->len += size + 4; - msg->FillI2NPMessageHeader (eI2NPData, 0, checksum); + msg->FillI2NPMessageHeader (eI2NPData, m_Owner->GetRng ()(), checksum); } else msg = nullptr; diff --git a/libi2pd/ECIESX25519AEADRatchetSession.cpp b/libi2pd/ECIESX25519AEADRatchetSession.cpp index 65eb57f6..2c6eb0ba 100644 --- a/libi2pd/ECIESX25519AEADRatchetSession.cpp +++ b/libi2pd/ECIESX25519AEADRatchetSession.cpp @@ -1123,7 +1123,7 @@ namespace garlic htobe32buf (m->GetPayload (), len); m->len += len + 4; - m->FillI2NPMessageHeader (eI2NPGarlic); + m->FillI2NPMessageHeader (eI2NPGarlic, GetOwner ()->GetRng ()()); return m; } diff --git a/libi2pd/I2NPProtocol.cpp b/libi2pd/I2NPProtocol.cpp index 1bfbc03a..3195ba76 100644 --- a/libi2pd/I2NPProtocol.cpp +++ b/libi2pd/I2NPProtocol.cpp @@ -49,24 +49,16 @@ namespace i2p return NewI2NPMessage (); } - void I2NPMessage::FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID, bool checksum) + void I2NPMessage::FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t msgID, bool checksum) { SetTypeID (msgType); - if (!replyMsgID) RAND_bytes ((uint8_t *)&replyMsgID, 4); - SetMsgID (replyMsgID); + if (!msgID) RAND_bytes ((uint8_t *)&msgID, 4); + SetMsgID (msgID); SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + I2NP_MESSAGE_EXPIRATION_TIMEOUT); UpdateSize (); if (checksum) UpdateChks (); } - void I2NPMessage::RenewI2NPMessageHeader () - { - uint32_t msgID; - RAND_bytes ((uint8_t *)&msgID, 4); - SetMsgID (msgID); - SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + I2NP_MESSAGE_EXPIRATION_TIMEOUT); - } - bool I2NPMessage::IsExpired (uint64_t ts) const { auto exp = GetExpiration (); diff --git a/libi2pd/I2NPProtocol.h b/libi2pd/I2NPProtocol.h index 1fd34152..98943f81 100644 --- a/libi2pd/I2NPProtocol.h +++ b/libi2pd/I2NPProtocol.h @@ -246,8 +246,7 @@ namespace tunnel memcpy (ntcp2 + I2NP_HEADER_TYPEID_OFFSET, GetHeader () + I2NP_HEADER_TYPEID_OFFSET, 5); // typeid + msgid } - void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0, bool checksum = true); - void RenewI2NPMessageHeader (); + void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t msgID = 0, bool checksum = true); bool IsExpired () const; bool IsExpired (uint64_t ts) const; // in milliseconds diff --git a/libi2pd/Streaming.cpp b/libi2pd/Streaming.cpp index 73e04c60..b7084596 100644 --- a/libi2pd/Streaming.cpp +++ b/libi2pd/Streaming.cpp @@ -2513,7 +2513,7 @@ namespace stream htobe16buf (buf + 6, toPort); // destination port buf[9] = i2p::client::PROTOCOL_TYPE_STREAMING; // streaming protocol msg->len += size; - msg->FillI2NPMessageHeader (eI2NPData, 0, checksum); + msg->FillI2NPMessageHeader (eI2NPData, m_Owner->GetRng ()(), checksum); } else msg = nullptr; diff --git a/libi2pd_client/I2CP.cpp b/libi2pd_client/I2CP.cpp index 6600f30e..8b1c2b7b 100644 --- a/libi2pd_client/I2CP.cpp +++ b/libi2pd_client/I2CP.cpp @@ -252,7 +252,7 @@ namespace client htobe32buf (buf, len); memcpy (buf + 4, payload, len); msg->len += len + 4; - msg->FillI2NPMessageHeader (eI2NPData); + msg->FillI2NPMessageHeader (eI2NPData, GetRng ()()); auto remote = FindLeaseSet (ident); if (remote) { @@ -393,7 +393,7 @@ namespace client htobe32buf (buf, len); memcpy (buf + 4, payload, len); msg->len += len + 4; - msg->FillI2NPMessageHeader (eI2NPData); + msg->FillI2NPMessageHeader (eI2NPData, GetRng ()()); // wrap in gralic auto garlic = remoteSession->WrapSingleMessage (msg); // send