2020-05-22 16:18:41 +03:00
|
|
|
/*
|
2024-02-21 12:37:33 -05:00
|
|
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
2020-05-22 16:18:41 +03: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
|
|
|
|
*/
|
|
|
|
|
2013-10-27 11:28:23 -04:00
|
|
|
#ifndef ROUTER_INFO_H__
|
|
|
|
#define ROUTER_INFO_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2021-12-30 15:16:13 -05:00
|
|
|
#include <array>
|
2013-10-27 11:28:23 -04:00
|
|
|
#include <iostream>
|
2024-09-08 16:30:27 -04:00
|
|
|
#include <memory>
|
2013-10-27 11:28:23 -04:00
|
|
|
#include <boost/asio.hpp>
|
2024-09-08 16:30:27 -04:00
|
|
|
#ifndef __cpp_lib_atomic_shared_ptr
|
2018-01-06 11:48:51 +08:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2024-09-08 16:30:27 -04:00
|
|
|
#endif
|
2014-01-09 22:26:30 -05:00
|
|
|
#include "Identity.h"
|
2015-03-24 12:47:57 -04:00
|
|
|
#include "Profiling.h"
|
2022-03-24 15:50:20 -04:00
|
|
|
#include "Family.h"
|
2013-10-27 11:28:23 -04:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace data
|
2014-09-02 16:11:31 -04:00
|
|
|
{
|
2016-02-20 20:20:19 -05:00
|
|
|
const char ROUTER_INFO_PROPERTY_LEASESETS[] = "netdb.knownLeaseSets";
|
2018-01-06 11:48:51 +08:00
|
|
|
const char ROUTER_INFO_PROPERTY_ROUTERS[] = "netdb.knownRouters";
|
2016-02-20 20:20:19 -05:00
|
|
|
const char ROUTER_INFO_PROPERTY_NETID[] = "netId";
|
2020-05-20 14:59:18 -04:00
|
|
|
const char ROUTER_INFO_PROPERTY_VERSION[] = "router.version";
|
2018-01-06 11:48:51 +08:00
|
|
|
const char ROUTER_INFO_PROPERTY_FAMILY[] = "family";
|
2016-02-20 20:20:19 -05:00
|
|
|
const char ROUTER_INFO_PROPERTY_FAMILY_SIG[] = "family.sig";
|
2018-01-06 11:48:51 +08:00
|
|
|
|
2014-09-02 16:11:31 -04:00
|
|
|
const char CAPS_FLAG_FLOODFILL = 'f';
|
|
|
|
const char CAPS_FLAG_HIDDEN = 'H';
|
|
|
|
const char CAPS_FLAG_REACHABLE = 'R';
|
2018-01-06 11:48:51 +08:00
|
|
|
const char CAPS_FLAG_UNREACHABLE = 'U';
|
2016-03-31 00:00:00 +00:00
|
|
|
/* bandwidth flags */
|
|
|
|
const char CAPS_FLAG_LOW_BANDWIDTH1 = 'K'; /* < 12 KBps */
|
|
|
|
const char CAPS_FLAG_LOW_BANDWIDTH2 = 'L'; /* 12-48 KBps */
|
2024-02-21 12:37:33 -05:00
|
|
|
const char CAPS_FLAG_LOW_BANDWIDTH3 = 'M'; /* 48-64 KBps */
|
2024-09-03 18:36:50 -04:00
|
|
|
const char CAPS_FLAG_LOW_BANDWIDTH4 = 'N'; /* 64-128 KBps */
|
|
|
|
const char CAPS_FLAG_HIGH_BANDWIDTH = 'O'; /* 128-256 KBps */
|
2023-10-15 08:31:55 -04:00
|
|
|
const char CAPS_FLAG_EXTRA_BANDWIDTH1 = 'P'; /* 256-2048 KBps */
|
|
|
|
const char CAPS_FLAG_EXTRA_BANDWIDTH2 = 'X'; /* > 2048 KBps */
|
|
|
|
// bandwidth limits in kBps
|
|
|
|
const uint32_t LOW_BANDWIDTH_LIMIT = 48;
|
|
|
|
const uint32_t HIGH_BANDWIDTH_LIMIT = 256;
|
|
|
|
const uint32_t EXTRA_BANDWIDTH_LIMIT = 2048;
|
2023-03-03 20:21:56 -05:00
|
|
|
// congesion flags
|
2023-03-04 15:46:44 -05:00
|
|
|
const char CAPS_FLAG_MEDIUM_CONGESTION = 'D';
|
|
|
|
const char CAPS_FLAG_HIGH_CONGESTION = 'E';
|
|
|
|
const char CAPS_FLAG_REJECT_ALL_CONGESTION = 'G';
|
2023-03-03 20:21:56 -05:00
|
|
|
|
2021-02-22 22:53:25 -05:00
|
|
|
const char CAPS_FLAG_V4 = '4';
|
|
|
|
const char CAPS_FLAG_V6 = '6';
|
2022-11-23 15:45:00 -05:00
|
|
|
const char CAPS_FLAG_SSU2_TESTING = 'B';
|
|
|
|
const char CAPS_FLAG_SSU2_INTRODUCER = 'C';
|
2014-09-02 16:11:31 -04:00
|
|
|
|
2021-03-01 11:09:25 -05:00
|
|
|
const uint8_t COST_NTCP2_PUBLISHED = 3;
|
|
|
|
const uint8_t COST_NTCP2_NON_PUBLISHED = 14;
|
2022-04-02 14:32:26 -04:00
|
|
|
const uint8_t COST_SSU2_DIRECT = 8;
|
2022-03-12 21:40:12 -05:00
|
|
|
const uint8_t COST_SSU2_NON_PUBLISHED = 15;
|
2022-05-20 19:56:05 +03:00
|
|
|
|
2022-04-09 14:40:38 -04:00
|
|
|
const size_t MAX_RI_BUFFER_SIZE = 3072; // if RouterInfo exceeds 3K we consider it as malformed, might extend later
|
2023-03-06 19:48:04 -05:00
|
|
|
const int HIGH_CONGESTION_INTERVAL = 15*60; // in seconds, 15 minutes
|
2023-04-05 21:30:36 -04:00
|
|
|
const int INTRODUCER_UPDATE_INTERVAL = 20*60*1000; // in milliseconds, 20 minutes
|
2023-03-03 20:21:56 -05:00
|
|
|
|
2013-11-24 18:10:27 -05:00
|
|
|
class RouterInfo: public RoutingDestination
|
2013-10-27 11:28:23 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2022-12-16 15:12:30 -05:00
|
|
|
enum SupportedTransportsIdx
|
|
|
|
{
|
|
|
|
eNTCP2V4Idx = 0,
|
|
|
|
eNTCP2V6Idx,
|
|
|
|
eSSU2V4Idx,
|
|
|
|
eSSU2V6Idx,
|
|
|
|
eNTCP2V6MeshIdx,
|
|
|
|
eNumTransports
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TransportBit(tr) e##tr = (1 << e##tr##Idx)
|
2023-01-03 21:25:19 +03:00
|
|
|
|
2021-06-02 12:55:08 -04:00
|
|
|
enum SupportedTransports
|
2018-01-06 11:48:51 +08:00
|
|
|
{
|
2022-12-16 15:12:30 -05:00
|
|
|
TransportBit(NTCP2V4), // 0x01
|
|
|
|
TransportBit(NTCP2V6), // 0x02
|
|
|
|
TransportBit(SSU2V4), // 0x04
|
|
|
|
TransportBit(SSU2V6), // 0x08
|
|
|
|
TransportBit(NTCP2V6Mesh), // 0x10
|
2021-11-05 14:51:24 -04:00
|
|
|
eAllTransports = 0xFF
|
2014-01-25 21:47:01 -05:00
|
|
|
};
|
2021-10-05 19:38:33 -04:00
|
|
|
typedef uint8_t CompatibleTransports;
|
2021-11-27 23:30:35 +03:00
|
|
|
|
2014-03-19 12:02:51 -04:00
|
|
|
enum Caps
|
|
|
|
{
|
|
|
|
eFloodfill = 0x01,
|
2014-03-19 15:58:57 -04:00
|
|
|
eHighBandwidth = 0x02,
|
2016-01-02 22:17:04 -05:00
|
|
|
eExtraBandwidth = 0x04,
|
|
|
|
eReachable = 0x08,
|
2021-02-22 22:53:25 -05:00
|
|
|
eHidden = 0x10,
|
|
|
|
eUnreachable = 0x20
|
2014-03-19 12:02:51 -04:00
|
|
|
};
|
|
|
|
|
2023-03-03 20:21:56 -05:00
|
|
|
enum Congestion
|
|
|
|
{
|
|
|
|
eLowCongestion = 0,
|
|
|
|
eMediumCongestion,
|
|
|
|
eHighCongestion,
|
|
|
|
eRejectAll
|
|
|
|
};
|
|
|
|
|
2021-02-22 22:53:25 -05:00
|
|
|
enum AddressCaps
|
|
|
|
{
|
|
|
|
eV4 = 0x01,
|
|
|
|
eV6 = 0x02,
|
|
|
|
eSSUTesting = 0x04,
|
|
|
|
eSSUIntroducer = 0x08
|
|
|
|
};
|
2021-11-27 23:30:35 +03:00
|
|
|
|
2013-10-27 11:28:23 -04:00
|
|
|
enum TransportStyle
|
|
|
|
{
|
|
|
|
eTransportUnknown = 0,
|
2022-11-23 15:45:00 -05:00
|
|
|
eTransportNTCP2,
|
2022-03-11 16:17:44 -05:00
|
|
|
eTransportSSU2
|
2013-10-27 11:28:23 -04:00
|
|
|
};
|
|
|
|
|
2018-01-06 11:48:51 +08:00
|
|
|
struct Introducer
|
2014-02-20 16:15:12 -05:00
|
|
|
{
|
2023-08-07 21:28:13 -04:00
|
|
|
Introducer (): iTag (0), iExp (0) { iH.Fill(0); };
|
2022-11-23 15:45:00 -05:00
|
|
|
IdentHash iH;
|
2014-02-20 16:15:12 -05:00
|
|
|
uint32_t iTag;
|
2017-05-24 12:49:36 -04:00
|
|
|
uint32_t iExp;
|
2014-02-20 16:15:12 -05:00
|
|
|
};
|
|
|
|
|
2017-01-02 16:36:59 -05:00
|
|
|
struct SSUExt
|
|
|
|
{
|
|
|
|
int mtu;
|
2018-01-06 11:48:51 +08:00
|
|
|
std::vector<Introducer> introducers;
|
2017-01-02 16:36:59 -05:00
|
|
|
};
|
2018-01-06 11:48:51 +08:00
|
|
|
|
2013-10-27 11:28:23 -04:00
|
|
|
struct Address
|
|
|
|
{
|
|
|
|
TransportStyle transportStyle;
|
2014-01-21 16:07:16 -05:00
|
|
|
boost::asio::ip::address host;
|
2022-02-06 10:17:35 -05:00
|
|
|
Tag<32> s, i; // keys, i is first 16 bytes for NTCP2 and 32 bytes intro key for SSU
|
2017-01-02 16:36:59 -05:00
|
|
|
int port;
|
2013-10-27 11:28:23 -04:00
|
|
|
uint64_t date;
|
2021-04-07 13:05:38 -04:00
|
|
|
uint8_t caps;
|
2021-04-05 21:45:48 -04:00
|
|
|
bool published = false;
|
2017-01-02 16:36:59 -05:00
|
|
|
std::unique_ptr<SSUExt> ssu; // not null for SSU
|
2014-10-26 21:32:06 -04:00
|
|
|
|
2018-01-06 11:48:51 +08:00
|
|
|
bool IsCompatible (const boost::asio::ip::address& other) const
|
2014-10-26 21:32:06 -04:00
|
|
|
{
|
2021-03-12 20:51:12 -05:00
|
|
|
return (IsV4 () && other.is_v4 ()) ||
|
|
|
|
(IsV6 () && other.is_v6 ());
|
2018-01-06 11:48:51 +08:00
|
|
|
}
|
2015-11-03 09:15:49 -05:00
|
|
|
|
|
|
|
bool operator==(const Address& other) const
|
|
|
|
{
|
2022-04-28 11:43:33 -04:00
|
|
|
return transportStyle == other.transportStyle &&
|
2018-08-26 09:40:27 -04:00
|
|
|
host == other.host && port == other.port;
|
2018-01-06 11:48:51 +08:00
|
|
|
}
|
2015-11-03 09:15:49 -05:00
|
|
|
|
|
|
|
bool operator!=(const Address& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
2018-01-06 11:48:51 +08:00
|
|
|
}
|
2018-06-15 12:52:43 -04:00
|
|
|
|
2022-11-23 15:45:00 -05:00
|
|
|
bool IsNTCP2 () const { return transportStyle == eTransportNTCP2; };
|
2022-05-20 19:56:05 +03:00
|
|
|
bool IsSSU2 () const { return transportStyle == eTransportSSU2; };
|
2021-04-05 21:45:48 -04:00
|
|
|
bool IsPublishedNTCP2 () const { return IsNTCP2 () && published; };
|
2022-04-28 11:43:33 -04:00
|
|
|
bool IsReachableSSU () const { return (bool)ssu && (published || UsesIntroducer ()); };
|
2022-05-20 19:56:05 +03:00
|
|
|
bool UsesIntroducer () const { return (bool)ssu && !ssu->introducers.empty (); };
|
2021-11-27 23:30:35 +03:00
|
|
|
|
2021-02-22 21:04:26 -05:00
|
|
|
bool IsIntroducer () const { return caps & eSSUIntroducer; };
|
|
|
|
bool IsPeerTesting () const { return caps & eSSUTesting; };
|
2021-03-12 16:13:01 -05:00
|
|
|
|
2021-04-03 22:18:09 -04:00
|
|
|
bool IsV4 () const { return (caps & AddressCaps::eV4) || (host.is_v4 () && !host.is_unspecified ()); };
|
|
|
|
bool IsV6 () const { return (caps & AddressCaps::eV6) || (host.is_v6 () && !host.is_unspecified ()); };
|
2013-10-27 11:28:23 -04:00
|
|
|
};
|
2022-01-03 16:27:28 -05:00
|
|
|
|
|
|
|
class Buffer: public std::array<uint8_t, MAX_RI_BUFFER_SIZE>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Buffer () = default;
|
|
|
|
Buffer (const uint8_t * buf, size_t len);
|
2024-05-26 15:33:37 -04:00
|
|
|
Buffer (const Buffer& other): Buffer (other.data (), other.m_BufferLen) {};
|
2024-05-08 19:09:03 -04:00
|
|
|
|
|
|
|
size_t GetBufferLen () const { return m_BufferLen; };
|
|
|
|
void SetBufferLen (size_t len) { m_BufferLen = len; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
size_t m_BufferLen = 0;
|
2022-01-03 16:27:28 -05:00
|
|
|
};
|
2022-05-20 19:56:05 +03:00
|
|
|
|
2022-12-16 15:12:30 -05:00
|
|
|
typedef std::array<std::shared_ptr<Address>, eNumTransports> Addresses;
|
2024-09-08 16:30:27 -04:00
|
|
|
#ifdef __cpp_lib_atomic_shared_ptr
|
|
|
|
typedef std::shared_ptr<Addresses> AddressesPtr;
|
|
|
|
#else
|
|
|
|
typedef boost::shared_ptr<Addresses> AddressesPtr;
|
|
|
|
#endif
|
2014-07-23 10:56:41 -04:00
|
|
|
RouterInfo (const std::string& fullPath);
|
2013-10-27 11:28:23 -04:00
|
|
|
RouterInfo (const RouterInfo& ) = default;
|
2013-12-29 10:48:57 -05:00
|
|
|
RouterInfo& operator=(const RouterInfo& ) = default;
|
2022-01-03 16:27:28 -05:00
|
|
|
RouterInfo (std::shared_ptr<Buffer>&& buf, size_t len);
|
|
|
|
RouterInfo (const uint8_t * buf, size_t len);
|
2022-01-15 12:48:49 -05:00
|
|
|
virtual ~RouterInfo ();
|
2018-01-06 11:48:51 +08:00
|
|
|
|
2015-11-03 09:15:49 -05:00
|
|
|
std::shared_ptr<const IdentityEx> GetRouterIdentity () const { return m_RouterIdentity; };
|
|
|
|
void SetRouterIdentity (std::shared_ptr<const IdentityEx> identity);
|
2014-11-20 12:21:27 -05:00
|
|
|
std::string GetIdentHashBase64 () const { return GetIdentHash ().ToBase64 (); };
|
2013-11-29 07:52:09 -05:00
|
|
|
uint64_t GetTimestamp () const { return m_Timestamp; };
|
2020-05-20 14:59:18 -04:00
|
|
|
int GetVersion () const { return m_Version; };
|
2022-05-20 19:56:05 +03:00
|
|
|
virtual void SetProperty (const std::string& key, const std::string& value) {};
|
2022-01-15 19:26:11 -05:00
|
|
|
virtual void ClearProperties () {};
|
2024-09-08 16:30:27 -04:00
|
|
|
AddressesPtr GetAddresses () const; // should be called for local RI only, otherwise must return shared_ptr
|
2023-02-05 18:26:09 -05:00
|
|
|
std::shared_ptr<const Address> GetNTCP2V4Address () const;
|
|
|
|
std::shared_ptr<const Address> GetNTCP2V6Address () const;
|
2021-11-27 23:30:35 +03:00
|
|
|
std::shared_ptr<const Address> GetPublishedNTCP2V4Address () const;
|
|
|
|
std::shared_ptr<const Address> GetPublishedNTCP2V6Address () const;
|
2021-01-31 17:25:07 -05:00
|
|
|
std::shared_ptr<const Address> GetYggdrasilAddress () const;
|
2022-03-16 21:11:48 -04:00
|
|
|
std::shared_ptr<const Address> GetSSU2V4Address () const;
|
|
|
|
std::shared_ptr<const Address> GetSSU2V6Address () const;
|
2022-06-07 16:09:20 -04:00
|
|
|
std::shared_ptr<const Address> GetSSU2Address (bool v4) const;
|
2018-01-06 11:48:51 +08:00
|
|
|
|
2023-01-28 22:33:44 -05:00
|
|
|
void AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv,int port, uint8_t caps); // non published
|
2021-11-27 23:30:35 +03:00
|
|
|
void AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv,
|
2023-01-28 22:33:44 -05:00
|
|
|
const boost::asio::ip::address& host, int port); // published
|
2023-01-26 11:21:08 -05:00
|
|
|
void RemoveNTCP2Address (bool v4);
|
2023-01-28 22:33:44 -05:00
|
|
|
void AddSSU2Address (const uint8_t * staticKey, const uint8_t * introKey, int port, uint8_t caps); // non published
|
2022-03-29 13:56:56 -04:00
|
|
|
void AddSSU2Address (const uint8_t * staticKey, const uint8_t * introKey,
|
|
|
|
const boost::asio::ip::address& host, int port); // published
|
2023-01-26 11:21:08 -05:00
|
|
|
void RemoveSSU2Address (bool v4);
|
2021-03-08 15:57:05 -05:00
|
|
|
void SetUnreachableAddressesTransportCaps (uint8_t transports); // bitmask of AddressCaps
|
2021-06-02 12:55:08 -04:00
|
|
|
void UpdateSupportedTransports ();
|
2023-04-05 21:30:36 -04:00
|
|
|
void UpdateIntroducers (uint64_t ts); // ts in seconds
|
2024-04-28 11:16:59 -04:00
|
|
|
bool IsFloodfill () const { return m_IsFloodfill; };
|
|
|
|
void SetFloodfill () { m_IsFloodfill = true; };
|
|
|
|
void ResetFloodfill () { m_IsFloodfill = false; };
|
2021-09-03 13:30:01 -04:00
|
|
|
bool IsECIES () const { return m_RouterIdentity->GetCryptoKeyType () == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD; };
|
2018-06-06 11:51:34 -04:00
|
|
|
bool IsNTCP2 (bool v4only = true) const;
|
2022-03-16 21:11:48 -04:00
|
|
|
bool IsNTCP2V6 () const { return m_SupportedTransports & eNTCP2V6; };
|
|
|
|
bool IsSSU2V4 () const { return m_SupportedTransports & eSSU2V4; };
|
|
|
|
bool IsSSU2V6 () const { return m_SupportedTransports & eSSU2V6; };
|
2022-11-23 15:45:00 -05:00
|
|
|
bool IsV6 () const { return m_SupportedTransports & (eNTCP2V6 | eSSU2V6); };
|
|
|
|
bool IsV4 () const { return m_SupportedTransports & (eNTCP2V4 | eSSU2V4); };
|
2022-03-16 21:11:48 -04:00
|
|
|
bool IsMesh () const { return m_SupportedTransports & eNTCP2V6Mesh; };
|
2014-10-26 21:32:06 -04:00
|
|
|
void EnableV6 ();
|
|
|
|
void DisableV6 ();
|
2016-03-24 18:44:41 -04:00
|
|
|
void EnableV4 ();
|
|
|
|
void DisableV4 ();
|
2021-01-31 17:25:07 -05:00
|
|
|
void EnableMesh ();
|
2021-11-27 23:30:35 +03:00
|
|
|
void DisableMesh ();
|
|
|
|
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
|
|
|
|
bool IsReachableFrom (const RouterInfo& other) const { return m_ReachableTransports & other.m_SupportedTransports; };
|
2021-10-05 19:38:33 -04:00
|
|
|
bool IsReachableBy (CompatibleTransports transports) const { return m_ReachableTransports & transports; };
|
2021-11-27 23:30:35 +03:00
|
|
|
CompatibleTransports GetCompatibleTransports (bool incoming) const { return incoming ? m_ReachableTransports : m_SupportedTransports; };
|
2024-04-19 19:12:29 -04:00
|
|
|
CompatibleTransports GetPublishedTransports () const { return m_PublishedTransports; };
|
2021-11-27 23:30:35 +03:00
|
|
|
bool HasValidAddresses () const { return m_SupportedTransports; };
|
2014-06-18 10:41:59 -04:00
|
|
|
bool IsHidden () const { return m_Caps & eHidden; };
|
2015-03-18 13:07:11 -04:00
|
|
|
bool IsHighBandwidth () const { return m_Caps & RouterInfo::eHighBandwidth; };
|
2018-01-06 11:48:51 +08:00
|
|
|
bool IsExtraBandwidth () const { return m_Caps & RouterInfo::eExtraBandwidth; };
|
2020-11-23 12:49:18 -05:00
|
|
|
bool IsEligibleFloodfill () const;
|
2024-04-28 11:16:59 -04:00
|
|
|
bool IsDeclaredFloodfill () const { return m_Caps & RouterInfo::eFloodfill; };
|
2023-04-06 16:03:15 -04:00
|
|
|
bool IsPublished (bool v4) const;
|
2024-06-14 18:05:01 -04:00
|
|
|
bool IsPublishedOn (CompatibleTransports transports) const;
|
2024-04-14 20:09:06 -04:00
|
|
|
bool IsNAT2NATOnly (const RouterInfo& other) const; // only NAT-to-NAT connection is possible
|
2022-06-01 21:51:02 -04:00
|
|
|
bool IsSSU2PeerTesting (bool v4) const;
|
2022-07-19 18:38:58 -04:00
|
|
|
bool IsSSU2Introducer (bool v4) const;
|
2023-04-10 23:04:38 -04:00
|
|
|
bool IsHighCongestion (bool highBandwidth) const;
|
2021-11-27 23:30:35 +03:00
|
|
|
|
2018-01-06 11:48:51 +08:00
|
|
|
uint8_t GetCaps () const { return m_Caps; };
|
2024-02-22 23:07:07 +02:00
|
|
|
char GetBandwidthCap() const { return m_BandwidthCap; };
|
2022-01-15 18:54:02 -05:00
|
|
|
void SetCaps (uint8_t caps) { m_Caps = caps; };
|
2014-03-19 15:58:57 -04:00
|
|
|
|
2023-03-03 20:21:56 -05:00
|
|
|
Congestion GetCongestion () const { return m_Congestion; };
|
|
|
|
|
2018-01-06 11:48:51 +08:00
|
|
|
void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; };
|
2013-12-10 08:10:49 -05:00
|
|
|
bool IsUnreachable () const { return m_IsUnreachable; };
|
2023-04-18 14:35:13 -04:00
|
|
|
void ExcludeReachableTransports (CompatibleTransports transports) { m_ReachableTransports &= ~transports; };
|
2014-07-10 15:33:42 -04:00
|
|
|
|
2023-02-12 19:10:22 -05:00
|
|
|
const uint8_t * GetBuffer () const { return m_Buffer ? m_Buffer->data () : nullptr; };
|
2021-10-07 15:08:33 -04:00
|
|
|
const uint8_t * LoadBuffer (const std::string& fullPath); // load if necessary
|
2024-05-08 19:09:03 -04:00
|
|
|
size_t GetBufferLen () const { return m_Buffer ? m_Buffer->GetBufferLen () : 0; };
|
2024-10-16 13:51:48 -04:00
|
|
|
void DeleteBuffer () { m_Buffer = nullptr; m_IsBufferScheduledToDelete = false; };
|
2024-05-26 15:33:37 -04:00
|
|
|
std::shared_ptr<Buffer> GetSharedBuffer () const { return m_Buffer; };
|
|
|
|
std::shared_ptr<Buffer> CopyBuffer () const;
|
2024-10-16 15:05:29 -04:00
|
|
|
void ScheduleBufferToDelete () { m_IsBufferScheduledToDelete = true; };
|
2024-10-16 13:51:48 -04:00
|
|
|
bool IsBufferScheduledToDelete () const { return m_IsBufferScheduledToDelete; };
|
2013-11-20 07:46:09 -05:00
|
|
|
|
|
|
|
bool IsUpdated () const { return m_IsUpdated; };
|
2018-01-06 11:48:51 +08:00
|
|
|
void SetUpdated (bool updated) { m_IsUpdated = updated; };
|
2016-04-05 00:00:00 +00:00
|
|
|
bool SaveToFile (const std::string& fullPath);
|
2024-05-08 19:09:03 -04:00
|
|
|
static bool SaveToFile (const std::string& fullPath, std::shared_ptr<Buffer> buf);
|
|
|
|
|
2015-03-24 18:48:16 -04:00
|
|
|
std::shared_ptr<RouterProfile> GetProfile () const;
|
2023-02-11 16:22:02 -05:00
|
|
|
void DropProfile () { m_Profile = nullptr; };
|
2024-04-30 14:16:05 -04:00
|
|
|
bool HasProfile () const { return (bool)m_Profile; };
|
2018-01-06 11:48:51 +08:00
|
|
|
|
2023-02-12 18:02:16 -05:00
|
|
|
bool Update (const uint8_t * buf, size_t len);
|
2018-01-06 11:48:51 +08:00
|
|
|
bool IsNewer (const uint8_t * buf, size_t len) const;
|
2016-02-17 15:36:55 -05:00
|
|
|
|
2020-03-01 13:25:50 +03:00
|
|
|
/** return true if we are in a router family and the signature is valid */
|
2022-03-24 15:50:20 -04:00
|
|
|
bool IsFamily (FamilyID famid) const;
|
2018-01-06 11:48:51 +08:00
|
|
|
|
2013-11-24 18:10:27 -05:00
|
|
|
// implements RoutingDestination
|
2017-11-02 14:50:57 -04:00
|
|
|
std::shared_ptr<const IdentityEx> GetIdentity () const { return m_RouterIdentity; };
|
2021-08-31 18:51:40 -04:00
|
|
|
void Encrypt (const uint8_t * data, uint8_t * encrypted) const;
|
2017-11-07 15:05:22 -05:00
|
|
|
|
2013-11-26 20:59:25 -05:00
|
|
|
bool IsDestination () const { return false; };
|
2014-07-21 22:59:57 -04:00
|
|
|
|
2022-01-15 12:48:49 -05:00
|
|
|
protected:
|
|
|
|
|
|
|
|
RouterInfo ();
|
|
|
|
uint8_t * GetBufferPointer (size_t offset = 0 ) { return m_Buffer->data () + offset; };
|
|
|
|
void UpdateBuffer (const uint8_t * buf, size_t len);
|
2024-05-08 19:09:03 -04:00
|
|
|
void SetBufferLen (size_t len) { if (m_Buffer) m_Buffer->SetBufferLen (len); };
|
2022-01-15 12:48:49 -05:00
|
|
|
void RefreshTimestamp ();
|
2022-07-20 16:01:08 -04:00
|
|
|
CompatibleTransports GetReachableTransports () const { return m_ReachableTransports; };
|
2022-10-09 20:24:43 +03:00
|
|
|
void SetReachableTransports (CompatibleTransports transports) { m_ReachableTransports = transports; };
|
2023-03-06 19:48:04 -05:00
|
|
|
void SetCongestion (Congestion c) { m_Congestion = c; };
|
|
|
|
|
2013-10-27 11:28:23 -04:00
|
|
|
private:
|
|
|
|
|
2021-10-07 15:08:33 -04:00
|
|
|
bool LoadFile (const std::string& fullPath);
|
|
|
|
void ReadFromFile (const std::string& fullPath);
|
2013-10-27 11:28:23 -04:00
|
|
|
void ReadFromStream (std::istream& s);
|
2014-10-29 16:03:07 -04:00
|
|
|
void ReadFromBuffer (bool verifySignature);
|
2016-08-15 13:12:56 -04:00
|
|
|
size_t ReadString (char* str, size_t len, std::istream& s) const;
|
2021-02-22 22:53:25 -05:00
|
|
|
void ExtractCaps (const char * value);
|
|
|
|
uint8_t ExtractAddressCaps (const char * value) const;
|
2023-04-05 21:30:36 -04:00
|
|
|
void UpdateIntroducers (std::shared_ptr<Address> address, uint64_t ts);
|
2018-08-04 08:47:58 -04:00
|
|
|
template<typename Filter>
|
|
|
|
std::shared_ptr<const Address> GetAddress (Filter filter) const;
|
2022-03-11 19:03:00 -05:00
|
|
|
virtual std::shared_ptr<Buffer> NewBuffer () const;
|
2023-01-05 18:16:36 -05:00
|
|
|
virtual std::shared_ptr<Address> NewAddress () const;
|
2024-09-08 16:30:27 -04:00
|
|
|
virtual AddressesPtr NewAddresses () const;
|
2023-03-16 21:32:53 -04:00
|
|
|
virtual std::shared_ptr<IdentityEx> NewIdentity (const uint8_t * buf, size_t len) const;
|
2022-05-20 19:56:05 +03:00
|
|
|
|
2013-10-27 11:28:23 -04:00
|
|
|
private:
|
|
|
|
|
2022-03-24 15:50:20 -04:00
|
|
|
FamilyID m_FamilyID;
|
2015-11-03 09:15:49 -05:00
|
|
|
std::shared_ptr<const IdentityEx> m_RouterIdentity;
|
2021-12-30 15:16:13 -05:00
|
|
|
std::shared_ptr<Buffer> m_Buffer;
|
2023-04-05 21:30:36 -04:00
|
|
|
uint64_t m_Timestamp; // in milliseconds
|
2024-09-08 16:30:27 -04:00
|
|
|
#ifdef __cpp_lib_atomic_shared_ptr
|
|
|
|
std::atomic<AddressesPtr> m_Addresses;
|
|
|
|
#else
|
|
|
|
AddressesPtr m_Addresses;
|
|
|
|
#endif
|
2024-10-16 13:51:48 -04:00
|
|
|
bool m_IsUpdated, m_IsUnreachable, m_IsFloodfill, m_IsBufferScheduledToDelete;
|
2024-04-14 20:09:06 -04:00
|
|
|
CompatibleTransports m_SupportedTransports, m_ReachableTransports, m_PublishedTransports;
|
2021-10-05 19:38:33 -04:00
|
|
|
uint8_t m_Caps;
|
2024-02-22 23:07:07 +02:00
|
|
|
char m_BandwidthCap;
|
2020-05-20 14:59:18 -04:00
|
|
|
int m_Version;
|
2023-03-03 20:21:56 -05:00
|
|
|
Congestion m_Congestion;
|
2015-03-24 18:48:16 -04:00
|
|
|
mutable std::shared_ptr<RouterProfile> m_Profile;
|
2018-01-06 11:48:51 +08:00
|
|
|
};
|
2022-01-15 12:48:49 -05:00
|
|
|
|
|
|
|
class LocalRouterInfo: public RouterInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
LocalRouterInfo () = default;
|
|
|
|
void CreateBuffer (const PrivateKeys& privateKeys);
|
2022-01-15 18:54:02 -05:00
|
|
|
void UpdateCaps (uint8_t caps);
|
2023-04-02 11:27:51 -04:00
|
|
|
bool UpdateCongestion (Congestion c); // returns true if updated
|
2022-01-15 18:54:02 -05:00
|
|
|
|
2022-05-20 19:56:05 +03:00
|
|
|
void SetProperty (const std::string& key, const std::string& value) override;
|
|
|
|
void DeleteProperty (const std::string& key);
|
|
|
|
std::string GetProperty (const std::string& key) const;
|
2022-01-15 19:26:11 -05:00
|
|
|
void ClearProperties () override { m_Properties.clear (); };
|
2024-04-28 11:16:59 -04:00
|
|
|
void UpdateFloodfillProperty (bool floodfill);
|
|
|
|
|
2022-07-20 16:01:08 -04:00
|
|
|
bool AddSSU2Introducer (const Introducer& introducer, bool v4);
|
|
|
|
bool RemoveSSU2Introducer (const IdentHash& h, bool v4);
|
2024-09-27 13:32:20 -04:00
|
|
|
bool UpdateSSU2Introducer (const IdentHash& h, bool v4, uint32_t iTag, uint32_t iExp);
|
2022-10-09 20:24:43 +03:00
|
|
|
|
2022-01-15 18:54:02 -05:00
|
|
|
private:
|
|
|
|
|
|
|
|
void WriteToStream (std::ostream& s) const;
|
|
|
|
void UpdateCapsProperty ();
|
|
|
|
void WriteString (const std::string& str, std::ostream& s) const;
|
2022-03-11 19:03:00 -05:00
|
|
|
std::shared_ptr<Buffer> NewBuffer () const override;
|
2023-01-05 18:16:36 -05:00
|
|
|
std::shared_ptr<Address> NewAddress () const override;
|
2024-09-08 16:30:27 -04:00
|
|
|
RouterInfo::AddressesPtr NewAddresses () const override;
|
2023-03-16 21:32:53 -04:00
|
|
|
std::shared_ptr<IdentityEx> NewIdentity (const uint8_t * buf, size_t len) const override;
|
2022-05-20 19:56:05 +03:00
|
|
|
|
2022-01-15 18:54:02 -05:00
|
|
|
private:
|
|
|
|
|
2022-05-20 19:56:05 +03:00
|
|
|
std::map<std::string, std::string> m_Properties;
|
|
|
|
};
|
2018-01-06 11:48:51 +08:00
|
|
|
}
|
2013-10-27 11:28:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|