Electroneum
net Namespace Reference

Namespaces

 socks
 
 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  error : int {
  error::expected_tld = 1, error::invalid_host, error::invalid_i2p_address, error::invalid_port,
  error::invalid_tor_address, error::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 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.

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

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;
60  }
Type not supported by get_network_address
::std::string string
Definition: gtest-port.h:1097
std::error_code make_error_code(::common_error value) noexcept
Definition: error.h:41
unsigned short uint16_t
Definition: stdint.h:125
Hostname is not valid.
unsigned int uint32_t
Definition: stdint.h:126
boost::endian::big_uint32_t ip
Definition: socks.cpp:61
boost::endian::big_uint16_t port
Definition: socks.cpp:60
const char * address
Definition: multisig.cpp:37
Outside of 0-65535 range.
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
Definition: string_tools.h:125
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
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:92
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 tor_address lhs,
const tor_address rhs 
)
inlinenoexcept

Definition at line 131 of file tor_address.h.

132  {
133  return !lhs.equal(rhs);
134  }

◆ operator!=() [2/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  }

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

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

◆ operator==() [1/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  }

◆ operator==() [2/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  }