From 070a7fea2c05e5a7d92c657eb3eb4465b44b4860 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 7 Oct 2014 21:47:32 -0400 Subject: [PATCH] DeliveryStatus per garlic destination --- Garlic.cpp | 60 ++++++++++++++++++++++---------------------------- Garlic.h | 12 +++++----- TunnelPool.cpp | 2 +- 3 files changed, 33 insertions(+), 41 deletions(-) diff --git a/Garlic.cpp b/Garlic.cpp index b9520d9d..ec381a3a 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -175,7 +175,7 @@ namespace garlic if (size > 0) // successive? { (*numCloves)++; - routing.DeliveryStatusSent (this, msgID); + m_Owner->DeliveryStatusSent (this, msgID); } else LogPrint ("DeliveryStatus clove was not created"); @@ -450,27 +450,13 @@ namespace garlic return session; } - GarlicRouting routing; - - void GarlicRouting::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID) + void GarlicDestination::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID) { std::unique_lock l(m_CreatedSessionsMutex); m_CreatedSessions[msgID] = session; - } - - void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg) - { - auto pool = msg->from ? msg->from->GetTunnelPool () : nullptr; - if (pool) - pool->GetGarlicDestination ().HandleGarlicMessage (msg); - else - { - LogPrint ("Local destination doesn't exist"); - DeleteI2NPMessage (msg); - } - } + } - void GarlicRouting::HandleDeliveryStatusMessage (I2NPMessage * msg) + void GarlicDestination::HandleDeliveryStatusMessage (I2NPMessage * msg) { I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload (); uint32_t msgID = be32toh (deliveryStatus->msgID); @@ -483,8 +469,22 @@ namespace garlic m_CreatedSessions.erase (it); LogPrint ("Garlic message ", msgID, " acknowledged"); } - } + } DeleteI2NPMessage (msg); + } + + GarlicRouting routing; + + void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg) + { + auto pool = msg->from ? msg->from->GetTunnelPool () : nullptr; + if (pool) + pool->GetGarlicDestination ().HandleGarlicMessage (msg); + else + { + LogPrint ("Local destination doesn't exist"); + DeleteI2NPMessage (msg); + } } void GarlicRouting::Start () @@ -517,21 +517,13 @@ namespace garlic try { I2NPMessage * msg = m_Queue.GetNext (); - if (msg) - { - switch (msg->GetHeader ()->typeID) - { - case eI2NPGarlic: - HandleGarlicMessage (msg); - break; - case eI2NPDeliveryStatus: - HandleDeliveryStatusMessage (msg); - break; - default: - LogPrint ("Garlic: unexpected message type ", msg->GetHeader ()->typeID); - i2p::HandleI2NPMessage (msg); - } - } + if (msg->GetHeader ()->typeID == eI2NPGarlic) + HandleGarlicMessage (msg); + else + { + LogPrint ("Garlic: unexpected message type ", msg->GetHeader ()->typeID); + i2p::HandleI2NPMessage (msg); + } } catch (std::exception& ex) { diff --git a/Garlic.h b/Garlic.h index 0f2087c0..1e2be426 100644 --- a/Garlic.h +++ b/Garlic.h @@ -91,6 +91,9 @@ namespace garlic void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag void HandleGarlicMessage (I2NPMessage * msg); + void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID); + void HandleDeliveryStatusMessage (I2NPMessage * msg); + virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO private: @@ -106,6 +109,9 @@ namespace garlic std::map m_Sessions; // incoming std::map> m_Tags; + // DeliveryStatus + std::mutex m_CreatedSessionsMutex; + std::map m_CreatedSessions; // msgID -> session }; class GarlicRouting @@ -119,22 +125,16 @@ namespace garlic void Stop (); void PostI2NPMsg (I2NPMessage * msg); - void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID); - private: void Run (); void HandleGarlicMessage (I2NPMessage * msg); - void HandleDeliveryStatusMessage (I2NPMessage * msg); private: bool m_IsRunning; std::thread * m_Thread; i2p::util::Queue m_Queue; - - std::mutex m_CreatedSessionsMutex; - std::map m_CreatedSessions; // msgID -> session }; extern GarlicRouting routing; diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 37091206..55e8bc5e 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -221,7 +221,7 @@ namespace tunnel DeleteI2NPMessage (msg); } else - i2p::garlic::routing.PostI2NPMsg (msg); + m_LocalDestination.HandleDeliveryStatusMessage (msg); } const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const