2013-10-27 15:28:23 +00:00
|
|
|
#ifndef ROUTER_INFO_H__
|
|
|
|
#define ROUTER_INFO_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <boost/asio.hpp>
|
2014-01-10 03:26:30 +00:00
|
|
|
#include "Identity.h"
|
2013-10-27 15:28:23 +00:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace data
|
2013-12-20 02:19:44 +00:00
|
|
|
{
|
2014-07-10 19:33:42 +00:00
|
|
|
const int MAX_RI_BUFFER_SIZE = 2048;
|
2013-11-24 23:10:27 +00:00
|
|
|
class RouterInfo: public RoutingDestination
|
2013-10-27 15:28:23 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-01-26 02:47:01 +00:00
|
|
|
enum SupportedTranports
|
|
|
|
{
|
|
|
|
eNTCPV4 = 0x01,
|
2014-03-19 16:02:51 +00:00
|
|
|
eNTCPV6 = 0x02,
|
|
|
|
eSSUV4 = 0x04,
|
|
|
|
eSSUV6 = 0x08
|
2014-01-26 02:47:01 +00:00
|
|
|
};
|
|
|
|
|
2014-03-19 16:02:51 +00:00
|
|
|
enum Caps
|
|
|
|
{
|
|
|
|
eFloodfill = 0x01,
|
2014-03-19 19:58:57 +00:00
|
|
|
eHighBandwidth = 0x02,
|
2014-04-09 01:56:34 +00:00
|
|
|
eReachable = 0x04,
|
|
|
|
eSSUTesting = 0x08,
|
2014-06-18 14:41:59 +00:00
|
|
|
eSSUIntroducer = 0x10,
|
|
|
|
eHidden = 0x20
|
2014-03-19 16:02:51 +00:00
|
|
|
};
|
|
|
|
|
2013-10-27 15:28:23 +00:00
|
|
|
enum TransportStyle
|
|
|
|
{
|
|
|
|
eTransportUnknown = 0,
|
|
|
|
eTransportNTCP,
|
|
|
|
eTransportSSU
|
|
|
|
};
|
|
|
|
|
2014-02-20 21:15:12 +00:00
|
|
|
struct Introducer
|
|
|
|
{
|
|
|
|
boost::asio::ip::address iHost;
|
|
|
|
int iPort;
|
|
|
|
uint8_t iKey[32];
|
|
|
|
uint32_t iTag;
|
|
|
|
};
|
|
|
|
|
2013-10-27 15:28:23 +00:00
|
|
|
struct Address
|
|
|
|
{
|
|
|
|
TransportStyle transportStyle;
|
2014-01-21 21:07:16 +00:00
|
|
|
boost::asio::ip::address host;
|
2013-10-27 15:28:23 +00:00
|
|
|
int port;
|
|
|
|
uint64_t date;
|
|
|
|
uint8_t cost;
|
2014-02-20 21:15:12 +00:00
|
|
|
// SSU only
|
|
|
|
uint8_t key[32]; // intro key for SSU
|
|
|
|
std::vector<Introducer> introducers;
|
2013-10-27 15:28:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RouterInfo (const char * filename);
|
|
|
|
RouterInfo () = default;
|
|
|
|
RouterInfo (const RouterInfo& ) = default;
|
2013-12-29 15:48:57 +00:00
|
|
|
RouterInfo& operator=(const RouterInfo& ) = default;
|
2013-10-27 15:28:23 +00:00
|
|
|
RouterInfo (const uint8_t * buf, int len);
|
|
|
|
|
2013-12-20 02:19:44 +00:00
|
|
|
const Identity& GetRouterIdentity () const { return m_RouterIdentity; };
|
|
|
|
void SetRouterIdentity (const Identity& identity);
|
2013-11-20 12:46:09 +00:00
|
|
|
const char * GetIdentHashBase64 () const { return m_IdentHashBase64; };
|
2013-11-27 01:59:25 +00:00
|
|
|
const char * GetIdentHashAbbreviation () const { return m_IdentHashAbbreviation; };
|
2013-11-29 12:52:09 +00:00
|
|
|
uint64_t GetTimestamp () const { return m_Timestamp; };
|
2014-02-09 02:06:40 +00:00
|
|
|
std::vector<Address>& GetAddresses () { return m_Addresses; };
|
2014-02-09 13:52:56 +00:00
|
|
|
const Address * GetNTCPAddress (bool v4only = true) const;
|
|
|
|
const Address * GetSSUAddress (bool v4only = true) const;
|
2014-01-04 02:24:20 +00:00
|
|
|
const RoutingKey& GetRoutingKey () const { return m_RoutingKey; };
|
2013-10-27 15:28:23 +00:00
|
|
|
|
|
|
|
void AddNTCPAddress (const char * host, int port);
|
2014-02-23 16:48:09 +00:00
|
|
|
void AddSSUAddress (const char * host, int port, const uint8_t * key);
|
2013-10-27 15:28:23 +00:00
|
|
|
void SetProperty (const char * key, const char * value);
|
|
|
|
const char * GetProperty (const char * key) const;
|
|
|
|
bool IsFloodfill () const;
|
2014-01-22 00:14:30 +00:00
|
|
|
bool IsNTCP (bool v4only = true) const;
|
2014-02-09 02:06:40 +00:00
|
|
|
bool IsSSU (bool v4only = true) const;
|
2014-01-26 02:47:01 +00:00
|
|
|
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
|
2014-02-21 21:13:36 +00:00
|
|
|
bool UsesIntroducer () const;
|
2014-04-09 01:56:34 +00:00
|
|
|
bool IsIntroducer () const { return m_Caps & eSSUIntroducer; };
|
|
|
|
bool IsPeerTesting () const { return m_Caps & eSSUTesting; };
|
2014-06-18 14:41:59 +00:00
|
|
|
bool IsHidden () const { return m_Caps & eHidden; };
|
|
|
|
|
2014-03-19 19:58:57 +00:00
|
|
|
uint8_t GetCaps () const { return m_Caps; };
|
|
|
|
|
2013-12-10 13:10:49 +00:00
|
|
|
void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; };
|
|
|
|
bool IsUnreachable () const { return m_IsUnreachable; };
|
2014-07-10 19:33:42 +00:00
|
|
|
|
|
|
|
const uint8_t * GetBuffer () const { return m_Buffer; };
|
|
|
|
int GetBufferLen () const { return m_BufferLen; };
|
2013-10-27 15:28:23 +00:00
|
|
|
|
|
|
|
void CreateBuffer ();
|
2014-01-04 02:24:20 +00:00
|
|
|
void UpdateRoutingKey ();
|
2013-11-20 12:46:09 +00:00
|
|
|
|
|
|
|
bool IsUpdated () const { return m_IsUpdated; };
|
|
|
|
void SetUpdated (bool updated) { m_IsUpdated = updated; };
|
2014-07-10 19:33:42 +00:00
|
|
|
void SaveToFile (const std::string& fullPath);
|
2013-11-24 23:10:27 +00:00
|
|
|
|
|
|
|
// implements RoutingDestination
|
2013-11-29 12:52:09 +00:00
|
|
|
const IdentHash& GetIdentHash () const { return m_IdentHash; };
|
2013-11-24 23:10:27 +00:00
|
|
|
const uint8_t * GetEncryptionPublicKey () const { return m_RouterIdentity.publicKey; };
|
2013-11-27 01:59:25 +00:00
|
|
|
bool IsDestination () const { return false; };
|
2013-10-27 15:28:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void ReadFromFile (const char * filename);
|
|
|
|
void ReadFromStream (std::istream& s);
|
|
|
|
void ReadFromBuffer ();
|
|
|
|
void WriteToStream (std::ostream& s);
|
|
|
|
size_t ReadString (char * str, std::istream& s);
|
|
|
|
void WriteString (const std::string& str, std::ostream& s);
|
2014-03-19 16:02:51 +00:00
|
|
|
void ExtractCaps (const char * value);
|
2013-12-29 15:48:57 +00:00
|
|
|
void UpdateIdentHashBase64 ();
|
2014-02-09 13:52:56 +00:00
|
|
|
const Address * GetAddress (TransportStyle s, bool v4only) const;
|
2013-10-27 15:28:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2013-12-20 02:19:44 +00:00
|
|
|
Identity m_RouterIdentity;
|
2013-11-29 12:52:09 +00:00
|
|
|
IdentHash m_IdentHash;
|
2014-01-04 02:24:20 +00:00
|
|
|
RoutingKey m_RoutingKey;
|
2013-11-27 01:59:25 +00:00
|
|
|
char m_IdentHashBase64[48], m_IdentHashAbbreviation[5];
|
2014-07-10 19:33:42 +00:00
|
|
|
uint8_t m_Buffer[MAX_RI_BUFFER_SIZE];
|
2013-10-27 15:28:23 +00:00
|
|
|
int m_BufferLen;
|
|
|
|
uint64_t m_Timestamp;
|
|
|
|
std::vector<Address> m_Addresses;
|
|
|
|
std::map<std::string, std::string> m_Properties;
|
2013-12-10 13:10:49 +00:00
|
|
|
bool m_IsUpdated, m_IsUnreachable;
|
2014-03-19 16:02:51 +00:00
|
|
|
uint8_t m_SupportedTransports, m_Caps;
|
2013-10-27 15:28:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|