23#include "util/rats_export.h"
24#include "core/ip_address.h"
39 Address(IpAddress ip, uint16_t port) : ip(ip), port(port) {}
45 Address(std::string_view numeric_ip, uint16_t port);
51 static std::optional<Address>
parse(std::string_view text);
57 bool is_valid() const noexcept {
return !ip.is_unspecified() && port != 0; }
62 return ip != o.ip ? ip < o.ip : port < o.port;
73 std::size_t h = a.ip.hash();
74 h ^= (
static_cast<std::size_t
>(a.port) + 0x9e3779b97f4a7c15ull + (h << 6) + (h >> 2));
Address(IpAddress ip, uint16_t port)
Address(std::string_view numeric_ip, uint16_t port)
Build from a numeric IP literal + port.
std::string to_string() const
IPv6 endpoints serialise bracketed; everything else plain. "" ip → ":port".
bool operator!=(const Address &o) const noexcept
bool operator<(const Address &o) const noexcept
static std::optional< Address > parse(std::string_view text)
Parse "host:port" or "[ipv6]:port".
bool operator==(const Address &o) const noexcept
bool is_valid() const noexcept
A usable dial target: a specified ip and a non-zero port.
std::size_t operator()(const librats::Address &a) const noexcept