diff --git a/Destination.cpp b/Destination.cpp index f3d27825..0d94de75 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -163,6 +163,26 @@ namespace client } } + bool ClientDestination::SubmitSessionKey (const uint8_t * key, const uint8_t * tag) + { + if (m_Service) + { + uint8_t k[32], t[32]; + memcpy (k, key, 32); + memcpy (t, tag, 32); + m_Service->post ([this,k,t](void) + { + this->AddSessionKey (k, t); + }); + return true; + } + else + { + LogPrint (eLogWarning, "Destination's thread is not running"); + return false; + } + } + void ClientDestination::ProcessGarlicMessage (I2NPMessage * msg) { if (m_Service) diff --git a/Destination.h b/Destination.h index 82c3d1d7..3cfa10e6 100644 --- a/Destination.h +++ b/Destination.h @@ -65,6 +65,7 @@ namespace client void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from); // override GarlicDestination + bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); void ProcessGarlicMessage (I2NPMessage * msg); void ProcessDeliveryStatusMessage (I2NPMessage * msg); void SetLeaseSetUpdated (); diff --git a/Garlic.cpp b/Garlic.cpp index 79c1d747..89b6fbda 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -322,6 +322,12 @@ namespace garlic } } + bool GarlicDestination::SubmitSessionKey (const uint8_t * key, const uint8_t * tag) + { + AddSessionKey (key, tag); + return true; + } + void GarlicDestination::HandleGarlicMessage (I2NPMessage * msg) { uint8_t * buf = msg->GetPayload (); @@ -389,8 +395,8 @@ namespace garlic { if (tagCount*32 > len) { - LogPrint (eLogWarning, "Tag count ", tagCount, " exceeds length ", len); - tagCount = len/32; + LogPrint (eLogError, "Tag count ", tagCount, " exceeds length ", len); + return ; } uint32_t ts = i2p::util::GetSecondsSinceEpoch (); for (int i = 0; i < tagCount; i++) diff --git a/Garlic.h b/Garlic.h index db106b67..88d47280 100644 --- a/Garlic.h +++ b/Garlic.h @@ -110,6 +110,7 @@ namespace garlic I2NPMessage * msg, bool attachLeaseSet = false); void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag + virtual bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); // from different thread void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID); virtual void ProcessGarlicMessage (I2NPMessage * msg); diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 75606295..c75b4d93 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -161,7 +161,7 @@ namespace i2p buf[32] = 1; // 1 tag rnd.GenerateBlock (buf + 33, 32); // tag if (pool) - pool->GetGarlicDestination ().AddSessionKey (buf, buf + 33); // introduce new key-tag to garlic engine + pool->GetGarlicDestination ().SubmitSessionKey (buf, buf + 33); // introduce new key-tag to garlic engine else LogPrint ("Destination for encrypteed reply not specified"); buf += 65;