| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#pragma once |
| 31 |
|
| 32 |
#include <boost/utility/string_ref.hpp> |
| 33 |
#include <cstdint> |
| 34 |
#include <string> |
| 35 |
|
| 36 |
#include "common/expect.h" |
| 37 |
#include "net/enums.h" |
| 38 |
#include "net/error.h" |
| 39 |
|
| 40 |
namespace epee |
| 41 |
{ |
| 42 |
namespace serialization |
| 43 |
{ |
| 44 |
class portable_storage; |
| 45 |
struct section; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
namespace net |
| 50 |
{ |
| 51 |
|
| 52 |
class tor_address |
| 53 |
{ |
| 54 |
std::uint16_t port_; |
| 55 |
char host_[63]; |
| 56 |
|
| 57 |
|
| 58 |
tor_address(boost::string_ref host, std::uint16_t port) noexcept; |
| 59 |
|
| 60 |
public: |
| 61 |
|
| 62 |
static constexpr std::size_t buffer_size() noexcept { return sizeof(host_); } |
| 63 |
|
| 64 |
|
| 65 |
static const char* unknown_str() noexcept; |
| 66 |
|
| 67 |
|
| 68 |
tor_address() noexcept; |
| 69 |
|
| 70 |
|
| 71 |
static tor_address unknown() noexcept { return tor_address{}; } |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
static expect<tor_address> make(boost::string_ref address, std::uint16_t default_port = 0); |
| 79 |
|
| 80 |
|
| 81 |
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent); |
| 82 |
|
| 83 |
|
| 84 |
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
tor_address(const tor_address& rhs) noexcept; |
| 89 |
~tor_address() = default; |
| 90 |
tor_address& operator=(const tor_address& rhs) noexcept; |
| 91 |
|
| 92 |
|
| 93 |
bool is_unknown() const noexcept; |
| 94 |
|
| 95 |
bool equal(const tor_address& rhs) const noexcept; |
| 96 |
bool less(const tor_address& rhs) const noexcept; |
| 97 |
|
| 98 |
|
| 99 |
bool is_same_host(const tor_address& rhs) const noexcept; |
| 100 |
|
| 101 |
|
| 102 |
std::string str() const; |
| 103 |
|
| 104 |
|
| 105 |
const char* host_str() const noexcept { return host_; } |
| 106 |
|
| 107 |
|
| 108 |
std::uint16_t port() const noexcept { return port_; } |
| 109 |
|
| 110 |
static constexpr bool is_loopback() noexcept { return false; } |
| 111 |
static constexpr bool is_local() noexcept { return false; } |
| 112 |
|
| 113 |
static constexpr epee::net_utils::address_type get_type_id() noexcept |
| 114 |
{ |
| 115 |
return epee::net_utils::address_type::tor; |
| 116 |
} |
| 117 |
|
| 118 |
static constexpr epee::net_utils::zone get_zone() noexcept |
| 119 |
{ |
| 120 |
return epee::net_utils::zone::tor; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
bool is_blockable() const noexcept { return !is_unknown(); } |
| 125 |
}; |
| 126 |
|
| 127 |
inline bool operator==(const tor_address& lhs, const tor_address& rhs) noexcept |
| 128 |
{ |
| 129 |
return lhs.equal(rhs); |
| 130 |
} |
| 131 |
|
| 132 |
inline bool operator!=(const tor_address& lhs, const tor_address& rhs) noexcept |
| 133 |
{ |
| 134 |
return !lhs.equal(rhs); |
| 135 |
} |
| 136 |
|
| 137 |
inline bool operator<(const tor_address& lhs, const tor_address& rhs) noexcept |
| 138 |
{ |
| 139 |
return lhs.less(rhs); |
| 140 |
} |
| 141 |
} |