From ac48e3b35502cfa8986387e1d5edbcc95d841672 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 20 Mar 2014 12:48:03 -0400 Subject: [PATCH] renew LeaseSet's I2NP message ID and timestamp before sending --- I2NPProtocol.cpp | 17 ++++++++++++++--- I2NPProtocol.h | 1 + Streaming.cpp | 8 ++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 5b2c66f1..0b34f9db 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -31,17 +31,17 @@ namespace i2p delete msg; } + static uint32_t I2NPmsgID = 0; // TODO: create class void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID) { - static uint32_t msgID = 0; I2NPHeader * header = msg->GetHeader (); header->typeID = msgType; if (replyMsgID) // for tunnel creation header->msgID = htobe32 (replyMsgID); else { - header->msgID = htobe32 (msgID); - msgID++; + header->msgID = htobe32 (I2NPmsgID); + I2NPmsgID++; } header->expiration = htobe64 (i2p::util::GetMillisecondsSinceEpoch () + 5000); // TODO: 5 secs is a magic number int len = msg->GetLength () - sizeof (I2NPHeader); @@ -51,6 +51,17 @@ namespace i2p header->chks = hash[0]; } + void RenewI2NPMessageHeader (I2NPMessage * msg) + { + if (msg) + { + I2NPHeader * header = msg->GetHeader (); + header->msgID = htobe32 (I2NPmsgID); + I2NPmsgID++; + header->expiration = htobe64 (i2p::util::GetMillisecondsSinceEpoch () + 5000); + } + } + I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID) { I2NPMessage * msg = NewI2NPMessage (); diff --git a/I2NPProtocol.h b/I2NPProtocol.h index fe836630..5e7900aa 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -142,6 +142,7 @@ namespace tunnel I2NPMessage * NewI2NPMessage (); void DeleteI2NPMessage (I2NPMessage * msg); void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID = 0); + void RenewI2NPMessageHeader (I2NPMessage * msg); I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID = 0); I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len); diff --git a/Streaming.cpp b/Streaming.cpp index c505711a..eb942bd5 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -369,10 +369,10 @@ namespace stream const I2NPMessage * StreamingDestination::GetLeaseSet () { - // TODO: LeaseSet is always re-created. ivestigate - if (m_LeaseSet) - DeleteI2NPMessage (m_LeaseSet); - m_LeaseSet = CreateLeaseSet (); + if (!m_LeaseSet) + m_LeaseSet = CreateLeaseSet (); + else + RenewI2NPMessageHeader (m_LeaseSet); return m_LeaseSet; }