From 296b2d7372211cde47934b93f5c8c9744eb3d23c Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 8 Oct 2014 07:55:46 -0400 Subject: [PATCH] exclude garlic thread --- Daemon.cpp | 4 ---- Garlic.cpp | 59 ------------------------------------------------ Garlic.h | 25 -------------------- I2NPProtocol.cpp | 7 ++++-- 4 files changed, 5 insertions(+), 90 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index b23eab10..0fcf6c39 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -111,8 +111,6 @@ namespace i2p LogPrint("Transports started"); i2p::tunnel::tunnels.Start(); LogPrint("Tunnels started"); - i2p::garlic::routing.Start(); - LogPrint("Routing started"); i2p::stream::StartStreaming(); LogPrint("Streaming started"); @@ -164,8 +162,6 @@ namespace i2p LogPrint("SOCKS Proxy stoped"); i2p::stream::StopStreaming(); LogPrint("Streaming stoped"); - i2p::garlic::routing.Stop(); - LogPrint("Routing stoped"); i2p::tunnel::tunnels.Stop(); LogPrint("Tunnels stoped"); i2p::transports.Stop(); diff --git a/Garlic.cpp b/Garlic.cpp index ec381a3a..b89bf84a 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -472,64 +472,5 @@ namespace garlic } 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 () - { - m_IsRunning = true; - m_Thread = new std::thread (std::bind (&GarlicRouting::Run, this)); - } - - void GarlicRouting::Stop () - { - m_IsRunning = false; - m_Queue.WakeUp (); - if (m_Thread) - { - m_Thread->join (); - delete m_Thread; - m_Thread = 0; - } - } - - void GarlicRouting::PostI2NPMsg (I2NPMessage * msg) - { - if (msg) m_Queue.Put (msg); - } - - void GarlicRouting::Run () - { - while (m_IsRunning) - { - try - { - I2NPMessage * msg = m_Queue.GetNext (); - if (msg->GetHeader ()->typeID == eI2NPGarlic) - HandleGarlicMessage (msg); - else - { - LogPrint ("Garlic: unexpected message type ", msg->GetHeader ()->typeID); - i2p::HandleI2NPMessage (msg); - } - } - catch (std::exception& ex) - { - LogPrint ("GarlicRouting: ", ex.what ()); - } - } - } } } diff --git a/Garlic.h b/Garlic.h index 1e2be426..2767b2f2 100644 --- a/Garlic.h +++ b/Garlic.h @@ -113,31 +113,6 @@ namespace garlic std::mutex m_CreatedSessionsMutex; std::map m_CreatedSessions; // msgID -> session }; - - class GarlicRouting - { - public: - - GarlicRouting (): m_IsRunning (false), m_Thread (nullptr) {}; - ~GarlicRouting () {}; - - void Start (); - void Stop (); - void PostI2NPMsg (I2NPMessage * msg); - - private: - - void Run (); - void HandleGarlicMessage (I2NPMessage * msg); - - private: - - bool m_IsRunning; - std::thread * m_Thread; - i2p::util::Queue m_Queue; - }; - - extern GarlicRouting routing; } } diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 1e18b783..804a7184 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -561,7 +561,10 @@ namespace i2p break; case eI2NPGarlic: LogPrint ("Garlic"); - i2p::garlic::routing.PostI2NPMsg (msg); + if (msg->from && msg->from->GetTunnelPool ()) + msg->from->GetTunnelPool ()->GetGarlicDestination ().HandleGarlicMessage (msg); + else + i2p::context.HandleGarlicMessage (msg); break; case eI2NPDatabaseStore: case eI2NPDatabaseSearchReply: @@ -574,7 +577,7 @@ namespace i2p if (msg->from && msg->from->GetTunnelPool ()) msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg); else - DeleteI2NPMessage (msg); + i2p::context.HandleDeliveryStatusMessage (msg); break; default: HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());