|
|
@ -236,37 +236,14 @@ namespace i2p |
|
|
|
memcpy (record.toPeer, (const uint8_t *)router.GetIdentHash (), 16); |
|
|
|
memcpy (record.toPeer, (const uint8_t *)router.GetIdentHash (), 16); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HandleVariableTunnelBuildMsg (uint32_t replyMsgID, uint8_t * buf, size_t len) |
|
|
|
bool HandleBuildRequestRecords (int num, I2NPBuildRequestRecordElGamalEncrypted * records, I2NPBuildRequestRecordClearText& clearText) |
|
|
|
{ |
|
|
|
|
|
|
|
int num = buf[0]; |
|
|
|
|
|
|
|
LogPrint ("VariableTunnelBuild ", num, " records"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i2p::tunnel::Tunnel * tunnel = i2p::tunnel::tunnels.GetPendingTunnel (replyMsgID); |
|
|
|
|
|
|
|
if (tunnel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// endpoint of inbound tunnel
|
|
|
|
|
|
|
|
LogPrint ("VariableTunnelBuild reply for tunnel ", tunnel->GetTunnelID ()); |
|
|
|
|
|
|
|
if (tunnel->HandleTunnelBuildResponse (buf, len)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint ("Inbound tunnel ", tunnel->GetTunnelID (), " has been created"); |
|
|
|
|
|
|
|
i2p::tunnel::tunnels.AddInboundTunnel (static_cast<i2p::tunnel::InboundTunnel *>(tunnel)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint ("Inbound tunnel ", tunnel->GetTunnelID (), " has been declined"); |
|
|
|
|
|
|
|
delete tunnel; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
I2NPBuildRequestRecordElGamalEncrypted * records = (I2NPBuildRequestRecordElGamalEncrypted *)(buf+1); |
|
|
|
|
|
|
|
for (int i = 0; i < num; i++) |
|
|
|
for (int i = 0; i < num; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!memcmp (records[i].toPeer, (const uint8_t *)i2p::context.GetRouterInfo ().GetIdentHash (), 16)) |
|
|
|
if (!memcmp (records[i].toPeer, (const uint8_t *)i2p::context.GetRouterInfo ().GetIdentHash (), 16)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("Record ",i," is ours"); |
|
|
|
LogPrint ("Record ",i," is ours"); |
|
|
|
|
|
|
|
|
|
|
|
I2NPBuildRequestRecordClearText clearText; |
|
|
|
|
|
|
|
i2p::crypto::ElGamalDecrypt (i2p::context.GetPrivateKey (), records[i].encrypted, (uint8_t *)&clearText); |
|
|
|
i2p::crypto::ElGamalDecrypt (i2p::context.GetPrivateKey (), records[i].encrypted, (uint8_t *)&clearText); |
|
|
|
|
|
|
|
|
|
|
|
i2p::tunnel::TransitTunnel * transitTunnel = |
|
|
|
i2p::tunnel::TransitTunnel * transitTunnel = |
|
|
@ -288,7 +265,39 @@ namespace i2p |
|
|
|
encryption.SetKeyWithIV (clearText.replyKey, 32, clearText.replyIV); |
|
|
|
encryption.SetKeyWithIV (clearText.replyKey, 32, clearText.replyIV); |
|
|
|
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])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void HandleVariableTunnelBuildMsg (uint32_t replyMsgID, uint8_t * buf, size_t len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int num = buf[0]; |
|
|
|
|
|
|
|
LogPrint ("VariableTunnelBuild ", num, " records"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i2p::tunnel::Tunnel * tunnel = i2p::tunnel::tunnels.GetPendingTunnel (replyMsgID); |
|
|
|
|
|
|
|
if (tunnel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// endpoint of inbound tunnel
|
|
|
|
|
|
|
|
LogPrint ("VariableTunnelBuild reply for tunnel ", tunnel->GetTunnelID ()); |
|
|
|
|
|
|
|
if (tunnel->HandleTunnelBuildResponse (buf, len)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint ("Inbound tunnel ", tunnel->GetTunnelID (), " has been created"); |
|
|
|
|
|
|
|
i2p::tunnel::tunnels.AddInboundTunnel (static_cast<i2p::tunnel::InboundTunnel *>(tunnel)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint ("Inbound tunnel ", tunnel->GetTunnelID (), " has been declined"); |
|
|
|
|
|
|
|
delete tunnel; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
I2NPBuildRequestRecordElGamalEncrypted * records = (I2NPBuildRequestRecordElGamalEncrypted *)(buf+1); |
|
|
|
|
|
|
|
I2NPBuildRequestRecordClearText clearText; |
|
|
|
|
|
|
|
if (HandleBuildRequestRecords (num, records, clearText)) |
|
|
|
|
|
|
|
{ |
|
|
|
if (clearText.flag & 0x40) // we are endpoint of outboud tunnel
|
|
|
|
if (clearText.flag & 0x40) // we are endpoint of outboud tunnel
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// so we send it to reply tunnel
|
|
|
|
// so we send it to reply tunnel
|
|
|
@ -300,10 +309,27 @@ namespace i2p |
|
|
|
else |
|
|
|
else |
|
|
|
i2p::transports.SendMessage (clearText.nextIdent, |
|
|
|
i2p::transports.SendMessage (clearText.nextIdent, |
|
|
|
CreateI2NPMessage (eI2NPVariableTunnelBuild, buf, len, be32toh (clearText.nextMessageID))); |
|
|
|
CreateI2NPMessage (eI2NPVariableTunnelBuild, buf, len, be32toh (clearText.nextMessageID))); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void HandleTunnelBuildMsg (uint8_t * buf, size_t len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
I2NPBuildRequestRecordClearText clearText; |
|
|
|
|
|
|
|
if (HandleBuildRequestRecords (NUM_TUNNEL_BUILD_RECORDS, (I2NPBuildRequestRecordElGamalEncrypted *)buf, clearText)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (clearText.flag & 0x40) // we are endpoint of outbound tunnel
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// so we send it to reply tunnel
|
|
|
|
|
|
|
|
i2p::transports.SendMessage (clearText.nextIdent, |
|
|
|
|
|
|
|
CreateTunnelGatewayMsg (be32toh (clearText.nextTunnel), |
|
|
|
|
|
|
|
eI2NPTunnelBuildReply, buf, len, |
|
|
|
|
|
|
|
be32toh (clearText.nextMessageID))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
i2p::transports.SendMessage (clearText.nextIdent, |
|
|
|
|
|
|
|
CreateI2NPMessage (eI2NPTunnelBuild, buf, len, be32toh (clearText.nextMessageID))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HandleVariableTunnelBuildReplyMsg (uint32_t replyMsgID, uint8_t * buf, size_t len) |
|
|
|
void HandleVariableTunnelBuildReplyMsg (uint32_t replyMsgID, uint8_t * buf, size_t len) |
|
|
@ -444,6 +470,14 @@ namespace i2p |
|
|
|
LogPrint ("VariableTunnelBuildReply"); |
|
|
|
LogPrint ("VariableTunnelBuildReply"); |
|
|
|
HandleVariableTunnelBuildReplyMsg (msgID, buf, size); |
|
|
|
HandleVariableTunnelBuildReplyMsg (msgID, buf, size); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case eI2NPTunnelBuild: |
|
|
|
|
|
|
|
LogPrint ("TunnelBuild"); |
|
|
|
|
|
|
|
HandleTunnelBuildMsg (buf, size); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case eI2NPTunnelBuildReply: |
|
|
|
|
|
|
|
LogPrint ("TunnelBuildReply"); |
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
break; |
|
|
|
case eI2NPDatabaseLookup: |
|
|
|
case eI2NPDatabaseLookup: |
|
|
|
LogPrint ("DatabaseLookup"); |
|
|
|
LogPrint ("DatabaseLookup"); |
|
|
|
HandleDatabaseLookupMsg (buf, size); |
|
|
|
HandleDatabaseLookupMsg (buf, size); |
|
|
|