From e50454d92e445b7eb34a0bf3662a67215affd8d2 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 11 Jul 2014 15:39:38 -0400 Subject: [PATCH] multiple local destinations --- Identity.h | 10 ++++++++++ Streaming.cpp | 21 ++++++++++++++++----- Streaming.h | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Identity.h b/Identity.h index 655c594a..6345a848 100644 --- a/Identity.h +++ b/Identity.h @@ -3,6 +3,8 @@ #include #include +#include +#include "base64.h" #include "ElGamal.h" namespace i2p @@ -35,6 +37,14 @@ namespace data bool operator== (const Tag& other) const { return !memcmp (m_Buf, other.m_Buf, sz); }; bool operator< (const Tag& other) const { return memcmp (m_Buf, other.m_Buf, sz) < 0; }; + std::string ToBase64 () const + { + char str[sz*2]; + int l = i2p::data::ByteStreamToBase64 (m_Buf, sz, str, sz*2); + str[l] = 0; + return std::string (str); + } + private: union // 8 bytes alignment diff --git a/Streaming.cpp b/Streaming.cpp index 7d7d38f3..ae9e9caf 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -464,15 +464,21 @@ namespace stream void StreamingDestinations::Start () { if (!m_SharedLocalDestination) + { m_SharedLocalDestination = new StreamingDestination (); - + m_Destinations[m_SharedLocalDestination->GetIdentHash ()] = m_SharedLocalDestination; + } + m_IsRunning = true; m_Thread = new std::thread (std::bind (&StreamingDestinations::Run, this)); } void StreamingDestinations::Stop () { - delete m_SharedLocalDestination; + for (auto it: m_Destinations) + delete it.second; + m_Destinations.clear (); + m_SharedLocalDestination = 0; // deleted through m_Destination m_IsRunning = false; m_Service.stop (); @@ -510,9 +516,14 @@ namespace stream void StreamingDestinations::PostNextPacket (i2p::data::IdentHash destination, Packet * packet) { - // TODO: we have onle one destination, might be more - if (m_SharedLocalDestination) - m_SharedLocalDestination->HandleNextPacket (packet); + auto it = m_Destinations.find (destination); + if (it != m_Destinations.end ()) + it->second->HandleNextPacket (packet); + else + { + LogPrint ("Local destination ", destination.ToBase64 (), " not found"); + delete packet; + } } Stream * CreateStream (const i2p::data::LeaseSet& remote) diff --git a/Streaming.h b/Streaming.h index 5b7fa413..abedddeb 100644 --- a/Streaming.h +++ b/Streaming.h @@ -184,6 +184,7 @@ namespace stream boost::asio::io_service m_Service; boost::asio::io_service::work m_Work; + std::map m_Destinations; StreamingDestination * m_SharedLocalDestination; };