Electroneum
Loading...
Searching...
No Matches
net::tor_address Class Reference

Tor onion address; internal format not condensed/decoded. More...

#include <tor_address.h>

Public Member Functions

 tor_address () noexcept
 An object with port() == 0 and host_str() == unknown_str().
bool _load (epee::serialization::portable_storage &src, epee::serialization::section *hparent)
 Load from epee p2p format, and.
bool store (epee::serialization::portable_storage &dest, epee::serialization::section *hparent) const
 Store in epee p2p format.
 tor_address (const tor_address &rhs) noexcept
 ~tor_address ()=default
tor_address & operator= (const tor_address &rhs) noexcept
bool is_unknown () const noexcept
bool equal (const tor_address &rhs) const noexcept
bool less (const tor_address &rhs) const noexcept
bool is_same_host (const tor_address &rhs) const noexcept
std::string str () const
const char * host_str () const noexcept
std::uint16_t port () const noexcept
bool is_blockable () const noexcept

Static Public Member Functions

static constexpr std::size_t buffer_size () noexcept
static const char * unknown_str () noexcept
static tor_address unknown () noexcept
static expect< tor_address > make (boost::string_ref address, std::uint16_t default_port=0)
static constexpr bool is_loopback () noexcept
static constexpr bool is_local () noexcept
static constexpr epee::net_utils::address_type get_type_id () noexcept
static constexpr epee::net_utils::zone get_zone () noexcept

Detailed Description

Tor onion address; internal format not condensed/decoded.

Definition at line 51 of file tor_address.h.

Constructor & Destructor Documentation

◆ 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
Here is the call graph for this function:

Member Function Documentation

◆ _load()

bool net::tor_address::_load ( epee::serialization::portable_storage & src,
epee::serialization::section * hparent )

Load from epee p2p format, and.

Returns
false if not valid tor address

Definition at line 125 of file tor_address.cpp.

126 {
127 tor_serialized in{};
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());
132 port_ = in.port;
133 return true;
134 }
135 static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size");
136 std::memcpy(host_, unknown_host, sizeof(unknown_host)); // include null terminator
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_); }
Here is the caller graph for this function:

◆ equal()

bool net::tor_address::equal ( const tor_address & rhs) const
noexcept

Definition at line 169 of file tor_address.cpp.

170 {
171 return port_ == rhs.port_ && is_same_host(rhs);
172 }
bool is_same_host(const tor_address &rhs) const noexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_type_id()

constexpr epee::net_utils::address_type net::tor_address::get_type_id ( )
inlinestaticconstexprnoexcept

Definition at line 112 of file tor_address.h.

Here is the caller graph for this function:

◆ get_zone()

constexpr epee::net_utils::zone net::tor_address::get_zone ( )
inlinestaticconstexprnoexcept

Definition at line 117 of file tor_address.h.

118 {
120 }

◆ host_str()

const char * net::tor_address::host_str ( ) const
inlinenoexcept
Returns
Null-terminated x.onion value or unknown_str().

Definition at line 104 of file tor_address.h.

104{ return host_; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_blockable()

bool net::tor_address::is_blockable ( ) const
inlinenoexcept
Returns
!is_unknown().

Definition at line 123 of file tor_address.h.

123{ return !is_unknown(); }
bool is_unknown() const noexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_local()

constexpr bool net::tor_address::is_local ( )
inlinestaticconstexprnoexcept

Definition at line 110 of file tor_address.h.

110{ return false; }
Here is the caller graph for this function:

◆ is_loopback()

constexpr bool net::tor_address::is_loopback ( )
inlinestaticconstexprnoexcept

Definition at line 109 of file tor_address.h.

109{ return false; }
Here is the caller graph for this function:

◆ 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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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] == '<'; // character is not allowed otherwise
167 }
Here is the caller graph for this function:

◆ 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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 {
110 boost::string_ref host = address.substr(0, address.rfind(':'));
111 const boost::string_ref port =
112 address.substr(host.size() + (host.size() == address.size() ? 0 : 1));
113
114 ELECTRONEUM_CHECK(host_check(host));
115
116 std::uint16_t porti = default_port;
117 if (!port.empty() && !epee::string_tools::get_xtype_from_string(porti, std::string{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.
Definition expect.h:47
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
@ invalid_port
Outside of 0-65535 range.
Definition error.h:43
const char * address
Definition multisig.cpp:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

107{ return port_; }
Here is the caller graph for this function:

◆ store()

bool net::tor_address::store ( epee::serialization::portable_storage & dest,
epee::serialization::section * hparent ) const

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
191 std::string out{};
192 out.reserve(host_length + port_length);
193 out.assign(host_str(), host_length);
194
195 if (port_ != 0)
196 {
197 out.push_back(':');
198 namespace karma = boost::spirit::karma;
199 karma::generate(std::back_inserter(out), karma::ushort_, port());
200 }
201 return out;
202 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unknown()

tor_address net::tor_address::unknown ( )
inlinestaticnoexcept
Returns
A default constructed tor_address object.

Definition at line 70 of file tor_address.h.

70{ return tor_address{}; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unknown_str()

const char * net::tor_address::unknown_str ( )
staticnoexcept
Returns
<unknown tor host>.

Definition at line 95 of file tor_address.cpp.

96 {
97 return unknown_host;
98 }
Here is the caller graph for this function:

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