i2pd/Destination.h

103 lines
3.3 KiB
C
Raw Normal View History

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