2018-08-30 18:48:43 +00:00
|
|
|
#ifndef LLARP_AI_HPP
|
|
|
|
#define LLARP_AI_HPP
|
2018-12-11 23:58:58 +00:00
|
|
|
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <bencode.hpp>
|
|
|
|
#include <crypto.h>
|
2018-12-12 00:38:58 +00:00
|
|
|
#include <crypto.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <mem.h>
|
|
|
|
#include <net.h>
|
2018-08-30 18:48:43 +00:00
|
|
|
|
|
|
|
#include <string>
|
2018-12-11 23:58:58 +00:00
|
|
|
#include <vector>
|
2018-12-12 00:38:58 +00:00
|
|
|
#include <stdbool.h>
|
2018-08-30 18:48:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* address_info.hpp
|
|
|
|
*
|
|
|
|
* utilities for handling addresses on the llarp network
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// address information model
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-11-05 11:27:12 +00:00
|
|
|
struct AddressInfo final : 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);
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const override;
|
2018-08-30 18:48:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override;
|
2018-08-31 12:46:54 +00:00
|
|
|
|
|
|
|
friend std::ostream&
|
|
|
|
operator<<(std::ostream& out, const AddressInfo& a)
|
|
|
|
{
|
|
|
|
char tmp[128] = {0};
|
2018-11-09 14:48:43 +00:00
|
|
|
inet_ntop(AF_INET6, (void*)&a.ip, tmp, sizeof(tmp));
|
2018-11-06 14:06:09 +00:00
|
|
|
out << tmp << ".";
|
2018-11-08 12:31:50 +00:00
|
|
|
#if defined(ANDROID) || defined(RPI)
|
2018-11-06 14:06:09 +00:00
|
|
|
snprintf(tmp, sizeof(tmp), "%u", a.port);
|
|
|
|
return out << tmp;
|
|
|
|
#else
|
|
|
|
return out << std::to_string(a.port);
|
|
|
|
#endif
|
2018-08-31 12:46:54 +00:00
|
|
|
}
|
2018-09-04 12:41:25 +00:00
|
|
|
|
|
|
|
struct Hash
|
|
|
|
{
|
|
|
|
size_t
|
|
|
|
operator()(const AddressInfo& addr) const
|
|
|
|
{
|
2018-12-20 14:18:03 +00:00
|
|
|
return AlignedBuffer< PUBKEYSIZE >::Hash()(addr.pubkey);
|
2018-09-04 12:41:25 +00:00
|
|
|
}
|
|
|
|
};
|
2018-08-30 18:48:43 +00:00
|
|
|
};
|
|
|
|
|
2018-12-12 00:26:37 +00:00
|
|
|
bool
|
|
|
|
operator==(const AddressInfo& lhs, const AddressInfo& rhs);
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator<(const AddressInfo& lhs, const AddressInfo& rhs);
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|