2020-05-22 13:18:41 +00:00
|
|
|
/*
|
2023-04-12 19:28:15 +00:00
|
|
|
* Copyright (c) 2013-2023, The PurpleI2P Project
|
2020-05-22 13:18:41 +00:00
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2014-10-05 12:54:59 +00:00
|
|
|
#ifndef DESTINATION_H__
|
|
|
|
#define DESTINATION_H__
|
|
|
|
|
2020-04-14 23:12:44 +00:00
|
|
|
#include <string.h>
|
2014-10-05 12:54:59 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
2014-11-23 16:33:58 +00:00
|
|
|
#include <memory>
|
2014-11-30 15:51:22 +00:00
|
|
|
#include <map>
|
2023-04-21 18:54:54 +00:00
|
|
|
#include <unordered_map>
|
2014-12-25 21:47:15 +00:00
|
|
|
#include <set>
|
2014-11-30 15:51:22 +00:00
|
|
|
#include <string>
|
2014-12-27 00:09:44 +00:00
|
|
|
#include <functional>
|
2014-12-25 21:47:15 +00:00
|
|
|
#include <boost/asio.hpp>
|
2014-10-05 12:54:59 +00:00
|
|
|
#include "Identity.h"
|
|
|
|
#include "TunnelPool.h"
|
2015-11-03 14:15:49 +00:00
|
|
|
#include "Crypto.h"
|
2014-10-12 20:22:14 +00:00
|
|
|
#include "LeaseSet.h"
|
2014-10-07 00:18:18 +00:00
|
|
|
#include "Garlic.h"
|
2017-04-22 00:04:16 +00:00
|
|
|
#include "NetDb.hpp"
|
2014-10-05 12:54:59 +00:00
|
|
|
#include "Streaming.h"
|
2014-10-22 19:30:25 +00:00
|
|
|
#include "Datagram.h"
|
2020-02-02 23:58:58 +00:00
|
|
|
#include "util.h"
|
2014-10-05 12:54:59 +00:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
2014-10-16 16:37:39 +00:00
|
|
|
namespace client
|
2014-10-05 12:54:59 +00:00
|
|
|
{
|
2014-10-22 18:01:23 +00:00
|
|
|
const uint8_t PROTOCOL_TYPE_STREAMING = 6;
|
|
|
|
const uint8_t PROTOCOL_TYPE_DATAGRAM = 17;
|
2017-04-08 16:51:35 +00:00
|
|
|
const uint8_t PROTOCOL_TYPE_RAW = 18;
|
2014-11-28 18:01:35 +00:00
|
|
|
const int PUBLISH_CONFIRMATION_TIMEOUT = 5; // in seconds
|
2017-12-07 13:26:28 +00:00
|
|
|
const int PUBLISH_VERIFICATION_TIMEOUT = 10; // in seconds after successful publish
|
2017-04-08 16:51:35 +00:00
|
|
|
const int PUBLISH_MIN_INTERVAL = 20; // in seconds
|
|
|
|
const int PUBLISH_REGULAR_VERIFICATION_INTERNAL = 100; // in seconds periodically
|
2014-12-25 21:47:15 +00:00
|
|
|
const int LEASESET_REQUEST_TIMEOUT = 5; // in seconds
|
|
|
|
const int MAX_LEASESET_REQUEST_TIMEOUT = 40; // in seconds
|
2017-04-08 16:51:35 +00:00
|
|
|
const int DESTINATION_CLEANUP_TIMEOUT = 3; // in minutes
|
2015-12-17 07:58:09 +00:00
|
|
|
const unsigned int MAX_NUM_FLOODFILLS_PER_REQUEST = 7;
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2014-11-30 15:51:22 +00:00
|
|
|
// I2CP
|
|
|
|
const char I2CP_PARAM_INBOUND_TUNNEL_LENGTH[] = "inbound.length";
|
|
|
|
const int DEFAULT_INBOUND_TUNNEL_LENGTH = 3;
|
|
|
|
const char I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH[] = "outbound.length";
|
|
|
|
const int DEFAULT_OUTBOUND_TUNNEL_LENGTH = 3;
|
2015-05-05 16:32:13 +00:00
|
|
|
const char I2CP_PARAM_INBOUND_TUNNELS_QUANTITY[] = "inbound.quantity";
|
|
|
|
const int DEFAULT_INBOUND_TUNNELS_QUANTITY = 5;
|
|
|
|
const char I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY[] = "outbound.quantity";
|
|
|
|
const int DEFAULT_OUTBOUND_TUNNELS_QUANTITY = 5;
|
2022-03-08 03:20:11 +00:00
|
|
|
const char I2CP_PARAM_INBOUND_TUNNELS_LENGTH_VARIANCE[] = "inbound.lengthVariance";
|
|
|
|
const int DEFAULT_INBOUND_TUNNELS_LENGTH_VARIANCE = 0;
|
|
|
|
const char I2CP_PARAM_OUTBOUND_TUNNELS_LENGTH_VARIANCE[] = "outbound.lengthVariance";
|
|
|
|
const int DEFAULT_OUTBOUND_TUNNELS_LENGTH_VARIANCE = 0;
|
2015-06-10 19:32:55 +00:00
|
|
|
const char I2CP_PARAM_EXPLICIT_PEERS[] = "explicitPeers";
|
2015-01-01 23:56:26 +00:00
|
|
|
const int STREAM_REQUEST_TIMEOUT = 60; //in seconds
|
2016-01-24 01:52:21 +00:00
|
|
|
const char I2CP_PARAM_TAGS_TO_SEND[] = "crypto.tagsToSend";
|
|
|
|
const int DEFAULT_TAGS_TO_SEND = 40;
|
2020-06-13 00:42:54 +00:00
|
|
|
const char I2CP_PARAM_RATCHET_INBOUND_TAGS[] = "crypto.ratchet.inboundTags";
|
|
|
|
const char I2CP_PARAM_RATCHET_OUTBOUND_TAGS[] = "crypto.ratchet.outboundTags"; // not used yet
|
2017-10-04 16:27:08 +00:00
|
|
|
const char I2CP_PARAM_INBOUND_NICKNAME[] = "inbound.nickname";
|
2017-12-20 16:38:35 +00:00
|
|
|
const char I2CP_PARAM_OUTBOUND_NICKNAME[] = "outbound.nickname";
|
2021-06-04 22:28:30 +00:00
|
|
|
const char I2CP_PARAM_DONT_PUBLISH_LEASESET[] = "i2cp.dontPublishLeaseSet";
|
2019-01-11 18:58:02 +00:00
|
|
|
const char I2CP_PARAM_LEASESET_TYPE[] = "i2cp.leaseSetType";
|
2021-05-23 18:28:10 +00:00
|
|
|
const int DEFAULT_LEASESET_TYPE = 3;
|
2019-01-15 20:43:21 +00:00
|
|
|
const char I2CP_PARAM_LEASESET_ENCRYPTION_TYPE[] = "i2cp.leaseSetEncType";
|
2019-06-07 18:51:08 +00:00
|
|
|
const char I2CP_PARAM_LEASESET_PRIV_KEY[] = "i2cp.leaseSetPrivKey"; // PSK decryption key, base64
|
2019-07-13 00:58:17 +00:00
|
|
|
const char I2CP_PARAM_LEASESET_AUTH_TYPE[] = "i2cp.leaseSetAuthType";
|
|
|
|
const char I2CP_PARAM_LEASESET_CLIENT_DH[] = "i2cp.leaseSetClient.dh"; // group of i2cp.leaseSetClient.dh.nnn
|
2021-11-27 20:30:35 +00:00
|
|
|
const char I2CP_PARAM_LEASESET_CLIENT_PSK[] = "i2cp.leaseSetClient.psk"; // group of i2cp.leaseSetClient.psk.nnn
|
|
|
|
|
2016-11-15 15:20:09 +00:00
|
|
|
// latency
|
|
|
|
const char I2CP_PARAM_MIN_TUNNEL_LATENCY[] = "latency.min";
|
|
|
|
const int DEFAULT_MIN_TUNNEL_LATENCY = 0;
|
|
|
|
const char I2CP_PARAM_MAX_TUNNEL_LATENCY[] = "latency.max";
|
|
|
|
const int DEFAULT_MAX_TUNNEL_LATENCY = 0;
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2017-11-24 20:37:17 +00:00
|
|
|
// streaming
|
|
|
|
const char I2CP_PARAM_STREAMING_INITIAL_ACK_DELAY[] = "i2p.streaming.initialAckDelay";
|
|
|
|
const int DEFAULT_INITIAL_ACK_DELAY = 200; // milliseconds
|
2020-09-30 21:12:28 +00:00
|
|
|
const char I2CP_PARAM_STREAMING_ANSWER_PINGS[] = "i2p.streaming.answerPings";
|
2021-11-27 20:30:35 +00:00
|
|
|
const int DEFAULT_ANSWER_PINGS = true;
|
2017-11-24 20:37:17 +00:00
|
|
|
|
2015-01-07 19:44:24 +00:00
|
|
|
typedef std::function<void (std::shared_ptr<i2p::stream::Stream> stream)> StreamRequestComplete;
|
|
|
|
|
2016-05-23 14:33:01 +00:00
|
|
|
class LeaseSetDestination: public i2p::garlic::GarlicDestination,
|
|
|
|
public std::enable_shared_from_this<LeaseSetDestination>
|
2014-10-05 12:54:59 +00:00
|
|
|
{
|
2015-04-07 16:02:25 +00:00
|
|
|
typedef std::function<void (std::shared_ptr<i2p::data::LeaseSet> leaseSet)> RequestComplete;
|
|
|
|
// leaseSet = nullptr means not found
|
2014-12-25 21:47:15 +00:00
|
|
|
struct LeaseSetRequest
|
|
|
|
{
|
|
|
|
LeaseSetRequest (boost::asio::io_service& service): requestTime (0), requestTimeoutTimer (service) {};
|
|
|
|
std::set<i2p::data::IdentHash> excluded;
|
|
|
|
uint64_t requestTime;
|
|
|
|
boost::asio::deadline_timer requestTimeoutTimer;
|
2016-11-17 03:28:13 +00:00
|
|
|
std::list<RequestComplete> requestComplete;
|
2016-02-26 21:17:29 +00:00
|
|
|
std::shared_ptr<i2p::tunnel::OutboundTunnel> outboundTunnel;
|
|
|
|
std::shared_ptr<i2p::tunnel::InboundTunnel> replyTunnel;
|
2019-03-22 19:32:13 +00:00
|
|
|
std::shared_ptr<const i2p::data::BlindedPublicKey> requestedBlindedKey; // for encrypted LeaseSet2 only
|
2016-11-17 03:28:13 +00:00
|
|
|
|
|
|
|
void Complete (std::shared_ptr<i2p::data::LeaseSet> ls)
|
|
|
|
{
|
|
|
|
for (auto& it: requestComplete) it (ls);
|
|
|
|
requestComplete.clear ();
|
2017-04-08 16:51:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-05 12:54:59 +00:00
|
|
|
public:
|
|
|
|
|
2020-02-02 23:58:58 +00:00
|
|
|
LeaseSetDestination (boost::asio::io_service& service, bool isPublic, const std::map<std::string, std::string> * params = nullptr);
|
2017-04-08 16:51:35 +00:00
|
|
|
~LeaseSetDestination ();
|
2017-10-04 16:27:08 +00:00
|
|
|
const std::string& GetNickname () const { return m_Nickname; };
|
2020-02-04 16:48:56 +00:00
|
|
|
boost::asio::io_service& GetService () { return m_Service; };
|
2014-10-05 12:54:59 +00:00
|
|
|
|
2020-02-02 23:58:58 +00:00
|
|
|
virtual void Start ();
|
|
|
|
virtual void Stop ();
|
2018-01-02 16:34:58 +00:00
|
|
|
|
|
|
|
/** i2cp reconfigure */
|
|
|
|
virtual bool Reconfigure(std::map<std::string, std::string> i2cpOpts);
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2017-04-08 16:51:35 +00:00
|
|
|
std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () { return m_Pool; };
|
2016-02-08 00:45:06 +00:00
|
|
|
bool IsReady () const { return m_LeaseSet && !m_LeaseSet->IsExpired () && m_Pool->GetOutboundTunnels ().size () > 0; };
|
2019-03-27 20:04:46 +00:00
|
|
|
std::shared_ptr<i2p::data::LeaseSet> FindLeaseSet (const i2p::data::IdentHash& ident);
|
2014-12-27 00:09:44 +00:00
|
|
|
bool RequestDestination (const i2p::data::IdentHash& dest, RequestComplete requestComplete = nullptr);
|
2020-03-01 10:25:50 +00:00
|
|
|
bool RequestDestinationWithEncryptedLeaseSet (std::shared_ptr<const i2p::data::BlindedPublicKey> dest, RequestComplete requestComplete = nullptr);
|
2017-04-08 16:51:35 +00:00
|
|
|
void CancelDestinationRequest (const i2p::data::IdentHash& dest, bool notify = true);
|
2019-03-27 20:04:46 +00:00
|
|
|
void CancelDestinationRequestWithEncryptedLeaseSet (std::shared_ptr<const i2p::data::BlindedPublicKey> dest, bool notify = true);
|
2016-05-26 19:53:32 +00:00
|
|
|
|
2014-10-08 01:08:00 +00:00
|
|
|
// implements GarlicDestination
|
2016-05-25 19:10:28 +00:00
|
|
|
std::shared_ptr<const i2p::data::LocalLeaseSet> GetLeaseSet ();
|
2015-04-05 16:54:15 +00:00
|
|
|
std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () const { return m_Pool; }
|
2014-10-08 01:08:00 +00:00
|
|
|
|
2014-10-08 18:17:17 +00:00
|
|
|
// override GarlicDestination
|
2014-12-08 20:36:00 +00:00
|
|
|
bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag);
|
2022-03-28 16:15:40 +00:00
|
|
|
void SubmitECIESx25519Key (const uint8_t * key, uint64_t tag);
|
2015-06-16 14:14:14 +00:00
|
|
|
void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
|
2017-04-08 16:51:35 +00:00
|
|
|
void ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
|
2014-10-08 18:17:17 +00:00
|
|
|
void SetLeaseSetUpdated ();
|
|
|
|
|
2021-03-09 22:48:42 +00:00
|
|
|
bool IsPublic () const { return m_IsPublic; };
|
2021-11-27 20:30:35 +00:00
|
|
|
void SetPublic (bool pub) { m_IsPublic = pub; };
|
2021-03-09 22:48:42 +00:00
|
|
|
|
2016-05-23 18:31:22 +00:00
|
|
|
protected:
|
2014-10-16 16:37:39 +00:00
|
|
|
|
2020-01-06 20:31:20 +00:00
|
|
|
// implements GarlicDestination
|
2020-01-07 20:20:55 +00:00
|
|
|
void HandleI2NPMessage (const uint8_t * buf, size_t len);
|
2021-07-21 02:00:06 +00:00
|
|
|
bool HandleCloveI2NPMessage (I2NPMessageType typeID, const uint8_t * payload, size_t len, uint32_t msgID);
|
2020-01-06 20:31:20 +00:00
|
|
|
|
2019-03-10 13:22:42 +00:00
|
|
|
void SetLeaseSet (std::shared_ptr<const i2p::data::LocalLeaseSet> newLeaseSet);
|
2019-01-11 18:58:02 +00:00
|
|
|
int GetLeaseSetType () const { return m_LeaseSetType; };
|
2019-02-12 19:56:39 +00:00
|
|
|
void SetLeaseSetType (int leaseSetType) { m_LeaseSetType = leaseSetType; };
|
2019-09-06 15:02:19 +00:00
|
|
|
int GetAuthType () const { return m_AuthType; };
|
2016-09-08 14:16:42 +00:00
|
|
|
virtual void CleanupDestination () {}; // additional clean up in derived classes
|
2016-05-23 18:31:22 +00:00
|
|
|
// I2CP
|
|
|
|
virtual void HandleDataMessage (const uint8_t * buf, size_t len) = 0;
|
2021-04-01 17:37:21 +00:00
|
|
|
virtual void CreateNewLeaseSet (const std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> >& tunnels) = 0;
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2014-10-16 16:37:39 +00:00
|
|
|
private:
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2014-10-05 12:54:59 +00:00
|
|
|
void UpdateLeaseSet ();
|
2019-03-10 13:22:42 +00:00
|
|
|
std::shared_ptr<const i2p::data::LocalLeaseSet> GetLeaseSetMt ();
|
2014-11-28 18:01:35 +00:00
|
|
|
void Publish ();
|
|
|
|
void HandlePublishConfirmationTimer (const boost::system::error_code& ecode);
|
2016-02-11 19:45:33 +00:00
|
|
|
void HandlePublishVerificationTimer (const boost::system::error_code& ecode);
|
2017-02-13 01:52:46 +00:00
|
|
|
void HandlePublishDelayTimer (const boost::system::error_code& ecode);
|
2014-12-25 21:47:15 +00:00
|
|
|
void HandleDatabaseStoreMessage (const uint8_t * buf, size_t len);
|
|
|
|
void HandleDatabaseSearchReplyMessage (const uint8_t * buf, size_t len);
|
2020-01-06 19:37:40 +00:00
|
|
|
void HandleDeliveryStatusMessage (uint32_t msgID);
|
2014-10-05 12:54:59 +00:00
|
|
|
|
2019-03-22 19:32:13 +00:00
|
|
|
void RequestLeaseSet (const i2p::data::IdentHash& dest, RequestComplete requestComplete, std::shared_ptr<const i2p::data::BlindedPublicKey> requestedBlindedKey = nullptr);
|
2020-03-01 10:25:50 +00:00
|
|
|
bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr<const i2p::data::RouterInfo> nextFloodfill, std::shared_ptr<LeaseSetRequest> request);
|
2014-12-25 21:47:15 +00:00
|
|
|
void HandleRequestTimoutTimer (const boost::system::error_code& ecode, const i2p::data::IdentHash& dest);
|
2015-01-23 17:48:25 +00:00
|
|
|
void HandleCleanupTimer (const boost::system::error_code& ecode);
|
2017-04-08 16:51:35 +00:00
|
|
|
void CleanupRemoteLeaseSets ();
|
2020-03-19 22:33:42 +00:00
|
|
|
i2p::data::CryptoKeyType GetPreferredCryptoType () const;
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2014-10-05 12:54:59 +00:00
|
|
|
private:
|
|
|
|
|
2020-02-02 23:58:58 +00:00
|
|
|
boost::asio::io_service& m_Service;
|
2016-07-22 13:56:17 +00:00
|
|
|
mutable std::mutex m_RemoteLeaseSetsMutex;
|
2023-04-21 18:54:54 +00:00
|
|
|
std::unordered_map<i2p::data::IdentHash, std::shared_ptr<i2p::data::LeaseSet> > m_RemoteLeaseSets;
|
|
|
|
std::unordered_map<i2p::data::IdentHash, std::shared_ptr<LeaseSetRequest> > m_LeaseSetRequests;
|
2014-10-16 16:37:39 +00:00
|
|
|
|
2015-01-20 03:28:13 +00:00
|
|
|
std::shared_ptr<i2p::tunnel::TunnelPool> m_Pool;
|
2016-10-25 18:07:34 +00:00
|
|
|
std::mutex m_LeaseSetMutex;
|
2019-03-10 13:22:42 +00:00
|
|
|
std::shared_ptr<const i2p::data::LocalLeaseSet> m_LeaseSet;
|
2014-10-16 16:37:39 +00:00
|
|
|
bool m_IsPublic;
|
2014-11-28 18:01:35 +00:00
|
|
|
uint32_t m_PublishReplyToken;
|
2017-02-13 01:52:46 +00:00
|
|
|
uint64_t m_LastSubmissionTime; // in seconds
|
2014-12-07 21:10:25 +00:00
|
|
|
std::set<i2p::data::IdentHash> m_ExcludedFloodfills; // for publishing
|
2017-04-08 16:51:35 +00:00
|
|
|
|
|
|
|
boost::asio::deadline_timer m_PublishConfirmationTimer, m_PublishVerificationTimer,
|
2017-02-13 01:52:46 +00:00
|
|
|
m_PublishDelayTimer, m_CleanupTimer;
|
2017-10-04 16:27:08 +00:00
|
|
|
std::string m_Nickname;
|
2019-09-06 15:02:19 +00:00
|
|
|
int m_LeaseSetType, m_AuthType;
|
2019-06-07 18:51:08 +00:00
|
|
|
std::unique_ptr<i2p::data::Tag<32> > m_LeaseSetPrivKey; // non-null if presented
|
2014-11-28 18:01:35 +00:00
|
|
|
|
2014-10-16 16:37:39 +00:00
|
|
|
public:
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2014-10-16 16:37:39 +00:00
|
|
|
// for HTTP only
|
|
|
|
int GetNumRemoteLeaseSets () const { return m_RemoteLeaseSets.size (); };
|
2016-11-12 14:49:16 +00:00
|
|
|
const decltype(m_RemoteLeaseSets)& GetLeaseSets () const { return m_RemoteLeaseSets; };
|
2019-05-14 18:42:10 +00:00
|
|
|
bool IsEncryptedLeaseSet () const { return m_LeaseSetType == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2; };
|
2019-09-06 15:02:19 +00:00
|
|
|
bool IsPerClientAuth () const { return m_AuthType > 0; };
|
2017-04-08 16:51:35 +00:00
|
|
|
};
|
2016-05-23 14:33:01 +00:00
|
|
|
|
2020-02-04 19:17:23 +00:00
|
|
|
class ClientDestination: public LeaseSetDestination
|
2016-05-23 14:33:01 +00:00
|
|
|
{
|
2020-04-14 23:12:44 +00:00
|
|
|
struct EncryptionKey
|
|
|
|
{
|
|
|
|
uint8_t pub[256], priv[256];
|
|
|
|
i2p::data::CryptoKeyType keyType;
|
|
|
|
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> decryptor;
|
|
|
|
|
|
|
|
EncryptionKey (i2p::data::CryptoKeyType t):keyType(t) { memset (pub, 0, 256); memset (priv, 0, 256); };
|
|
|
|
void GenerateKeys () { i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, priv, pub); };
|
|
|
|
void CreateDecryptor () { decryptor = i2p::data::PrivateKeys::CreateDecryptor (keyType, priv); };
|
2020-03-01 10:25:50 +00:00
|
|
|
};
|
|
|
|
|
2016-05-23 14:33:01 +00:00
|
|
|
public:
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2020-03-01 10:25:50 +00:00
|
|
|
ClientDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys,
|
2020-02-04 19:17:23 +00:00
|
|
|
bool isPublic, const std::map<std::string, std::string> * params = nullptr);
|
2016-05-23 18:31:22 +00:00
|
|
|
~ClientDestination ();
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2020-02-04 19:17:23 +00:00
|
|
|
void Start ();
|
|
|
|
void Stop ();
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2016-05-26 18:54:33 +00:00
|
|
|
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
2017-04-08 16:51:35 +00:00
|
|
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const { m_Keys.Sign (buf, len, signature); };
|
|
|
|
|
2017-07-06 20:12:06 +00:00
|
|
|
// ref counter
|
2018-01-06 03:48:51 +00:00
|
|
|
int Acquire () { return ++m_RefCounter; };
|
2017-07-06 20:12:06 +00:00
|
|
|
int Release () { return --m_RefCounter; };
|
2018-01-06 03:48:51 +00:00
|
|
|
int GetRefCounter () const { return m_RefCounter; };
|
2017-07-06 20:12:06 +00:00
|
|
|
|
2016-05-23 18:31:22 +00:00
|
|
|
// streaming
|
2023-06-12 02:10:32 +00:00
|
|
|
std::shared_ptr<i2p::stream::StreamingDestination> CreateStreamingDestination (uint16_t port, bool gzip = true); // additional
|
|
|
|
std::shared_ptr<i2p::stream::StreamingDestination> GetStreamingDestination (uint16_t port = 0) const;
|
|
|
|
std::shared_ptr<i2p::stream::StreamingDestination> RemoveStreamingDestination (uint16_t port);
|
2016-05-23 18:31:22 +00:00
|
|
|
// following methods operate with default streaming destination
|
2023-06-12 02:10:32 +00:00
|
|
|
void CreateStream (StreamRequestComplete streamRequestComplete, const i2p::data::IdentHash& dest, uint16_t port = 0);
|
|
|
|
void CreateStream (StreamRequestComplete streamRequestComplete, std::shared_ptr<const i2p::data::BlindedPublicKey> dest, uint16_t port = 0);
|
|
|
|
std::shared_ptr<i2p::stream::Stream> CreateStream (const i2p::data::IdentHash& dest, uint16_t port = 0); // sync
|
|
|
|
std::shared_ptr<i2p::stream::Stream> CreateStream (std::shared_ptr<const i2p::data::BlindedPublicKey> dest, uint16_t port = 0); // sync
|
|
|
|
std::shared_ptr<i2p::stream::Stream> CreateStream (std::shared_ptr<const i2p::data::LeaseSet> remote, uint16_t port = 0);
|
2021-09-26 20:25:12 +00:00
|
|
|
void SendPing (const i2p::data::IdentHash& to);
|
|
|
|
void SendPing (std::shared_ptr<const i2p::data::BlindedPublicKey> to);
|
2016-05-23 18:31:22 +00:00
|
|
|
void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor);
|
|
|
|
void StopAcceptingStreams ();
|
|
|
|
bool IsAcceptingStreams () const;
|
2016-12-24 13:53:35 +00:00
|
|
|
void AcceptOnce (const i2p::stream::StreamingDestination::Acceptor& acceptor);
|
2017-11-24 20:37:17 +00:00
|
|
|
int GetStreamingAckDelay () const { return m_StreamingAckDelay; }
|
2020-09-30 21:12:28 +00:00
|
|
|
bool IsStreamingAnswerPings () const { return m_IsStreamingAnswerPings; }
|
2021-11-27 20:30:35 +00:00
|
|
|
|
2016-05-23 18:31:22 +00:00
|
|
|
// datagram
|
2020-03-01 10:25:50 +00:00
|
|
|
i2p::datagram::DatagramDestination * GetDatagramDestination () const { return m_DatagramDestination; };
|
|
|
|
i2p::datagram::DatagramDestination * CreateDatagramDestination (bool gzip = true);
|
2017-04-08 16:51:35 +00:00
|
|
|
|
|
|
|
// implements LocalDestination
|
2021-08-31 22:51:40 +00:00
|
|
|
bool Decrypt (const uint8_t * encrypted, uint8_t * data, i2p::data::CryptoKeyType preferredCrypto) const;
|
2017-04-08 16:51:35 +00:00
|
|
|
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Keys.GetPublic (); };
|
2020-03-01 10:25:50 +00:00
|
|
|
bool SupportsEncryptionType (i2p::data::CryptoKeyType keyType) const;
|
2020-04-14 23:12:44 +00:00
|
|
|
const uint8_t * GetEncryptionPublicKey (i2p::data::CryptoKeyType keyType) const;
|
2016-05-23 14:33:01 +00:00
|
|
|
|
2016-05-23 18:31:22 +00:00
|
|
|
protected:
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2016-09-08 14:16:42 +00:00
|
|
|
void CleanupDestination ();
|
2016-05-23 18:31:22 +00:00
|
|
|
// I2CP
|
|
|
|
void HandleDataMessage (const uint8_t * buf, size_t len);
|
2021-04-01 17:37:21 +00:00
|
|
|
void CreateNewLeaseSet (const std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> >& tunnels);
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2016-05-23 14:33:01 +00:00
|
|
|
private:
|
|
|
|
|
2020-04-03 11:31:18 +00:00
|
|
|
std::shared_ptr<ClientDestination> GetSharedFromThis () {
|
|
|
|
return std::static_pointer_cast<ClientDestination>(shared_from_this ());
|
|
|
|
}
|
2020-04-16 02:04:18 +00:00
|
|
|
void PersistTemporaryKeys (EncryptionKey * keys, bool isSingleKey);
|
2019-07-16 20:31:17 +00:00
|
|
|
void ReadAuthKey (const std::string& group, const std::map<std::string, std::string> * params);
|
|
|
|
|
2023-01-03 18:25:19 +00:00
|
|
|
template<typename Dest>
|
2023-06-12 02:10:32 +00:00
|
|
|
std::shared_ptr<i2p::stream::Stream> CreateStreamSync (const Dest& dest, uint16_t port);
|
2023-01-03 18:25:19 +00:00
|
|
|
|
2020-03-01 10:25:50 +00:00
|
|
|
private:
|
|
|
|
|
2016-05-23 14:33:01 +00:00
|
|
|
i2p::data::PrivateKeys m_Keys;
|
2020-04-14 23:12:44 +00:00
|
|
|
std::unique_ptr<EncryptionKey> m_StandardEncryptionKey;
|
|
|
|
std::unique_ptr<EncryptionKey> m_ECIESx25519EncryptionKey;
|
2016-05-23 18:31:22 +00:00
|
|
|
|
2017-11-24 20:37:17 +00:00
|
|
|
int m_StreamingAckDelay;
|
2020-09-30 21:12:28 +00:00
|
|
|
bool m_IsStreamingAnswerPings;
|
2016-05-23 18:31:22 +00:00
|
|
|
std::shared_ptr<i2p::stream::StreamingDestination> m_StreamingDestination; // default
|
|
|
|
std::map<uint16_t, std::shared_ptr<i2p::stream::StreamingDestination> > m_StreamingDestinationsByPorts;
|
2023-04-12 19:28:15 +00:00
|
|
|
std::shared_ptr<i2p::stream::StreamingDestination> m_LastStreamingDestination; uint16_t m_LastPort; // for server tunnels
|
2018-01-06 04:01:44 +00:00
|
|
|
i2p::datagram::DatagramDestination * m_DatagramDestination;
|
2017-07-06 20:12:06 +00:00
|
|
|
int m_RefCounter; // how many clients(tunnels) use this destination
|
2016-05-23 18:31:22 +00:00
|
|
|
|
2016-08-30 17:27:57 +00:00
|
|
|
boost::asio::deadline_timer m_ReadyChecker;
|
2017-04-08 16:51:35 +00:00
|
|
|
|
2020-03-01 10:25:50 +00:00
|
|
|
std::shared_ptr<std::vector<i2p::data::AuthPublicKey> > m_AuthKeys; // we don't need them for I2CP
|
2019-07-16 20:31:17 +00:00
|
|
|
|
2016-05-23 18:31:22 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
// for HTTP only
|
|
|
|
std::vector<std::shared_ptr<const i2p::stream::Stream> > GetAllStreams () const;
|
2020-03-04 20:54:09 +00:00
|
|
|
bool DeleteStream (uint32_t recvStreamID);
|
2017-04-08 16:51:35 +00:00
|
|
|
};
|
2020-02-04 19:17:23 +00:00
|
|
|
|
|
|
|
class RunnableClientDestination: private i2p::util::RunnableService, public ClientDestination
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
RunnableClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params = nullptr);
|
2020-03-01 10:25:50 +00:00
|
|
|
~RunnableClientDestination ();
|
2020-02-04 19:17:23 +00:00
|
|
|
|
|
|
|
void Start ();
|
|
|
|
void Stop ();
|
|
|
|
};
|
|
|
|
|
2017-04-08 16:51:35 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-05 12:54:59 +00:00
|
|
|
|
|
|
|
#endif
|