|
|
@ -4,6 +4,8 @@ |
|
|
|
#include <string> |
|
|
|
#include <string> |
|
|
|
#include "ElGamal.h" |
|
|
|
#include "ElGamal.h" |
|
|
|
#include "RouterContext.h" |
|
|
|
#include "RouterContext.h" |
|
|
|
|
|
|
|
#include "I2NPProtocol.h" |
|
|
|
|
|
|
|
#include "Tunnel.h" |
|
|
|
#include "Timestamp.h" |
|
|
|
#include "Timestamp.h" |
|
|
|
#include "Streaming.h" |
|
|
|
#include "Streaming.h" |
|
|
|
#include "Garlic.h" |
|
|
|
#include "Garlic.h" |
|
|
@ -65,8 +67,6 @@ namespace garlic |
|
|
|
FillI2NPMessageHeader (m, eI2NPGarlic); |
|
|
|
FillI2NPMessageHeader (m, eI2NPGarlic); |
|
|
|
if (msg) |
|
|
|
if (msg) |
|
|
|
DeleteI2NPMessage (msg); |
|
|
|
DeleteI2NPMessage (msg); |
|
|
|
if (leaseSet) |
|
|
|
|
|
|
|
DeleteI2NPMessage (leaseSet); |
|
|
|
|
|
|
|
return m; |
|
|
|
return m; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -97,17 +97,23 @@ namespace garlic |
|
|
|
size_t GarlicRoutingSession::CreateGarlicPayload (uint8_t * payload, I2NPMessage * msg, I2NPMessage * leaseSet) |
|
|
|
size_t GarlicRoutingSession::CreateGarlicPayload (uint8_t * payload, I2NPMessage * msg, I2NPMessage * leaseSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint64_t ts = i2p::util::GetMillisecondsSinceEpoch () + 5000; // 5 sec
|
|
|
|
uint64_t ts = i2p::util::GetMillisecondsSinceEpoch () + 5000; // 5 sec
|
|
|
|
|
|
|
|
uint32_t msgID = m_Rnd.GenerateWord32 (); |
|
|
|
size_t size = 0; |
|
|
|
size_t size = 0; |
|
|
|
uint8_t * numCloves = payload + size; |
|
|
|
uint8_t * numCloves = payload + size; |
|
|
|
*numCloves = 0; |
|
|
|
*numCloves = 0; |
|
|
|
size++; |
|
|
|
size++; |
|
|
|
|
|
|
|
|
|
|
|
if (leaseSet) // first clove is our leaseSet if presented
|
|
|
|
if (leaseSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// clove is DeliveryStatus is LeaseSet is presented
|
|
|
|
|
|
|
|
size += CreateDeliveryStatusClove (payload + size, msgID); |
|
|
|
|
|
|
|
(*numCloves)++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clove is our leaseSet if presented
|
|
|
|
size += CreateGarlicClove (payload + size, leaseSet, false); |
|
|
|
size += CreateGarlicClove (payload + size, leaseSet, false); |
|
|
|
(*numCloves)++; |
|
|
|
(*numCloves)++; |
|
|
|
} |
|
|
|
} |
|
|
|
if (msg) // next clove message ifself if presented
|
|
|
|
if (msg) // clove message ifself if presented
|
|
|
|
{ |
|
|
|
{ |
|
|
|
size += CreateGarlicClove (payload + size, msg, m_Destination->IsDestination ()); |
|
|
|
size += CreateGarlicClove (payload + size, msg, m_Destination->IsDestination ()); |
|
|
|
(*numCloves)++; |
|
|
|
(*numCloves)++; |
|
|
@ -115,7 +121,7 @@ namespace garlic |
|
|
|
|
|
|
|
|
|
|
|
memset (payload + size, 0, 3); // certificate of message
|
|
|
|
memset (payload + size, 0, 3); // certificate of message
|
|
|
|
size += 3; |
|
|
|
size += 3; |
|
|
|
*(uint32_t *)(payload + size) = htobe32 (m_Rnd.GenerateWord32 ()); // MessageID
|
|
|
|
*(uint32_t *)(payload + size) = htobe32 (msgID); // MessageID
|
|
|
|
size += 4; |
|
|
|
size += 4; |
|
|
|
*(uint64_t *)(payload + size) = htobe64 (ts); // Expiration of message
|
|
|
|
*(uint64_t *)(payload + size) = htobe64 (ts); // Expiration of message
|
|
|
|
size += 8; |
|
|
|
size += 8; |
|
|
@ -150,6 +156,42 @@ namespace garlic |
|
|
|
return size; |
|
|
|
return size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t GarlicRoutingSession::CreateDeliveryStatusClove (uint8_t * buf, uint32_t msgID) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
size_t size = 0; |
|
|
|
|
|
|
|
auto tunnel = i2p::tunnel::tunnels.GetNextInboundTunnel (); |
|
|
|
|
|
|
|
if (tunnel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
buf[size] = eGarlicDeliveryTypeTunnel << 5; // delivery instructions flag tunnel
|
|
|
|
|
|
|
|
size++; |
|
|
|
|
|
|
|
*(uint32_t *)(buf + size) = htobe32 (tunnel->GetNextTunnelID ()); // tunnelID
|
|
|
|
|
|
|
|
size += 4; |
|
|
|
|
|
|
|
memcpy (buf + size, tunnel->GetNextIdentHash (), 32); // To Hash
|
|
|
|
|
|
|
|
size += 32; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint ("No reply tunnels for garlic DeliveryStatus found"); |
|
|
|
|
|
|
|
buf[size] = 0;// delivery instructions flag local
|
|
|
|
|
|
|
|
size++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I2NPMessage * msg = CreateDeliveryStatusMsg (msgID); |
|
|
|
|
|
|
|
memcpy (buf + size, msg->GetBuffer (), msg->GetLength ()); |
|
|
|
|
|
|
|
size += msg->GetLength (); |
|
|
|
|
|
|
|
DeleteI2NPMessage (msg); |
|
|
|
|
|
|
|
uint64_t ts = i2p::util::GetMillisecondsSinceEpoch () + 5000; // 5 sec
|
|
|
|
|
|
|
|
*(uint32_t *)(buf + size) = htobe32 (m_Rnd.GenerateWord32 ()); // CloveID
|
|
|
|
|
|
|
|
size += 4; |
|
|
|
|
|
|
|
*(uint64_t *)(buf + size) = htobe64 (ts); // Expiration of clove
|
|
|
|
|
|
|
|
size += 8; |
|
|
|
|
|
|
|
memset (buf + size, 0, 3); // certificate of clove
|
|
|
|
|
|
|
|
size += 3; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return size; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GarlicRouting routing; |
|
|
|
GarlicRouting routing; |
|
|
|
GarlicRouting::GarlicRouting () |
|
|
|
GarlicRouting::GarlicRouting () |
|
|
|
{ |
|
|
|
{ |
|
|
|