i2pd/RouterInfo.h

94 lines
2.6 KiB
C
Raw Normal View History

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>
2013-11-24 23:10:27 +00:00
#include "LeaseSet.h"
2013-10-27 15:28:23 +00:00
namespace i2p
{
namespace data
{
2013-11-24 23:10:27 +00:00
class RouterInfo: public RoutingDestination
2013-10-27 15:28:23 +00:00
{
public:
enum TransportStyle
{
eTransportUnknown = 0,
eTransportNTCP,
eTransportSSU
};
struct Address
{
TransportStyle transportStyle;
std::string host;
int port;
uint64_t date;
uint8_t cost;
};
RouterInfo (const char * filename);
RouterInfo () = default;
RouterInfo (const RouterInfo& ) = default;
RouterInfo (const uint8_t * buf, int len);
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; };
const char * GetIdentHashAbbreviation () const { return m_IdentHashAbbreviation; };
2013-11-29 12:52:09 +00:00
uint64_t GetTimestamp () const { return m_Timestamp; };
2013-10-27 15:28:23 +00:00
const std::vector<Address>& GetAddresses () const { return m_Addresses; };
Address * GetNTCPAddress ();
void AddNTCPAddress (const char * host, int port);
void SetProperty (const char * key, const char * value);
const char * GetProperty (const char * key) const;
bool IsFloodfill () const;
bool IsNTCP () const;
2013-12-10 13:10:49 +00:00
void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; };
bool IsUnreachable () const { return m_IsUnreachable; };
2013-10-27 15:28:23 +00:00
void CreateBuffer ();
const char * GetBuffer () const { return m_Buffer; };
int GetBufferLen () const { return m_BufferLen; };
2013-11-20 12:46:09 +00:00
bool IsUpdated () const { return m_IsUpdated; };
void SetUpdated (bool updated) { m_IsUpdated = updated; };
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; };
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);
private:
Identity m_RouterIdentity;
2013-11-29 12:52:09 +00:00
IdentHash m_IdentHash;
char m_IdentHashBase64[48], m_IdentHashAbbreviation[5];
2013-10-27 15:28:23 +00:00
char m_Buffer[2048];
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;
2013-10-27 15:28:23 +00:00
};
}
}
#endif