|
|
@ -40,7 +40,7 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
return std::make_shared<I2NPMessageBuffer<I2NP_MAX_MEDIUM_MESSAGE_SIZE> >(); |
|
|
|
return std::make_shared<I2NPMessageBuffer<I2NP_MAX_MEDIUM_MESSAGE_SIZE> >(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<I2NPMessage> NewI2NPTunnelMessage (bool endpoint) |
|
|
|
std::shared_ptr<I2NPMessage> NewI2NPTunnelMessage (bool endpoint) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return i2p::tunnel::tunnels.NewI2NPTunnelMessage (endpoint); |
|
|
|
return i2p::tunnel::tunnels.NewI2NPTunnelMessage (endpoint); |
|
|
@ -51,7 +51,7 @@ namespace i2p |
|
|
|
len += I2NP_HEADER_SIZE + 2; |
|
|
|
len += I2NP_HEADER_SIZE + 2; |
|
|
|
if (len <= I2NP_MAX_SHORT_MESSAGE_SIZE) return NewI2NPShortMessage (); |
|
|
|
if (len <= I2NP_MAX_SHORT_MESSAGE_SIZE) return NewI2NPShortMessage (); |
|
|
|
if (len <= I2NP_MAX_MEDIUM_MESSAGE_SIZE) return NewI2NPMediumMessage (); |
|
|
|
if (len <= I2NP_MAX_MEDIUM_MESSAGE_SIZE) return NewI2NPMediumMessage (); |
|
|
|
return NewI2NPMessage (); |
|
|
|
return NewI2NPMessage (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void I2NPMessage::FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID, bool checksum) |
|
|
|
void I2NPMessage::FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID, bool checksum) |
|
|
@ -428,7 +428,7 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "I2NP: Too many records in VaribleTunnelBuild message ", num); |
|
|
|
LogPrint (eLogError, "I2NP: Too many records in VaribleTunnelBuild message ", num); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (len < num*TUNNEL_BUILD_RECORD_SIZE + 1) |
|
|
|
if (len < num*TUNNEL_BUILD_RECORD_SIZE + 1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "I2NP: VaribleTunnelBuild message of ", num, " records is too short ", len); |
|
|
|
LogPrint (eLogError, "I2NP: VaribleTunnelBuild message of ", num, " records is too short ", len); |
|
|
@ -486,7 +486,7 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "I2NP: Too many records in TunnelBuildReply message ", num); |
|
|
|
LogPrint (eLogError, "I2NP: Too many records in TunnelBuildReply message ", num); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
size_t recordSize = isShort ? SHORT_TUNNEL_BUILD_RECORD_SIZE : TUNNEL_BUILD_RECORD_SIZE; |
|
|
|
size_t recordSize = isShort ? SHORT_TUNNEL_BUILD_RECORD_SIZE : TUNNEL_BUILD_RECORD_SIZE; |
|
|
|
if (len < num*recordSize + 1) |
|
|
|
if (len < num*recordSize + 1) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -522,7 +522,7 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "I2NP: Too many records in ShortTunnelBuild message ", num); |
|
|
|
LogPrint (eLogError, "I2NP: Too many records in ShortTunnelBuild message ", num); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (len < num*SHORT_TUNNEL_BUILD_RECORD_SIZE + 1) |
|
|
|
if (len < num*SHORT_TUNNEL_BUILD_RECORD_SIZE + 1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "I2NP: ShortTunnelBuild message of ", num, " records is too short ", len); |
|
|
|
LogPrint (eLogError, "I2NP: ShortTunnelBuild message of ", num, " records is too short ", len); |
|
|
@ -748,46 +748,38 @@ namespace i2p |
|
|
|
return l; |
|
|
|
return l; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HandleI2NPMessage (uint8_t * msg, size_t len) |
|
|
|
void HandleTunnelBuildI2NPMessage (std::shared_ptr<I2NPMessage> msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (len < I2NP_HEADER_SIZE) |
|
|
|
if (msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "I2NP: Message length ", len, " is smaller than header"); |
|
|
|
uint8_t typeID = msg->GetTypeID(); |
|
|
|
return; |
|
|
|
uint32_t msgID = msg->GetMsgID(); |
|
|
|
} |
|
|
|
LogPrint (eLogDebug, "I2NP: Handling tunnel build message with len=", msg->GetLength(),", type=", (int)typeID, ", msgID=", (unsigned int)msgID); |
|
|
|
uint8_t typeID = msg[I2NP_HEADER_TYPEID_OFFSET]; |
|
|
|
uint8_t * payload = msg->GetPayload(); |
|
|
|
uint32_t msgID = bufbe32toh (msg + I2NP_HEADER_MSGID_OFFSET); |
|
|
|
auto size = msg->GetPayloadLength(); |
|
|
|
LogPrint (eLogDebug, "I2NP: Msg received len=", len,", type=", (int)typeID, ", msgID=", (unsigned int)msgID); |
|
|
|
switch (typeID) |
|
|
|
uint8_t * buf = msg + I2NP_HEADER_SIZE; |
|
|
|
{ |
|
|
|
auto size = bufbe16toh (msg + I2NP_HEADER_SIZE_OFFSET); |
|
|
|
case eI2NPVariableTunnelBuild: |
|
|
|
len -= I2NP_HEADER_SIZE; |
|
|
|
HandleVariableTunnelBuildMsg (msgID, payload, size); |
|
|
|
if (size > len) |
|
|
|
break; |
|
|
|
{ |
|
|
|
case eI2NPShortTunnelBuild: |
|
|
|
LogPrint (eLogError, "I2NP: Payload size ", size, " exceeds buffer length ", len); |
|
|
|
HandleShortTunnelBuildMsg (msgID, payload, size); |
|
|
|
size = len; |
|
|
|
break; |
|
|
|
} |
|
|
|
case eI2NPVariableTunnelBuildReply: |
|
|
|
switch (typeID) |
|
|
|
HandleTunnelBuildReplyMsg (msgID, payload, size, false); |
|
|
|
{ |
|
|
|
break; |
|
|
|
case eI2NPVariableTunnelBuild: |
|
|
|
case eI2NPShortTunnelBuildReply: |
|
|
|
HandleVariableTunnelBuildMsg (msgID, buf, size); |
|
|
|
HandleTunnelBuildReplyMsg (msgID, payload, size, true); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPShortTunnelBuild: |
|
|
|
case eI2NPTunnelBuild: |
|
|
|
HandleShortTunnelBuildMsg (msgID, buf, size); |
|
|
|
HandleTunnelBuildMsg (payload, size); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPVariableTunnelBuildReply: |
|
|
|
case eI2NPTunnelBuildReply: |
|
|
|
HandleTunnelBuildReplyMsg (msgID, buf, size, false); |
|
|
|
// TODO:
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPShortTunnelBuildReply: |
|
|
|
default: |
|
|
|
HandleTunnelBuildReplyMsg (msgID, buf, size, true); |
|
|
|
LogPrint (eLogError, "I2NP: Unexpected message with type", (int)typeID, " during handling TBM; skipping"); |
|
|
|
break; |
|
|
|
} |
|
|
|
case eI2NPTunnelBuild: |
|
|
|
|
|
|
|
HandleTunnelBuildMsg (buf, size); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case eI2NPTunnelBuildReply: |
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
LogPrint (eLogWarning, "I2NP: Unexpected message ", (int)typeID); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -851,7 +843,7 @@ namespace i2p |
|
|
|
i2p::tunnel::tunnels.PostTunnelData (msg); |
|
|
|
i2p::tunnel::tunnels.PostTunnelData (msg); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); |
|
|
|
LogPrint(eLogError, "I2NP: Unexpected I2NP message with type ", int(typeID), " during handling; skipping"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|