|
|
@ -60,7 +60,7 @@ namespace i2p |
|
|
|
msg->len += len; |
|
|
|
msg->len += len; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogError, "I2NP message length ", len, " exceeds max length"); |
|
|
|
LogPrint (eLogError, "I2NP: message length ", len, " exceeds max length"); |
|
|
|
msg->FillI2NPMessageHeader (msgType, replyMsgID); |
|
|
|
msg->FillI2NPMessageHeader (msgType, replyMsgID); |
|
|
|
return msg; |
|
|
|
return msg; |
|
|
|
} |
|
|
|
} |
|
|
@ -75,7 +75,7 @@ namespace i2p |
|
|
|
msg->from = from; |
|
|
|
msg->from = from; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogError, "I2NP message length ", len, " exceeds max length"); |
|
|
|
LogPrint (eLogError, "I2NP: message length ", len, " exceeds max length"); |
|
|
|
return msg; |
|
|
|
return msg; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -276,7 +276,7 @@ namespace i2p |
|
|
|
uint8_t * record = records + i*TUNNEL_BUILD_RECORD_SIZE; |
|
|
|
uint8_t * record = records + i*TUNNEL_BUILD_RECORD_SIZE; |
|
|
|
if (!memcmp (record + BUILD_REQUEST_RECORD_TO_PEER_OFFSET, (const uint8_t *)i2p::context.GetRouterInfo ().GetIdentHash (), 16)) |
|
|
|
if (!memcmp (record + BUILD_REQUEST_RECORD_TO_PEER_OFFSET, (const uint8_t *)i2p::context.GetRouterInfo ().GetIdentHash (), 16)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Record ",i," is ours"); |
|
|
|
LogPrint (eLogDebug, "I2NP: Build request record ", i, " is ours"); |
|
|
|
|
|
|
|
|
|
|
|
i2p::crypto::ElGamalDecrypt (i2p::context.GetEncryptionPrivateKey (), record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET, clearText); |
|
|
|
i2p::crypto::ElGamalDecrypt (i2p::context.GetEncryptionPrivateKey (), record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET, clearText); |
|
|
|
// replace record to reply
|
|
|
|
// replace record to reply
|
|
|
@ -320,22 +320,22 @@ namespace i2p |
|
|
|
void HandleVariableTunnelBuildMsg (uint32_t replyMsgID, uint8_t * buf, size_t len) |
|
|
|
void HandleVariableTunnelBuildMsg (uint32_t replyMsgID, uint8_t * buf, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int num = buf[0]; |
|
|
|
int num = buf[0]; |
|
|
|
LogPrint ("VariableTunnelBuild ", num, " records"); |
|
|
|
LogPrint (eLogDebug, "I2NP: VariableTunnelBuild ", num, " records"); |
|
|
|
|
|
|
|
|
|
|
|
auto tunnel = i2p::tunnel::tunnels.GetPendingInboundTunnel (replyMsgID); |
|
|
|
auto tunnel = i2p::tunnel::tunnels.GetPendingInboundTunnel (replyMsgID); |
|
|
|
if (tunnel) |
|
|
|
if (tunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// endpoint of inbound tunnel
|
|
|
|
// endpoint of inbound tunnel
|
|
|
|
LogPrint ("VariableTunnelBuild reply for tunnel ", tunnel->GetTunnelID ()); |
|
|
|
LogPrint (eLogDebug, "I2NP: VariableTunnelBuild reply for tunnel ", tunnel->GetTunnelID ()); |
|
|
|
if (tunnel->HandleTunnelBuildResponse (buf, len)) |
|
|
|
if (tunnel->HandleTunnelBuildResponse (buf, len)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Inbound tunnel ", tunnel->GetTunnelID (), " has been created"); |
|
|
|
LogPrint (eLogInfo, "I2NP: Inbound tunnel ", tunnel->GetTunnelID (), " has been created"); |
|
|
|
tunnel->SetState (i2p::tunnel::eTunnelStateEstablished); |
|
|
|
tunnel->SetState (i2p::tunnel::eTunnelStateEstablished); |
|
|
|
i2p::tunnel::tunnels.AddInboundTunnel (tunnel); |
|
|
|
i2p::tunnel::tunnels.AddInboundTunnel (tunnel); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Inbound tunnel ", tunnel->GetTunnelID (), " has been declined"); |
|
|
|
LogPrint (eLogInfo, "I2NP: Inbound tunnel ", tunnel->GetTunnelID (), " has been declined"); |
|
|
|
tunnel->SetState (i2p::tunnel::eTunnelStateBuildFailed); |
|
|
|
tunnel->SetState (i2p::tunnel::eTunnelStateBuildFailed); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -382,25 +382,25 @@ namespace i2p |
|
|
|
|
|
|
|
|
|
|
|
void HandleVariableTunnelBuildReplyMsg (uint32_t replyMsgID, uint8_t * buf, size_t len) |
|
|
|
void HandleVariableTunnelBuildReplyMsg (uint32_t replyMsgID, uint8_t * buf, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("VariableTunnelBuildReplyMsg replyMsgID=", replyMsgID); |
|
|
|
LogPrint (eLogDebug, "I2NP: VariableTunnelBuildReplyMsg replyMsgID=", replyMsgID); |
|
|
|
auto tunnel = i2p::tunnel::tunnels.GetPendingOutboundTunnel (replyMsgID); |
|
|
|
auto tunnel = i2p::tunnel::tunnels.GetPendingOutboundTunnel (replyMsgID); |
|
|
|
if (tunnel) |
|
|
|
if (tunnel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// reply for outbound tunnel
|
|
|
|
// reply for outbound tunnel
|
|
|
|
if (tunnel->HandleTunnelBuildResponse (buf, len)) |
|
|
|
if (tunnel->HandleTunnelBuildResponse (buf, len)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Outbound tunnel ", tunnel->GetTunnelID (), " has been created"); |
|
|
|
LogPrint (eLogInfo, "I2NP: Outbound tunnel ", tunnel->GetTunnelID (), " has been created"); |
|
|
|
tunnel->SetState (i2p::tunnel::eTunnelStateEstablished); |
|
|
|
tunnel->SetState (i2p::tunnel::eTunnelStateEstablished); |
|
|
|
i2p::tunnel::tunnels.AddOutboundTunnel (tunnel); |
|
|
|
i2p::tunnel::tunnels.AddOutboundTunnel (tunnel); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Outbound tunnel ", tunnel->GetTunnelID (), " has been declined"); |
|
|
|
LogPrint (eLogInfo, "I2NP: Outbound tunnel ", tunnel->GetTunnelID (), " has been declined"); |
|
|
|
tunnel->SetState (i2p::tunnel::eTunnelStateBuildFailed); |
|
|
|
tunnel->SetState (i2p::tunnel::eTunnelStateBuildFailed); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint ("Pending tunnel for message ", replyMsgID, " not found"); |
|
|
|
LogPrint (eLogWarning, "I2NP: Pending tunnel for message ", replyMsgID, " not found"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -488,30 +488,26 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t typeID = msg[I2NP_HEADER_TYPEID_OFFSET]; |
|
|
|
uint8_t typeID = msg[I2NP_HEADER_TYPEID_OFFSET]; |
|
|
|
uint32_t msgID = bufbe32toh (msg + I2NP_HEADER_MSGID_OFFSET); |
|
|
|
uint32_t msgID = bufbe32toh (msg + I2NP_HEADER_MSGID_OFFSET); |
|
|
|
LogPrint ("I2NP msg received len=", len,", type=", (int)typeID, ", msgID=", (unsigned int)msgID); |
|
|
|
LogPrint (eLogDebug, "I2NP: msg received len=", len,", type=", (int)typeID, ", msgID=", (unsigned int)msgID); |
|
|
|
|
|
|
|
|
|
|
|
uint8_t * buf = msg + I2NP_HEADER_SIZE; |
|
|
|
uint8_t * buf = msg + I2NP_HEADER_SIZE; |
|
|
|
int size = bufbe16toh (msg + I2NP_HEADER_SIZE_OFFSET); |
|
|
|
int size = bufbe16toh (msg + I2NP_HEADER_SIZE_OFFSET); |
|
|
|
switch (typeID) |
|
|
|
switch (typeID) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case eI2NPVariableTunnelBuild: |
|
|
|
case eI2NPVariableTunnelBuild: |
|
|
|
LogPrint ("VariableTunnelBuild"); |
|
|
|
|
|
|
|
HandleVariableTunnelBuildMsg (msgID, buf, size); |
|
|
|
HandleVariableTunnelBuildMsg (msgID, buf, size); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPVariableTunnelBuildReply: |
|
|
|
case eI2NPVariableTunnelBuildReply: |
|
|
|
LogPrint ("VariableTunnelBuildReply"); |
|
|
|
|
|
|
|
HandleVariableTunnelBuildReplyMsg (msgID, buf, size); |
|
|
|
HandleVariableTunnelBuildReplyMsg (msgID, buf, size); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPTunnelBuild: |
|
|
|
case eI2NPTunnelBuild: |
|
|
|
LogPrint ("TunnelBuild"); |
|
|
|
|
|
|
|
HandleTunnelBuildMsg (buf, size); |
|
|
|
HandleTunnelBuildMsg (buf, size); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPTunnelBuildReply: |
|
|
|
case eI2NPTunnelBuildReply: |
|
|
|
LogPrint ("TunnelBuildReply"); |
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// TODO:
|
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
LogPrint ("Unexpected message ", (int)typeID); |
|
|
|
LogPrint (eLogWarning, "I2NP: Unexpected message ", (int)typeID); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -519,25 +515,24 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (msg) |
|
|
|
if (msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (msg->GetTypeID ()) |
|
|
|
uint8_t typeID = msg->GetTypeID (); |
|
|
|
|
|
|
|
LogPrint (eLogDebug, "I2NP: Got message with type ", (int)typeID); |
|
|
|
|
|
|
|
switch (typeID) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case eI2NPTunnelData: |
|
|
|
case eI2NPTunnelData: |
|
|
|
LogPrint ("TunnelData"); |
|
|
|
|
|
|
|
i2p::tunnel::tunnels.PostTunnelData (msg); |
|
|
|
i2p::tunnel::tunnels.PostTunnelData (msg); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPTunnelGateway: |
|
|
|
case eI2NPTunnelGateway: |
|
|
|
LogPrint ("TunnelGateway"); |
|
|
|
|
|
|
|
i2p::tunnel::tunnels.PostTunnelData (msg); |
|
|
|
i2p::tunnel::tunnels.PostTunnelData (msg); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPGarlic: |
|
|
|
case eI2NPGarlic: |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Garlic"); |
|
|
|
|
|
|
|
if (msg->from) |
|
|
|
if (msg->from) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (msg->from->GetTunnelPool ()) |
|
|
|
if (msg->from->GetTunnelPool ()) |
|
|
|
msg->from->GetTunnelPool ()->ProcessGarlicMessage (msg); |
|
|
|
msg->from->GetTunnelPool ()->ProcessGarlicMessage (msg); |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogInfo, "Local destination for garlic doesn't exist anymore"); |
|
|
|
LogPrint (eLogInfo, "I2NP: Local destination for garlic doesn't exist anymore"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
i2p::context.ProcessGarlicMessage (msg); |
|
|
|
i2p::context.ProcessGarlicMessage (msg); |
|
|
@ -551,7 +546,6 @@ namespace i2p |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eI2NPDeliveryStatus: |
|
|
|
case eI2NPDeliveryStatus: |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("DeliveryStatus"); |
|
|
|
|
|
|
|
if (msg->from && msg->from->GetTunnelPool ()) |
|
|
|
if (msg->from && msg->from->GetTunnelPool ()) |
|
|
|
msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg); |
|
|
|
msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg); |
|
|
|
else |
|
|
|
else |
|
|
|