From 375fceb530e4937e01c5dcc62b228c2993240cb2 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 8 Oct 2014 14:17:17 -0400 Subject: [PATCH] moved garlic decryption to streaming thread --- Destination.cpp | 13 +++++++++++-- Destination.h | 6 +++++- Garlic.cpp | 15 ++++++++++++--- Garlic.h | 14 +++++++++----- I2NPProtocol.cpp | 6 +++--- TunnelPool.cpp | 2 +- 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index 751d885f..a7dfcf3c 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -187,8 +187,7 @@ namespace stream if (uncompressed->len <= MAX_PACKET_SIZE) { decompressor.Get (uncompressed->buf, uncompressed->len); - // then forward to streaming thread - m_Service.post (boost::bind (&StreamingDestination::HandleNextPacket, this, uncompressed)); + HandleNextPacket (uncompressed); } else { @@ -232,6 +231,16 @@ namespace stream i2p::data::netdb.PublishLeaseSet (m_LeaseSet, m_Pool); } + void StreamingDestination::ProcessGarlicMessage (I2NPMessage * msg) + { + m_Service.post (boost::bind (&StreamingDestination::HandleGarlicMessage, this, msg)); + } + + void StreamingDestination::ProcessDeliveryStatusMessage (I2NPMessage * msg) + { + m_Service.post (boost::bind (&StreamingDestination::HandleDeliveryStatusMessage, this, msg)); + } + StreamingDestinations destinations; void StreamingDestinations::Start () { diff --git a/Destination.h b/Destination.h index aadb8c37..9de28b4b 100644 --- a/Destination.h +++ b/Destination.h @@ -41,11 +41,15 @@ namespace stream const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; }; const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; - void SetLeaseSetUpdated (); // implements GarlicDestination const i2p::data::LeaseSet * GetLeaseSet (); + // override GarlicDestination + void ProcessGarlicMessage (I2NPMessage * msg); + void ProcessDeliveryStatusMessage (I2NPMessage * msg); + void SetLeaseSetUpdated (); + private: Stream * CreateNewIncomingStream (); diff --git a/Garlic.cpp b/Garlic.cpp index 9b9c0a23..b238b74f 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -454,7 +454,6 @@ namespace garlic void GarlicDestination::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID) { - std::unique_lock l(m_CreatedSessionsMutex); m_CreatedSessions[msgID] = session; } @@ -463,7 +462,6 @@ namespace garlic I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload (); uint32_t msgID = be32toh (deliveryStatus->msgID); { - std::unique_lock l(m_CreatedSessionsMutex); auto it = m_CreatedSessions.find (msgID); if (it != m_CreatedSessions.end ()) { @@ -477,9 +475,20 @@ namespace garlic void GarlicDestination::SetLeaseSetUpdated () { - std::unique_lock l(m_CreatedSessionsMutex); + std::unique_lock l(m_SessionsMutex); for (auto it: m_Sessions) it.second->SetLeaseSetUpdated (); } + + void GarlicDestination::ProcessGarlicMessage (I2NPMessage * msg) + { + HandleGarlicMessage (msg); + } + + void GarlicDestination::ProcessDeliveryStatusMessage (I2NPMessage * msg) + { + HandleDeliveryStatusMessage (msg); + } + } } diff --git a/Garlic.h b/Garlic.h index 33739d8a..8986b82b 100644 --- a/Garlic.h +++ b/Garlic.h @@ -92,14 +92,19 @@ namespace garlic I2NPMessage * msg, bool attachLeaseSet = false); 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 void ProcessGarlicMessage (I2NPMessage * msg); + virtual void ProcessDeliveryStatusMessage (I2NPMessage * msg); virtual void SetLeaseSetUpdated (); + virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO - + + protected: + + void HandleGarlicMessage (I2NPMessage * msg); + void HandleDeliveryStatusMessage (I2NPMessage * msg); + private: void HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr decryption, @@ -114,7 +119,6 @@ namespace garlic // incoming std::map> m_Tags; // DeliveryStatus - std::mutex m_CreatedSessionsMutex; std::map m_CreatedSessions; // msgID -> session }; } diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 804a7184..a48d4f2d 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -562,9 +562,9 @@ namespace i2p case eI2NPGarlic: LogPrint ("Garlic"); if (msg->from && msg->from->GetTunnelPool ()) - msg->from->GetTunnelPool ()->GetGarlicDestination ().HandleGarlicMessage (msg); + msg->from->GetTunnelPool ()->GetGarlicDestination ().ProcessGarlicMessage (msg); else - i2p::context.HandleGarlicMessage (msg); + i2p::context.ProcessGarlicMessage (msg); break; case eI2NPDatabaseStore: case eI2NPDatabaseSearchReply: @@ -577,7 +577,7 @@ namespace i2p if (msg->from && msg->from->GetTunnelPool ()) msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg); else - i2p::context.HandleDeliveryStatusMessage (msg); + i2p::context.ProcessDeliveryStatusMessage (msg); break; default: HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 55e8bc5e..a82e8934 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -221,7 +221,7 @@ namespace tunnel DeleteI2NPMessage (msg); } else - m_LocalDestination.HandleDeliveryStatusMessage (msg); + m_LocalDestination.ProcessDeliveryStatusMessage (msg); } const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const