2014-10-05 16:54:59 +04:00
|
|
|
#ifndef DESTINATION_H__
|
|
|
|
#define DESTINATION_H__
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include "Identity.h"
|
|
|
|
#include "TunnelPool.h"
|
|
|
|
#include "CryptoConst.h"
|
|
|
|
#include "NetDb.h"
|
2014-10-07 04:18:18 +04:00
|
|
|
#include "Garlic.h"
|
2014-10-05 16:54:59 +04:00
|
|
|
#include "Streaming.h"
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace stream
|
|
|
|
{
|
2014-10-07 04:18:18 +04:00
|
|
|
class StreamingDestination: public i2p::garlic::GarlicDestination
|
2014-10-05 16:54:59 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-10-09 18:05:28 +04:00
|
|
|
StreamingDestination (bool isPublic);
|
|
|
|
StreamingDestination (const std::string& fullPath, bool isPublic);
|
|
|
|
StreamingDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
2014-10-05 16:54:59 +04:00
|
|
|
~StreamingDestination ();
|
|
|
|
|
2014-10-09 18:05:28 +04:00
|
|
|
void Start ();
|
|
|
|
void Stop ();
|
|
|
|
|
2014-10-05 16:54:59 +04:00
|
|
|
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };
|
|
|
|
|
|
|
|
Stream * CreateNewOutgoingStream (const i2p::data::LeaseSet& remote);
|
|
|
|
void DeleteStream (Stream * stream);
|
|
|
|
void SetAcceptor (const std::function<void (Stream *)>& acceptor) { m_Acceptor = acceptor; };
|
|
|
|
void ResetAcceptor () { m_Acceptor = nullptr; };
|
|
|
|
bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
|
|
|
|
void HandleNextPacket (Packet * packet);
|
2014-10-07 18:33:17 +04:00
|
|
|
void SendTunnelDataMsgs (const std::vector<i2p::tunnel::TunnelMessageBlock>& msgs);
|
2014-10-07 22:06:50 +04:00
|
|
|
void ResetCurrentOutboundTunnel () { m_CurrentOutboundTunnel = nullptr; };
|
|
|
|
// I2CP
|
|
|
|
void HandleDataMessage (const uint8_t * buf, size_t len);
|
|
|
|
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
|
2014-10-05 16:54:59 +04:00
|
|
|
|
|
|
|
// implements LocalDestination
|
|
|
|
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; };
|
2014-10-12 05:27:55 +04:00
|
|
|
void HandleI2NPMessage (const uint8_t * buf, size_t len);
|
2014-10-05 16:54:59 +04:00
|
|
|
|
2014-10-08 05:08:00 +04:00
|
|
|
// implements GarlicDestination
|
|
|
|
const i2p::data::LeaseSet * GetLeaseSet ();
|
|
|
|
|
2014-10-08 22:17:17 +04:00
|
|
|
// override GarlicDestination
|
|
|
|
void ProcessGarlicMessage (I2NPMessage * msg);
|
|
|
|
void ProcessDeliveryStatusMessage (I2NPMessage * msg);
|
|
|
|
void SetLeaseSetUpdated ();
|
|
|
|
|
2014-10-05 16:54:59 +04:00
|
|
|
private:
|
|
|
|
|
2014-10-09 18:05:28 +04:00
|
|
|
void Run ();
|
2014-10-05 16:54:59 +04:00
|
|
|
Stream * CreateNewIncomingStream ();
|
|
|
|
void UpdateLeaseSet ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-10-09 18:05:28 +04:00
|
|
|
bool m_IsRunning;
|
|
|
|
std::thread * m_Thread;
|
|
|
|
boost::asio::io_service m_Service;
|
|
|
|
boost::asio::io_service::work m_Work;
|
|
|
|
|
2014-10-05 16:54:59 +04:00
|
|
|
std::mutex m_StreamsMutex;
|
|
|
|
std::map<uint32_t, Stream *> m_Streams;
|
|
|
|
i2p::data::PrivateKeys m_Keys;
|
|
|
|
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
|
|
|
|
|
|
|
|
i2p::tunnel::TunnelPool * m_Pool;
|
2014-10-07 18:33:17 +04:00
|
|
|
i2p::tunnel::OutboundTunnel * m_CurrentOutboundTunnel;
|
2014-10-05 16:54:59 +04:00
|
|
|
i2p::data::LeaseSet * m_LeaseSet;
|
|
|
|
bool m_IsPublic;
|
|
|
|
|
|
|
|
std::function<void (Stream *)> m_Acceptor;
|
2014-10-12 02:21:52 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// for HTTP only
|
|
|
|
const decltype(m_Streams)& GetStreams () const { return m_Streams; };
|
2014-10-05 16:54:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class StreamingDestinations
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-10-09 18:05:28 +04:00
|
|
|
StreamingDestinations (): m_SharedLocalDestination (nullptr) {};
|
2014-10-05 16:54:59 +04:00
|
|
|
~StreamingDestinations () {};
|
|
|
|
|
|
|
|
void Start ();
|
|
|
|
void Stop ();
|
|
|
|
|
|
|
|
Stream * CreateClientStream (const i2p::data::LeaseSet& remote);
|
|
|
|
void DeleteStream (Stream * stream);
|
|
|
|
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
|
|
|
StreamingDestination * CreateNewLocalDestination (bool isPublic);
|
|
|
|
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
|
|
|
void DeleteLocalDestination (StreamingDestination * destination);
|
|
|
|
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
|
|
|
StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void LoadLocalDestinations ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
std::mutex m_DestinationsMutex;
|
|
|
|
std::map<i2p::data::IdentHash, StreamingDestination *> m_Destinations;
|
|
|
|
StreamingDestination * m_SharedLocalDestination;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// for HTTP
|
|
|
|
const decltype(m_Destinations)& GetDestinations () const { return m_Destinations; };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Stream * CreateStream (const i2p::data::LeaseSet& remote);
|
|
|
|
void DeleteStream (Stream * stream);
|
|
|
|
void StartStreaming ();
|
|
|
|
void StopStreaming ();
|
|
|
|
StreamingDestination * GetSharedLocalDestination ();
|
|
|
|
StreamingDestination * CreateNewLocalDestination (bool isPublic = true);
|
|
|
|
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true);
|
|
|
|
void DeleteLocalDestination (StreamingDestination * destination);
|
|
|
|
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);
|
|
|
|
StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
|
|
|
// for HTTP
|
|
|
|
const StreamingDestinations& GetLocalDestinations ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|