short I2NP message

This commit is contained in:
orignal 2014-07-30 16:52:35 -04:00
parent 5e8dd82b6b
commit 816c415f22
2 changed files with 19 additions and 6 deletions

View File

@ -18,13 +18,14 @@ namespace i2p
I2NPMessage * NewI2NPMessage ()
{
I2NPMessage * msg = new I2NPMessage;
msg->offset = 2; // reserve 2 bytes for NTCP header, should reserve more for SSU in future
msg->len = sizeof (I2NPHeader) + 2;
msg->from = nullptr;
return msg;
return new I2NPMessageBuffer<I2NP_MAX_MESSAGE_SIZE>();
}
I2NPMessage * NewI2NPShortMessage ()
{
return new I2NPMessageBuffer<I2NP_MAX_SHORT_MESSAGE_SIZE>();
}
void DeleteI2NPMessage (I2NPMessage * msg)
{
delete msg;

View File

@ -102,12 +102,15 @@ namespace tunnel
}
const size_t I2NP_MAX_MESSAGE_SIZE = 32768;
const size_t I2NP_MAX_SHORT_MESSAGE_SIZE = 2400;
struct I2NPMessage
{
uint8_t buf[I2NP_MAX_MESSAGE_SIZE];
uint8_t * buf;
size_t len, offset;
i2p::tunnel::InboundTunnel * from;
I2NPMessage (): buf (nullptr),len (sizeof (I2NPHeader) + 2), offset(2), from (nullptr) {};
// reserve 2 bytes for NTCP header
I2NPHeader * GetHeader () { return (I2NPHeader *)GetBuffer (); };
uint8_t * GetPayload () { return GetBuffer () + sizeof(I2NPHeader); };
uint8_t * GetBuffer () { return buf + offset; };
@ -144,7 +147,16 @@ namespace tunnel
return be32toh (header.msgID);
}
};
template<int sz>
struct I2NPMessageBuffer: public I2NPMessage
{
I2NPMessageBuffer () { buf = m_Buffer; };
uint8_t m_Buffer[sz];
};
I2NPMessage * NewI2NPMessage ();
I2NPMessage * NewI2NPShortMessage ();
void DeleteI2NPMessage (I2NPMessage * msg);
void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID = 0);
void RenewI2NPMessageHeader (I2NPMessage * msg);