Browse Source

renew LeaseSet's I2NP message ID and timestamp before sending

pull/48/head
orignal 11 years ago
parent
commit
ac48e3b355
  1. 17
      I2NPProtocol.cpp
  2. 1
      I2NPProtocol.h
  3. 8
      Streaming.cpp

17
I2NPProtocol.cpp

@ -31,17 +31,17 @@ namespace i2p @@ -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 @@ -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 ();

1
I2NPProtocol.h

@ -142,6 +142,7 @@ namespace tunnel @@ -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);

8
Streaming.cpp

@ -369,10 +369,10 @@ namespace stream @@ -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;
}

Loading…
Cancel
Save