Electroneum
Loading...
Searching...
No Matches
net Namespace Reference

Namespaces

namespace  socks
namespace  zmq

Classes

class  i2p_address
 b32 i2p address; internal format not condensed/decoded. More...
class  tor_address
 Tor onion address; internal format not condensed/decoded. More...

Enumerations

enum class  error : int {
  expected_tld = 1 , invalid_host , invalid_i2p_address , invalid_port ,
  invalid_tor_address , unsupported_address
}
 General net errors. More...

Functions

std::error_category const & error_category () noexcept
std::error_code make_error_code (error value) noexcept
bool operator== (const i2p_address &lhs, const i2p_address &rhs) noexcept
bool operator!= (const i2p_address &lhs, const i2p_address &rhs) noexcept
bool operator< (const i2p_address &lhs, const i2p_address &rhs) noexcept
expect< epee::net_utils::network_addressget_network_address (const boost::string_ref address, const std::uint16_t default_port)
bool operator== (const tor_address &lhs, const tor_address &rhs) noexcept
bool operator!= (const tor_address &lhs, const tor_address &rhs) noexcept
bool operator< (const tor_address &lhs, const tor_address &rhs) noexcept

Enumeration Type Documentation

◆ error

enum class net::error : int
strong

General net errors.

Enumerator
expected_tld 

Expected a tld.

invalid_host 

Hostname is not valid.

invalid_i2p_address 
invalid_port 

Outside of 0-65535 range.

invalid_tor_address 

Invalid base32 or length.

unsupported_address 

Type not supported by get_network_address.

Definition at line 37 of file error.h.

38 {
39 // 0 reserved for success (as per expect<T>)
40 expected_tld = 1,
46 };
@ invalid_port
Outside of 0-65535 range.
Definition error.h:43
@ invalid_tor_address
Invalid base32 or length.
Definition error.h:44
@ unsupported_address
Type not supported by get_network_address.
Definition error.h:45
@ expected_tld
Expected a tld.
Definition error.h:40
@ invalid_i2p_address
Definition error.h:42
@ invalid_host
Hostname is not valid.
Definition error.h:41

Function Documentation

◆ error_category()

std::error_category const & net::error_category ( )
noexcept
Returns
std::error_category for net namespace.

Definition at line 87 of file error.cpp.

88 {
89 static const net_category instance{};
90 return instance;
91 }
Here is the caller graph for this function:

◆ get_network_address()

expect< epee::net_utils::network_address > net::get_network_address ( boost::string_ref address,
std::uint16_t default_port )

Identifies onion, i2p and IPv4 addresses and returns them as a generic network_address. If the type is unsupported, it might be a hostname, and error() == net::error::kUnsupportedAddress is returned.

Parameters
addressAn onion address, i2p address, ipv4 address or hostname. Hostname will return an error.
default_portIf address does not specify a port, this value will be used.
Returns
A tor or IPv4 address, else error.

Definition at line 38 of file parse.cpp.

39 {
40 const boost::string_ref host = address.substr(0, address.rfind(':'));
41
42 if (host.empty())
44 if (host.ends_with(".onion"))
45 return tor_address::make(address, default_port);
46 if (host.ends_with(".i2p"))
47 return i2p_address::make(address, default_port);
48
49 std::uint16_t port = default_port;
50 if (host.size() < address.size())
51 {
52 if (!epee::string_tools::get_xtype_from_string(port, std::string{address.substr(host.size() + 1)}))
54 }
55
56 std::uint32_t ip = 0;
57 if (epee::string_tools::get_ip_int32_from_string(ip, std::string{host}))
58 return {epee::net_utils::ipv4_network_address{ip, port}};
60 }
static expect< i2p_address > make(boost::string_ref address, std::uint16_t default_port=0)
static expect< tor_address > make(boost::string_ref address, std::uint16_t default_port=0)
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
std::error_code make_error_code(error value) noexcept
Definition error.h:52
const char * address
Definition multisig.cpp:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_error_code()

std::error_code net::make_error_code ( error value)
inlinenoexcept
Returns
net::error as a std::error_code value.

Definition at line 52 of file error.h.

53 {
54 return std::error_code{int(value), error_category()};
55 }
std::error_category const & error_category() noexcept
Definition error.cpp:87
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=() [1/2]

bool net::operator!= ( const i2p_address & lhs,
const i2p_address & rhs )
inlinenoexcept

Definition at line 131 of file i2p_address.h.

132 {
133 return !lhs.equal(rhs);
134 }
bool equal(const i2p_address &rhs) const noexcept

◆ operator!=() [2/2]

bool net::operator!= ( const tor_address & lhs,
const tor_address & rhs )
inlinenoexcept

Definition at line 131 of file tor_address.h.

132 {
133 return !lhs.equal(rhs);
134 }
bool equal(const tor_address &rhs) const noexcept

◆ operator<() [1/2]

bool net::operator< ( const i2p_address & lhs,
const i2p_address & rhs )
inlinenoexcept

Definition at line 136 of file i2p_address.h.

137 {
138 return lhs.less(rhs);
139 }
bool less(const i2p_address &rhs) const noexcept

◆ operator<() [2/2]

bool net::operator< ( const tor_address & lhs,
const tor_address & rhs )
inlinenoexcept

Definition at line 136 of file tor_address.h.

137 {
138 return lhs.less(rhs);
139 }
bool less(const tor_address &rhs) const noexcept

◆ operator==() [1/2]

bool net::operator== ( const i2p_address & lhs,
const i2p_address & rhs )
inlinenoexcept

Definition at line 126 of file i2p_address.h.

127 {
128 return lhs.equal(rhs);
129 }

◆ operator==() [2/2]

bool net::operator== ( const tor_address & lhs,
const tor_address & rhs )
inlinenoexcept

Definition at line 126 of file tor_address.h.

127 {
128 return lhs.equal(rhs);
129 }