Tor onion address; internal format not condensed/decoded.
More...
#include <tor_address.h>
Tor onion address; internal format not condensed/decoded.
Definition at line 51 of file tor_address.h.
◆ tor_address() [1/2]
| net::tor_address::tor_address |
( |
| ) |
|
|
noexcept |
An object with port() == 0 and host_str() == unknown_str().
Definition at line 100 of file tor_address.cpp.
101 : port_(0)
102 {
103 static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size");
104 std::memcpy(host_, unknown_host, sizeof(unknown_host));
105 std::memset(host_ + sizeof(unknown_host), 0, sizeof(host_) - sizeof(unknown_host));
106 }
◆ tor_address() [2/2]
| net::tor_address::tor_address |
( |
const tor_address & | rhs | ) |
|
|
noexcept |
Definition at line 147 of file tor_address.cpp.
148 : port_(rhs.port_)
149 {
150 std::memcpy(host_, rhs.host_, sizeof(host_));
151 }
◆ ~tor_address()
| net::tor_address::~tor_address |
( |
| ) |
|
|
default |
◆ _load()
Load from epee p2p format, and.
- Returns
- false if not valid tor address
Definition at line 125 of file tor_address.cpp.
126 {
128 if (
in._load(src, hparent) &&
in.host.size() <
sizeof(host_) && (
in.host == unknown_host || !host_check(
in.host).has_error()))
129 {
130 std::memcpy(host_,
in.host.data(),
in.host.size());
131 std::memset(host_ +
in.host.size(), 0,
sizeof(host_) -
in.host.size());
133 return true;
134 }
135 static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size");
136 std::memcpy(host_, unknown_host, sizeof(unknown_host));
137 port_ = 0;
138 return false;
139 }
◆ buffer_size()
| constexpr std::size_t net::tor_address::buffer_size |
( |
| ) |
|
|
inlinestaticconstexprnoexcept |
- Returns
- Size of internal buffer for host.
Definition at line 61 of file tor_address.h.
61{ return sizeof(host_); }
◆ equal()
| bool net::tor_address::equal |
( |
const tor_address & | rhs | ) |
const |
|
noexcept |
Definition at line 169 of file tor_address.cpp.
170 {
172 }
bool is_same_host(const tor_address &rhs) const noexcept
◆ get_type_id()
|
|
inlinestaticconstexprnoexcept |
◆ get_zone()
|
|
inlinestaticconstexprnoexcept |
◆ host_str()
| const char * net::tor_address::host_str |
( |
| ) |
const |
|
inlinenoexcept |
◆ is_blockable()
| bool net::tor_address::is_blockable |
( |
| ) |
const |
|
inlinenoexcept |
- Returns
- !is_unknown().
Definition at line 123 of file tor_address.h.
bool is_unknown() const noexcept
◆ is_local()
| constexpr bool net::tor_address::is_local |
( |
| ) |
|
|
inlinestaticconstexprnoexcept |
◆ is_loopback()
| constexpr bool net::tor_address::is_loopback |
( |
| ) |
|
|
inlinestaticconstexprnoexcept |
◆ is_same_host()
| bool net::tor_address::is_same_host |
( |
const tor_address & | rhs | ) |
const |
|
noexcept |
- Returns
- True if onion addresses are identical.
\TODO v2 and v3 should be comparable - requires base32
Definition at line 179 of file tor_address.cpp.
180 {
182 return std::strcmp(
host_str(), rhs.host_str()) == 0;
183 }
const char * host_str() const noexcept
◆ is_unknown()
| bool net::tor_address::is_unknown |
( |
| ) |
const |
|
noexcept |
- Returns
- True if default constructed or via unknown().
Definition at line 163 of file tor_address.cpp.
164 {
165 static_assert(1 <= sizeof(host_), "host size too small");
166 return host_[0] == '<';
167 }
◆ less()
| bool net::tor_address::less |
( |
const tor_address & | rhs | ) |
const |
|
noexcept |
Definition at line 174 of file tor_address.cpp.
175 {
176 return std::strcmp(
host_str(), rhs.host_str()) < 0 ||
port() < rhs.port();
177 }
std::uint16_t port() const noexcept
◆ make()
| expect< tor_address > net::tor_address::make |
( |
boost::string_ref | address, |
|
|
std::uint16_t | default_port = 0 ) |
|
static |
Parse address in onion v2 or v3 format with (i.e. x.onion:80) with default_port being used iff port is not specified in address.
Definition at line 108 of file tor_address.cpp.
109 {
111 const boost::string_ref
port =
112 address.substr(host.size() + (host.size() ==
address.size() ? 0 : 1));
113
115
116 std::uint16_t porti = default_port;
119
120 static_assert(v2_length <= v3_length, "bad internal host size");
121 static_assert(v3_length + sizeof(tld) == sizeof(tor_address::host_), "bad internal host size");
122 return tor_address{host, porti};
123 }
#define ELECTRONEUM_CHECK(...)
Check expect<void> and return errors in current scope.
@ invalid_port
Outside of 0-65535 range.
◆ operator=()
| tor_address & net::tor_address::operator= |
( |
const tor_address & | rhs | ) |
|
|
noexcept |
Definition at line 153 of file tor_address.cpp.
154 {
155 if (this != std::addressof(rhs))
156 {
157 port_ = rhs.port_;
158 std::memcpy(host_, rhs.host_, sizeof(host_));
159 }
160 return *this;
161 }
◆ port()
| std::uint16_t net::tor_address::port |
( |
| ) |
const |
|
inlinenoexcept |
- Returns
- Port value or 0 if unspecified.
Definition at line 107 of file tor_address.h.
◆ store()
Store in epee p2p format.
Definition at line 141 of file tor_address.cpp.
142 {
143 const tor_serialized
out{std::string{host_}, port_};
144 return out.store(
dest, hparent);
145 }
CXA_THROW_INFO_T void(* dest)(void *))
◆ str()
| std::string net::tor_address::str |
( |
| ) |
const |
- Returns
- x.onion or x.onion:z if port() != 0.
Definition at line 185 of file tor_address.cpp.
186 {
187 const std::size_t host_length = std::strlen(
host_str());
188 const std::size_t port_length =
189 port_ == 0 ? 0 : std::numeric_limits<std::uint16_t>::digits10 + 2;
190
192 out.reserve(host_length + port_length);
194
195 if (port_ != 0)
196 {
198 namespace karma = boost::spirit::karma;
199 karma::generate(std::back_inserter(out), karma::ushort_,
port());
200 }
202 }
◆ unknown()
| tor_address net::tor_address::unknown |
( |
| ) |
|
|
inlinestaticnoexcept |
◆ unknown_str()
| const char * net::tor_address::unknown_str |
( |
| ) |
|
|
staticnoexcept |
The documentation for this class was generated from the following files:
- /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/net/tor_address.h
- /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/net/tor_address.cpp