2018-08-30 18:48:43 +00:00
|
|
|
#ifndef LLARP_AI_HPP
|
|
|
|
#define LLARP_AI_HPP
|
2018-12-11 23:58:58 +00:00
|
|
|
|
2019-01-13 16:30:07 +00:00
|
|
|
#include <crypto/types.hpp>
|
2019-01-11 01:42:02 +00:00
|
|
|
#include <net/net.h>
|
2019-01-10 19:41:51 +00:00
|
|
|
#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-08-30 18:48:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* address_info.hpp
|
|
|
|
*
|
|
|
|
* utilities for handling addresses on the llarp network
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// address information model
|
|
|
|
namespace llarp
|
|
|
|
{
|
2019-05-24 02:01:36 +00:00
|
|
|
struct AddressInfo
|
2018-08-30 18:48:43 +00:00
|
|
|
{
|
|
|
|
uint16_t rank;
|
|
|
|
std::string dialect;
|
|
|
|
llarp::PubKey pubkey;
|
|
|
|
struct in6_addr ip;
|
|
|
|
uint16_t port;
|
2019-05-24 02:01:36 +00:00
|
|
|
uint64_t version = LLARP_PROTO_VERSION;
|
2018-08-30 18:48:43 +00:00
|
|
|
|
2019-05-24 02:01:36 +00:00
|
|
|
bool
|
|
|
|
BDecode(llarp_buffer_t* buf)
|
2018-09-06 11:46:19 +00:00
|
|
|
{
|
2019-05-24 02:01:36 +00:00
|
|
|
return bencode_decode_dict(*this, buf);
|
2018-09-06 11:46:19 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
bool
|
2019-05-24 02:01:36 +00:00
|
|
|
BEncode(llarp_buffer_t* buf) const;
|
2018-08-30 18:48:43 +00:00
|
|
|
|
|
|
|
bool
|
2019-05-24 02:01:36 +00:00
|
|
|
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf);
|
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;
|
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
|
|
|
};
|
|
|
|
|
2019-08-19 22:25:40 +00:00
|
|
|
void
|
|
|
|
to_json(nlohmann::json& j, const AddressInfo& a);
|
|
|
|
|
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
|