mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-07 11:54:16 +00:00
multiple local destinations
This commit is contained in:
parent
a7406e03ab
commit
e50454d92e
10
Identity.h
10
Identity.h
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <string>
|
||||||
|
#include "base64.h"
|
||||||
#include "ElGamal.h"
|
#include "ElGamal.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
@ -35,6 +37,14 @@ namespace data
|
|||||||
bool operator== (const Tag<sz>& other) const { return !memcmp (m_Buf, other.m_Buf, sz); };
|
bool operator== (const Tag<sz>& other) const { return !memcmp (m_Buf, other.m_Buf, sz); };
|
||||||
bool operator< (const Tag<sz>& other) const { return memcmp (m_Buf, other.m_Buf, sz) < 0; };
|
bool operator< (const Tag<sz>& 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:
|
private:
|
||||||
|
|
||||||
union // 8 bytes alignment
|
union // 8 bytes alignment
|
||||||
|
@ -464,15 +464,21 @@ namespace stream
|
|||||||
void StreamingDestinations::Start ()
|
void StreamingDestinations::Start ()
|
||||||
{
|
{
|
||||||
if (!m_SharedLocalDestination)
|
if (!m_SharedLocalDestination)
|
||||||
|
{
|
||||||
m_SharedLocalDestination = new StreamingDestination ();
|
m_SharedLocalDestination = new StreamingDestination ();
|
||||||
|
m_Destinations[m_SharedLocalDestination->GetIdentHash ()] = m_SharedLocalDestination;
|
||||||
|
}
|
||||||
|
|
||||||
m_IsRunning = true;
|
m_IsRunning = true;
|
||||||
m_Thread = new std::thread (std::bind (&StreamingDestinations::Run, this));
|
m_Thread = new std::thread (std::bind (&StreamingDestinations::Run, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamingDestinations::Stop ()
|
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_IsRunning = false;
|
||||||
m_Service.stop ();
|
m_Service.stop ();
|
||||||
@ -510,9 +516,14 @@ namespace stream
|
|||||||
|
|
||||||
void StreamingDestinations::PostNextPacket (i2p::data::IdentHash destination, Packet * packet)
|
void StreamingDestinations::PostNextPacket (i2p::data::IdentHash destination, Packet * packet)
|
||||||
{
|
{
|
||||||
// TODO: we have onle one destination, might be more
|
auto it = m_Destinations.find (destination);
|
||||||
if (m_SharedLocalDestination)
|
if (it != m_Destinations.end ())
|
||||||
m_SharedLocalDestination->HandleNextPacket (packet);
|
it->second->HandleNextPacket (packet);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint ("Local destination ", destination.ToBase64 (), " not found");
|
||||||
|
delete packet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream * CreateStream (const i2p::data::LeaseSet& remote)
|
Stream * CreateStream (const i2p::data::LeaseSet& remote)
|
||||||
|
@ -184,6 +184,7 @@ namespace stream
|
|||||||
boost::asio::io_service m_Service;
|
boost::asio::io_service m_Service;
|
||||||
boost::asio::io_service::work m_Work;
|
boost::asio::io_service::work m_Work;
|
||||||
|
|
||||||
|
std::map<i2p::data::IdentHash, StreamingDestination *> m_Destinations;
|
||||||
StreamingDestination * m_SharedLocalDestination;
|
StreamingDestination * m_SharedLocalDestination;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user