lokinet/include/llarp/address_info.hpp

81 lines
1.5 KiB
C++
Raw Normal View History

2018-08-30 18:48:43 +00:00
#ifndef LLARP_AI_HPP
#define LLARP_AI_HPP
#include <llarp/mem.h>
#include <llarp/net.h>
#include <stdbool.h>
2018-08-31 12:46:54 +00:00
#include <llarp/bencode.hpp>
2018-08-30 18:48:43 +00:00
#include <llarp/crypto.hpp>
#include <string>
/**
* address_info.hpp
*
* utilities for handling addresses on the llarp network
*/
/// address information model
namespace llarp
{
2018-08-31 12:46:54 +00:00
struct AddressInfo : public IBEncodeMessage
2018-08-30 18:48:43 +00:00
{
uint16_t rank;
std::string dialect;
llarp::PubKey pubkey;
struct in6_addr ip;
uint16_t port;
2018-09-06 11:46:19 +00:00
AddressInfo() : IBEncodeMessage()
{
}
AddressInfo(const AddressInfo& other)
: IBEncodeMessage()
, rank(other.rank)
, dialect(other.dialect)
, pubkey(other.pubkey)
{
port = other.port;
version = other.version;
memcpy(ip.s6_addr, other.ip.s6_addr, 16);
}
2018-08-31 12:46:54 +00:00
~AddressInfo();
2018-08-31 13:51:24 +00:00
AddressInfo&
operator=(const AddressInfo& other);
bool
operator==(const AddressInfo& other) const;
bool
operator<(const AddressInfo& other) const;
2018-08-30 18:48:43 +00:00
bool
2018-08-31 12:46:54 +00:00
BEncode(llarp_buffer_t* buf) const;
2018-08-30 18:48:43 +00:00
bool
2018-08-31 12:46:54 +00:00
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf);
friend std::ostream&
operator<<(std::ostream& out, const AddressInfo& a)
{
char tmp[128] = {0};
inet_ntop(AF_INET6, &a.ip, tmp, sizeof(tmp));
return out << tmp << "." << std::to_string(a.port);
}
struct Hash
{
size_t
operator()(const AddressInfo& addr) const
{
return *addr.pubkey.data_l();
}
};
2018-08-30 18:48:43 +00:00
};
} // namespace llarp
#endif