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"
|
2014-10-13 00:22:14 +04:00
|
|
|
#include "LeaseSet.h"
|
2014-10-07 04:18:18 +04:00
|
|
|
#include "Garlic.h"
|
2014-10-05 16:54:59 +04:00
|
|
|
#include "Streaming.h"
|
2014-10-22 23:30:25 +04:00
|
|
|
#include "Datagram.h"
|
2014-10-05 16:54:59 +04:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
2014-10-16 20:37:39 +04:00
|
|
|
namespace client
|
2014-10-05 16:54:59 +04:00
|
|
|
{
|
2014-10-22 22:01:23 +04:00
|
|
|
const uint8_t PROTOCOL_TYPE_STREAMING = 6;
|
|
|
|
const uint8_t PROTOCOL_TYPE_DATAGRAM = 17;
|
|
|
|
const uint8_t PROTOCOL_TYPE_RAW = 18;
|
|
|
|
|
2014-10-16 20:37:39 +04:00
|
|
|
class ClientDestination: public i2p::garlic::GarlicDestination
|
2014-10-05 16:54:59 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-10-16 20:37:39 +04:00
|
|
|
ClientDestination (bool isPublic, i2p::data::SigningKeyType sigType);
|
|
|
|
ClientDestination (const std::string& fullPath, bool isPublic);
|
|
|
|
ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
|
|
|
~ClientDestination ();
|
2014-10-05 16:54:59 +04:00
|
|
|
|
2014-10-16 20:37:39 +04:00
|
|
|
virtual void Start ();
|
|
|
|
virtual void Stop ();
|
2014-10-13 19:21:57 +04:00
|
|
|
bool IsRunning () const { return m_IsRunning; };
|
2014-10-16 20:37:39 +04:00
|
|
|
boost::asio::io_service * GetService () { return m_Service; };
|
|
|
|
i2p::tunnel::TunnelPool * GetTunnelPool () { return m_Pool; };
|
2014-10-17 00:36:12 +04:00
|
|
|
bool IsReady () const { return m_LeaseSet && m_LeaseSet->HasNonExpiredLeases (); };
|
2014-10-05 16:54:59 +04:00
|
|
|
|
2014-10-07 22:06:50 +04:00
|
|
|
void ResetCurrentOutboundTunnel () { m_CurrentOutboundTunnel = nullptr; };
|
2014-10-13 00:22:14 +04:00
|
|
|
const i2p::data::LeaseSet * FindLeaseSet (const i2p::data::IdentHash& ident);
|
2014-10-16 20:37:39 +04:00
|
|
|
void SendTunnelDataMsgs (const std::vector<i2p::tunnel::TunnelMessageBlock>& msgs);
|
2014-10-05 16:54:59 +04:00
|
|
|
|
2014-10-22 22:01:23 +04:00
|
|
|
// streaming
|
|
|
|
i2p::stream::StreamingDestination * GetStreamingDestination () const { return m_StreamingDestination; };
|
2014-10-23 05:36:11 +04:00
|
|
|
i2p::stream::Stream * CreateStream (const i2p::data::LeaseSet& remote, int port = 0);
|
2014-11-18 17:33:58 +03:00
|
|
|
void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor);
|
2014-10-22 22:01:23 +04:00
|
|
|
void StopAcceptingStreams ();
|
|
|
|
bool IsAcceptingStreams () const;
|
|
|
|
|
2014-10-23 00:42:26 +04:00
|
|
|
// datagram
|
|
|
|
i2p::datagram::DatagramDestination * GetDatagramDestination () const { return m_DatagramDestination; };
|
2014-10-31 23:44:44 +03:00
|
|
|
i2p::datagram::DatagramDestination * CreateDatagramDestination ();
|
2014-10-23 00:42:26 +04:00
|
|
|
|
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-16 20:37:39 +04:00
|
|
|
|
2014-10-08 05:08:00 +04:00
|
|
|
// implements GarlicDestination
|
|
|
|
const i2p::data::LeaseSet * GetLeaseSet ();
|
2014-10-14 01:45:07 +04:00
|
|
|
void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from);
|
2014-10-08 05:08:00 +04:00
|
|
|
|
2014-10-08 22:17:17 +04:00
|
|
|
// override GarlicDestination
|
|
|
|
void ProcessGarlicMessage (I2NPMessage * msg);
|
|
|
|
void ProcessDeliveryStatusMessage (I2NPMessage * msg);
|
|
|
|
void SetLeaseSetUpdated ();
|
|
|
|
|
2014-10-16 20:37:39 +04:00
|
|
|
// I2CP
|
|
|
|
void HandleDataMessage (const uint8_t * buf, size_t len);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Run ();
|
2014-10-05 16:54:59 +04:00
|
|
|
void UpdateLeaseSet ();
|
2014-10-16 20:37:39 +04:00
|
|
|
void HandleDatabaseStoreMessage (const uint8_t * buf, size_t len);
|
2014-10-05 16:54:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-10-09 18:05:28 +04:00
|
|
|
bool m_IsRunning;
|
|
|
|
std::thread * m_Thread;
|
2014-10-13 20:33:51 +04:00
|
|
|
boost::asio::io_service * m_Service;
|
|
|
|
boost::asio::io_service::work * m_Work;
|
2014-10-05 16:54:59 +04:00
|
|
|
i2p::data::PrivateKeys m_Keys;
|
|
|
|
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
|
2014-10-16 20:37:39 +04:00
|
|
|
std::map<i2p::data::IdentHash, i2p::data::LeaseSet *> m_RemoteLeaseSets;
|
|
|
|
|
2014-10-05 16:54:59 +04:00
|
|
|
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;
|
2014-10-16 20:37:39 +04:00
|
|
|
bool m_IsPublic;
|
|
|
|
|
2014-10-22 19:46:54 +04:00
|
|
|
i2p::stream::StreamingDestination * m_StreamingDestination;
|
2014-10-22 23:30:25 +04:00
|
|
|
i2p::datagram::DatagramDestination * m_DatagramDestination;
|
2014-10-22 19:46:54 +04:00
|
|
|
|
2014-10-16 20:37:39 +04:00
|
|
|
public:
|
2014-10-13 00:22:14 +04:00
|
|
|
|
2014-10-16 20:37:39 +04:00
|
|
|
// for HTTP only
|
|
|
|
int GetNumRemoteLeaseSets () const { return m_RemoteLeaseSets.size (); };
|
|
|
|
};
|
2014-10-22 19:46:54 +04:00
|
|
|
}
|
2014-10-05 16:54:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|