Browse Source

eliminated TunnelGatewayHeader

pull/129/head
orignal 10 years ago
parent
commit
0f07b04627
  1. 45
      I2NPProtocol.cpp
  2. 15
      I2NPProtocol.h
  3. 4
      TunnelEndpoint.cpp

45
I2NPProtocol.cpp

@ -464,26 +464,26 @@ namespace i2p
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, const uint8_t * buf, size_t len) I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, const uint8_t * buf, size_t len)
{ {
I2NPMessage * msg = NewI2NPMessage (len); I2NPMessage * msg = NewI2NPMessage (len);
TunnelGatewayHeader * header = (TunnelGatewayHeader *)msg->GetPayload (); uint8_t * payload = msg->GetPayload ();
header->tunnelID = htobe32 (tunnelID); htobe32buf (payload + TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET, tunnelID);
header->length = htobe16 (len); htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len);
memcpy (msg->GetPayload () + sizeof (TunnelGatewayHeader), buf, len); memcpy (payload + TUNNEL_GATEWAY_HEADER_SIZE, buf, len);
msg->len += sizeof (TunnelGatewayHeader) + len; msg->len += TUNNEL_GATEWAY_HEADER_SIZE + len;
FillI2NPMessageHeader (msg, eI2NPTunnelGateway); FillI2NPMessageHeader (msg, eI2NPTunnelGateway);
return msg; return msg;
} }
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessage * msg) I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessage * msg)
{ {
if (msg->offset >= sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader)) if (msg->offset >= I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE)
{ {
// message is capable to be used without copying // message is capable to be used without copying
TunnelGatewayHeader * header = (TunnelGatewayHeader *)(msg->GetBuffer () - sizeof (TunnelGatewayHeader)); uint8_t * payload = msg->GetBuffer () - TUNNEL_GATEWAY_HEADER_SIZE;
header->tunnelID = htobe32 (tunnelID); htobe32buf (payload + TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET, tunnelID);
int len = msg->GetLength (); int len = msg->GetLength ();
header->length = htobe16 (len); htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len);
msg->offset -= (sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader)); msg->offset -= (I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE);
msg->len = msg->offset + sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader) +len; msg->len = msg->offset + I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE +len;
FillI2NPMessageHeader (msg, eI2NPTunnelGateway); FillI2NPMessageHeader (msg, eI2NPTunnelGateway);
return msg; return msg;
} }
@ -499,7 +499,7 @@ namespace i2p
const uint8_t * buf, size_t len, uint32_t replyMsgID) const uint8_t * buf, size_t len, uint32_t replyMsgID)
{ {
I2NPMessage * msg = NewI2NPMessage (len); I2NPMessage * msg = NewI2NPMessage (len);
size_t gatewayMsgOffset = sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader); size_t gatewayMsgOffset = I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE;
msg->offset += gatewayMsgOffset; msg->offset += gatewayMsgOffset;
msg->len += gatewayMsgOffset; msg->len += gatewayMsgOffset;
memcpy (msg->GetPayload (), buf, len); memcpy (msg->GetPayload (), buf, len);
@ -507,24 +507,25 @@ namespace i2p
FillI2NPMessageHeader (msg, msgType, replyMsgID); // create content message FillI2NPMessageHeader (msg, msgType, replyMsgID); // create content message
len = msg->GetLength (); len = msg->GetLength ();
msg->offset -= gatewayMsgOffset; msg->offset -= gatewayMsgOffset;
TunnelGatewayHeader * header = (TunnelGatewayHeader *)msg->GetPayload (); uint8_t * payload = msg->GetPayload ();
header->tunnelID = htobe32 (tunnelID); htobe32buf (payload + TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET, tunnelID);
header->length = htobe16 (len); htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len);
FillI2NPMessageHeader (msg, eI2NPTunnelGateway); // gateway message FillI2NPMessageHeader (msg, eI2NPTunnelGateway); // gateway message
return msg; return msg;
} }
void HandleTunnelGatewayMsg (I2NPMessage * msg) void HandleTunnelGatewayMsg (I2NPMessage * msg)
{ {
TunnelGatewayHeader * header = (TunnelGatewayHeader *)msg->GetPayload (); const uint8_t * payload = msg->GetPayload ();
uint32_t tunnelID = be32toh(header->tunnelID); uint32_t tunnelID = bufbe32toh(payload + TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET);
uint16_t len = be16toh(header->length); uint16_t len = bufbe16toh(payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET);
// we make payload as new I2NP message to send // we make payload as new I2NP message to send
msg->offset += sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader); msg->offset += I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE;
msg->len = msg->offset + len; msg->len = msg->offset + len;
LogPrint ("TunnelGateway of ", (int)len, " bytes for tunnel ", (unsigned int)tunnelID, ". Msg type ", (int)msg->GetHeader()->typeID); auto typeID = msg->GetTypeID ();
if (msg->GetHeader()->typeID == eI2NPDatabaseStore || LogPrint ("TunnelGateway of ", (int)len, " bytes for tunnel ", (unsigned int)tunnelID, ". Msg type ", (int)typeID);
msg->GetHeader()->typeID == eI2NPDatabaseSearchReply)
if (typeID == eI2NPDatabaseStore || typeID == eI2NPDatabaseSearchReply)
{ {
// transit DatabaseStore my contain new/updated RI // transit DatabaseStore my contain new/updated RI
// or DatabaseSearchReply with new routers // or DatabaseSearchReply with new routers

15
I2NPProtocol.h

@ -18,7 +18,13 @@ namespace i2p
const size_t I2NP_HEADER_EXPIRATION_OFFSET = I2NP_HEADER_MSGID_OFFSET + 4; const size_t I2NP_HEADER_EXPIRATION_OFFSET = I2NP_HEADER_MSGID_OFFSET + 4;
const size_t I2NP_HEADER_SIZE_OFFSET = I2NP_HEADER_EXPIRATION_OFFSET + 8; const size_t I2NP_HEADER_SIZE_OFFSET = I2NP_HEADER_EXPIRATION_OFFSET + 8;
const size_t I2NP_HEADER_CHKS_OFFSET = I2NP_HEADER_SIZE_OFFSET + 2; const size_t I2NP_HEADER_CHKS_OFFSET = I2NP_HEADER_SIZE_OFFSET + 2;
const size_t I2NP_HEADER_SIZE = I2NP_HEADER_CHKS_OFFSET + 1;
// Tunnel Gateway header
const size_t TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET = 0;
const size_t TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET = TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET + 4;
const size_t TUNNEL_GATEWAY_HEADER_SIZE = TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET + 2;
#pragma pack (1) #pragma pack (1)
struct I2NPHeader struct I2NPHeader
@ -77,13 +83,6 @@ namespace i2p
uint8_t toPeer[16]; uint8_t toPeer[16];
uint8_t encrypted[512]; uint8_t encrypted[512];
}; };
struct TunnelGatewayHeader
{
uint32_t tunnelID;
uint16_t length;
};
#pragma pack () #pragma pack ()

4
TunnelEndpoint.cpp

@ -105,8 +105,8 @@ namespace tunnel
{ {
// this is not last message. we have to copy it // this is not last message. we have to copy it
m.data = NewI2NPMessage (); m.data = NewI2NPMessage ();
m.data->offset += sizeof (TunnelGatewayHeader); // reserve room for TunnelGateway header m.data->offset += TUNNEL_GATEWAY_HEADER_SIZE; // reserve room for TunnelGateway header
m.data->len += sizeof (TunnelGatewayHeader); m.data->len += TUNNEL_GATEWAY_HEADER_SIZE;
*(m.data) = *msg; *(m.data) = *msg;
} }
else else

Loading…
Cancel
Save