From 990906c57fc6014f1ae77d03ed86f5bc9784f30f Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 28 Mar 2022 12:15:40 -0400 Subject: [PATCH] insert garlic tag in destination's thread --- libi2pd/Destination.cpp | 16 ++++++++++++++++ libi2pd/Destination.h | 1 + libi2pd/Garlic.cpp | 7 ++++++- libi2pd/Garlic.h | 3 ++- libi2pd/Tunnel.cpp | 2 +- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index cc06e16d..de2a3ddb 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -339,6 +339,22 @@ namespace client return true; } + void LeaseSetDestination::SubmitECIESx25519Key (const uint8_t * key, uint64_t tag) + { + struct + { + uint8_t k[32]; + uint64_t t; + } data; + memcpy (data.k, key, 32); + data.t = tag; + auto s = shared_from_this (); + m_Service.post ([s,data](void) + { + s->AddECIESx25519Key (data.k, data.t); + }); + } + void LeaseSetDestination::ProcessGarlicMessage (std::shared_ptr msg) { m_Service.post (std::bind (&LeaseSetDestination::HandleGarlicMessage, shared_from_this (), msg)); diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index 33aa301a..4b08ec51 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -138,6 +138,7 @@ namespace client // override GarlicDestination bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); + void SubmitECIESx25519Key (const uint8_t * key, uint64_t tag); void ProcessGarlicMessage (std::shared_ptr msg); void ProcessDeliveryStatusMessage (std::shared_ptr msg); void SetLeaseSetUpdated (); diff --git a/libi2pd/Garlic.cpp b/libi2pd/Garlic.cpp index 03376f9e..ef92c6f5 100644 --- a/libi2pd/Garlic.cpp +++ b/libi2pd/Garlic.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2021, The PurpleI2P Project +* Copyright (c) 2013-2022, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -484,6 +484,11 @@ namespace garlic return true; } + void GarlicDestination::SubmitECIESx25519Key (const uint8_t * key, uint64_t tag) + { + AddECIESx25519Key (key, tag); + } + void GarlicDestination::HandleGarlicMessage (std::shared_ptr msg) { uint8_t * buf = msg->GetPayload (); diff --git a/libi2pd/Garlic.h b/libi2pd/Garlic.h index bf7a5a0e..b926abda 100644 --- a/libi2pd/Garlic.h +++ b/libi2pd/Garlic.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2021, The PurpleI2P Project +* Copyright (c) 2013-2022, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -245,6 +245,7 @@ namespace garlic void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag void AddECIESx25519Key (const uint8_t * key, uint64_t tag); // one tag virtual bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); // from different thread + virtual void SubmitECIESx25519Key (const uint8_t * key, uint64_t tag); // from different thread void DeliveryStatusSent (GarlicRoutingSessionPtr session, uint32_t msgID); uint64_t AddECIESx25519SessionNextTag (ReceiveRatchetTagSetPtr tagset); void AddECIESx25519Session (const uint8_t * staticKey, ECIESX25519AEADRatchetSessionPtr session); diff --git a/libi2pd/Tunnel.cpp b/libi2pd/Tunnel.cpp index 3417cd71..725ff7c9 100644 --- a/libi2pd/Tunnel.cpp +++ b/libi2pd/Tunnel.cpp @@ -114,7 +114,7 @@ namespace tunnel uint8_t key[32]; uint64_t tag = m_Config->GetLastHop ()->GetGarlicKey (key); if (m_Pool && m_Pool->GetLocalDestination ()) - m_Pool->GetLocalDestination ()->AddECIESx25519Key (key, tag); + m_Pool->GetLocalDestination ()->SubmitECIESx25519Key (key, tag); else i2p::context.AddECIESx25519Key (key, tag); }