mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
introduced ClientDestination
This commit is contained in:
parent
14f4bb8656
commit
f516d4c6f2
2 changed files with 264 additions and 214 deletions
101
Destination.h
101
Destination.h
|
@ -12,41 +12,32 @@
|
|||
|
||||
namespace i2p
|
||||
{
|
||||
namespace stream
|
||||
namespace client
|
||||
{
|
||||
class StreamingDestination: public i2p::garlic::GarlicDestination
|
||||
class ClientDestination: public i2p::garlic::GarlicDestination
|
||||
{
|
||||
public:
|
||||
|
||||
StreamingDestination (bool isPublic, i2p::data::SigningKeyType sigType);
|
||||
StreamingDestination (const std::string& fullPath, bool isPublic);
|
||||
StreamingDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
||||
~StreamingDestination ();
|
||||
ClientDestination (bool isPublic, i2p::data::SigningKeyType sigType);
|
||||
ClientDestination (const std::string& fullPath, bool isPublic);
|
||||
ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
||||
~ClientDestination ();
|
||||
|
||||
void Start ();
|
||||
void Stop ();
|
||||
virtual void Start ();
|
||||
virtual void Stop ();
|
||||
bool IsRunning () const { return m_IsRunning; };
|
||||
|
||||
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };
|
||||
boost::asio::io_service * GetService () { return m_Service; };
|
||||
i2p::tunnel::TunnelPool * GetTunnelPool () { 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);
|
||||
void SendTunnelDataMsgs (const std::vector<i2p::tunnel::TunnelMessageBlock>& msgs);
|
||||
void ResetCurrentOutboundTunnel () { m_CurrentOutboundTunnel = nullptr; };
|
||||
const i2p::data::LeaseSet * FindLeaseSet (const i2p::data::IdentHash& ident);
|
||||
// I2CP
|
||||
void HandleDataMessage (const uint8_t * buf, size_t len);
|
||||
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
|
||||
void SendTunnelDataMsgs (const std::vector<i2p::tunnel::TunnelMessageBlock>& msgs);
|
||||
|
||||
// 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; };
|
||||
|
||||
|
||||
// implements GarlicDestination
|
||||
const i2p::data::LeaseSet * GetLeaseSet ();
|
||||
void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from);
|
||||
|
@ -56,12 +47,19 @@ namespace stream
|
|||
void ProcessDeliveryStatusMessage (I2NPMessage * msg);
|
||||
void SetLeaseSetUpdated ();
|
||||
|
||||
private:
|
||||
|
||||
void Run ();
|
||||
Stream * CreateNewIncomingStream ();
|
||||
// I2CP
|
||||
void HandleDataMessage (const uint8_t * buf, size_t len);
|
||||
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void HandleNextPacket (i2p::stream::Packet * packet) = 0; // TODO
|
||||
|
||||
private:
|
||||
|
||||
void Run ();
|
||||
void UpdateLeaseSet ();
|
||||
void HandleDatabaseStoreMessage (const uint8_t * buf, size_t len);
|
||||
void HandleDatabaseStoreMessage (const uint8_t * buf, size_t len);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -69,24 +67,61 @@ namespace stream
|
|||
std::thread * m_Thread;
|
||||
boost::asio::io_service * m_Service;
|
||||
boost::asio::io_service::work * m_Work;
|
||||
std::map<i2p::data::IdentHash, i2p::data::LeaseSet *> m_RemoteLeaseSets;
|
||||
|
||||
std::mutex m_StreamsMutex;
|
||||
std::map<uint32_t, Stream *> m_Streams;
|
||||
i2p::data::PrivateKeys m_Keys;
|
||||
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
|
||||
|
||||
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;
|
||||
bool m_IsPublic;
|
||||
bool m_IsPublic;
|
||||
|
||||
public:
|
||||
|
||||
// for HTTP only
|
||||
int GetNumRemoteLeaseSets () const { return m_RemoteLeaseSets.size (); };
|
||||
};
|
||||
}
|
||||
|
||||
namespace stream
|
||||
{
|
||||
class StreamingDestination: public i2p::client::ClientDestination
|
||||
{
|
||||
public:
|
||||
|
||||
StreamingDestination (bool isPublic, i2p::data::SigningKeyType sigType):
|
||||
ClientDestination (isPublic, sigType) {};
|
||||
StreamingDestination (const std::string& fullPath, bool isPublic):
|
||||
ClientDestination (fullPath, isPublic) {};
|
||||
StreamingDestination (const i2p::data::PrivateKeys& keys, bool isPublic):
|
||||
ClientDestination (keys, isPublic) {};
|
||||
~StreamingDestination () {};
|
||||
|
||||
void Start ();
|
||||
void Stop ();
|
||||
|
||||
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; };
|
||||
|
||||
// ClientDestination
|
||||
void HandleNextPacket (Packet * packet);
|
||||
|
||||
private:
|
||||
|
||||
Stream * CreateNewIncomingStream ();
|
||||
|
||||
private:
|
||||
|
||||
std::mutex m_StreamsMutex;
|
||||
std::map<uint32_t, Stream *> m_Streams;
|
||||
std::function<void (Stream *)> m_Acceptor;
|
||||
|
||||
public:
|
||||
|
||||
// for HTTP only
|
||||
int GetNumRemoteLeaseSets () const { return m_RemoteLeaseSets.size (); };
|
||||
const decltype(m_Streams)& GetStreams () const { return m_Streams; };
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue