|
|
@ -58,6 +58,14 @@ namespace i2p |
|
|
|
return msg; |
|
|
|
return msg; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
I2NPMessage * msg = NewI2NPMessage (); |
|
|
|
|
|
|
|
memcpy (msg->GetBuffer (), buf, len); |
|
|
|
|
|
|
|
msg->len += msg->offset + len; |
|
|
|
|
|
|
|
return msg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * CreateDeliveryStatusMsg () |
|
|
|
I2NPMessage * CreateDeliveryStatusMsg () |
|
|
|
{ |
|
|
|
{ |
|
|
|
#pragma pack(1) |
|
|
|
#pragma pack(1) |
|
|
@ -238,8 +246,17 @@ namespace i2p |
|
|
|
encryption.ProcessData((uint8_t *)(records + j), (uint8_t *)(records + j), sizeof (records[j])); |
|
|
|
encryption.ProcessData((uint8_t *)(records + j), (uint8_t *)(records + j), sizeof (records[j])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
i2p::transports.SendMessage (clearText.nextIdent, |
|
|
|
if (clearText.flag & 0x40) // we are endpoint of outboud tunnel
|
|
|
|
CreateI2NPMessage (eI2NPVariableTunnelBuild, buf, len, be32toh (clearText.nextMessageID))); |
|
|
|
{ |
|
|
|
|
|
|
|
// so we send it to reply tunnel
|
|
|
|
|
|
|
|
i2p::transports.SendMessage (clearText.nextIdent, |
|
|
|
|
|
|
|
CreateTunnelGatewayMsg (be32toh (clearText.nextTunnel), |
|
|
|
|
|
|
|
eI2NPVariableTunnelBuildReply, buf, len, |
|
|
|
|
|
|
|
be32toh (clearText.nextMessageID))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
i2p::transports.SendMessage (clearText.nextIdent, |
|
|
|
|
|
|
|
CreateI2NPMessage (eI2NPVariableTunnelBuild, buf, len, be32toh (clearText.nextMessageID))); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -279,22 +296,80 @@ namespace i2p |
|
|
|
return msg; |
|
|
|
return msg; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, const uint8_t * buf, size_t len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
I2NPMessage * msg = NewI2NPMessage (); |
|
|
|
|
|
|
|
TunnelGatewayHeader * header = (TunnelGatewayHeader *)msg->GetPayload (); |
|
|
|
|
|
|
|
header->tunnelID = htobe32 (tunnelID); |
|
|
|
|
|
|
|
header->length = htobe16 (len); |
|
|
|
|
|
|
|
memcpy (msg->GetPayload () + sizeof (TunnelGatewayHeader), buf, len); |
|
|
|
|
|
|
|
msg->len += sizeof (TunnelGatewayHeader) + len; |
|
|
|
|
|
|
|
FillI2NPMessageHeader (msg, eI2NPTunnelGateway); |
|
|
|
|
|
|
|
return msg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessage * msg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (msg->offset >= sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// message is capable to be used without copying
|
|
|
|
|
|
|
|
TunnelGatewayHeader * header = (TunnelGatewayHeader *)(msg->GetBuffer () - sizeof (TunnelGatewayHeader)); |
|
|
|
|
|
|
|
header->tunnelID = htobe32 (tunnelID); |
|
|
|
|
|
|
|
int len = msg->GetLength (); |
|
|
|
|
|
|
|
header->length = htobe16 (len); |
|
|
|
|
|
|
|
msg->offset -= (sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader)); |
|
|
|
|
|
|
|
msg->len = msg->offset + sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader) +len; |
|
|
|
|
|
|
|
FillI2NPMessageHeader (msg, eI2NPTunnelGateway); |
|
|
|
|
|
|
|
return msg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
I2NPMessage * msg1 = CreateTunnelGatewayMsg (tunnelID, msg->GetBuffer (), msg->GetLength ()); |
|
|
|
|
|
|
|
DeleteI2NPMessage (msg); |
|
|
|
|
|
|
|
return msg1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessageType msgType, |
|
|
|
|
|
|
|
const uint8_t * buf, size_t len, uint32_t replyMsgID) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
I2NPMessage * msg = NewI2NPMessage (); |
|
|
|
|
|
|
|
size_t gatewayMsgOffset = sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader); |
|
|
|
|
|
|
|
msg->offset += gatewayMsgOffset; |
|
|
|
|
|
|
|
msg->len += gatewayMsgOffset; |
|
|
|
|
|
|
|
memcpy (msg->GetPayload (), buf, len); |
|
|
|
|
|
|
|
msg->len += len; |
|
|
|
|
|
|
|
FillI2NPMessageHeader (msg, msgType, replyMsgID); // create content message
|
|
|
|
|
|
|
|
len = msg->GetLength (); |
|
|
|
|
|
|
|
msg->offset -= gatewayMsgOffset; |
|
|
|
|
|
|
|
TunnelGatewayHeader * header = (TunnelGatewayHeader *)msg->GetPayload (); |
|
|
|
|
|
|
|
header->tunnelID = htobe32 (tunnelID); |
|
|
|
|
|
|
|
header->length = htobe16 (len); |
|
|
|
|
|
|
|
FillI2NPMessageHeader (msg, eI2NPTunnelGateway); // gateway message
|
|
|
|
|
|
|
|
return msg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HandleTunnelGatewayMsg (uint8_t * buf, size_t len) |
|
|
|
void HandleTunnelGatewayMsg (I2NPMessage * msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
TunnelGatewayHeader * header = (TunnelGatewayHeader *)buf; |
|
|
|
TunnelGatewayHeader * header = (TunnelGatewayHeader *)msg->GetPayload (); |
|
|
|
uint32_t tunnelID = be32toh(header->tunnelID); |
|
|
|
uint32_t tunnelID = be32toh(header->tunnelID); |
|
|
|
LogPrint ("TunnelGateway of ", (int)be16toh(header->length), |
|
|
|
uint16_t len = be16toh(header->length); |
|
|
|
" bytes for tunnel ", (unsigned int)tunnelID); |
|
|
|
LogPrint ("TunnelGateway of ", (int)len, " bytes for tunnel ", (unsigned int)tunnelID); |
|
|
|
i2p::tunnel::Tunnel * tunnel = i2p::tunnel::tunnels.GetTunnel (tunnelID); |
|
|
|
i2p::tunnel::TransitTunnel * tunnel = i2p::tunnel::tunnels.GetTransitTunnel (tunnelID); |
|
|
|
if (tunnel) |
|
|
|
if (tunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// TODO: we must submit message to tunnel
|
|
|
|
// we make payload as new I2NP message to send
|
|
|
|
|
|
|
|
msg->offset += sizeof (I2NPHeader) + sizeof (TunnelGatewayHeader); |
|
|
|
|
|
|
|
msg->len = msg->offset + len; |
|
|
|
|
|
|
|
tunnel->SendTunnelDataMsg (nullptr, 0, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
LogPrint ("Tunnel ", (unsigned int)tunnelID, " not found"); |
|
|
|
LogPrint ("Tunnel ", (unsigned int)tunnelID, " not found"); |
|
|
|
|
|
|
|
i2p::DeleteI2NPMessage (msg); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HandleI2NPMessage (uint8_t * msg, size_t len) |
|
|
|
void HandleI2NPMessage (uint8_t * msg, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
I2NPHeader * header = (I2NPHeader *)msg; |
|
|
|
I2NPHeader * header = (I2NPHeader *)msg; |
|
|
@ -305,9 +380,6 @@ namespace i2p |
|
|
|
int size = be16toh (header->size); |
|
|
|
int size = be16toh (header->size); |
|
|
|
switch (header->typeID) |
|
|
|
switch (header->typeID) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case eI2NPTunnelData: // main message
|
|
|
|
|
|
|
|
LogPrint ("Unexpected TunnelData"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case eI2NPGarlic: |
|
|
|
case eI2NPGarlic: |
|
|
|
LogPrint ("Garlic"); |
|
|
|
LogPrint ("Garlic"); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -326,16 +398,12 @@ namespace i2p |
|
|
|
LogPrint ("VariableTunnelBuild"); |
|
|
|
LogPrint ("VariableTunnelBuild"); |
|
|
|
HandleVariableTunnelBuildMsg (msgID, buf, size); |
|
|
|
HandleVariableTunnelBuildMsg (msgID, buf, size); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPTunnelGateway: |
|
|
|
|
|
|
|
LogPrint ("TunnelGateway"); |
|
|
|
|
|
|
|
HandleTunnelGatewayMsg (buf, size); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case eI2NPVariableTunnelBuildReply: |
|
|
|
case eI2NPVariableTunnelBuildReply: |
|
|
|
LogPrint ("VariableTunnelBuildReply"); |
|
|
|
LogPrint ("VariableTunnelBuildReply"); |
|
|
|
HandleVariableTunnelBuildReplyMsg (msgID, buf, size); |
|
|
|
HandleVariableTunnelBuildReplyMsg (msgID, buf, size); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
; |
|
|
|
LogPrint ("Unexpected message ", (int)header->typeID); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -348,6 +416,11 @@ namespace i2p |
|
|
|
LogPrint ("TunnelData"); |
|
|
|
LogPrint ("TunnelData"); |
|
|
|
i2p::tunnel::tunnels.PostTunnelData (msg); |
|
|
|
i2p::tunnel::tunnels.PostTunnelData (msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (msg->GetHeader ()->typeID == eI2NPTunnelGateway) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint ("TunnelGateway"); |
|
|
|
|
|
|
|
HandleTunnelGatewayMsg (msg); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); |
|
|
|
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); |
|
|
|