lokinet/llarp/net/address_info.hpp

83 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
2018-12-11 23:58:58 +00:00
#include <crypto/types.hpp>
#include <net/net.h>
#include <util/bencode.hpp>
#include <util/mem.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
{
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)
2019-01-17 15:11:17 +00:00
: IBEncodeMessage(other.version)
2018-09-06 11:46:19 +00:00
, rank(other.rank)
, dialect(other.dialect)
, pubkey(other.pubkey)
2019-01-17 15:11:17 +00:00
, port(other.port)
2018-09-06 11:46:19 +00:00
{
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
BEncode(llarp_buffer_t* buf) const override;
2018-08-30 18:48:43 +00:00
bool
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf) override;
2018-08-31 12:46:54 +00:00
2019-02-24 23:46:37 +00:00
std::ostream&
print(std::ostream& stream, int level, int spaces) const;
struct Hash
{
size_t
operator()(const AddressInfo& addr) const
{
return AlignedBuffer< PUBKEYSIZE >::Hash()(addr.pubkey);
}
};
2018-08-30 18:48:43 +00:00
};
2019-02-24 23:46:37 +00:00
inline std::ostream&
operator<<(std::ostream& out, const AddressInfo& a)
{
return a.print(out, -1, -1);
}
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