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

b32 i2p address; internal format not condensed/decoded. More...

#include <i2p_address.h>

Public Member Functions

 i2p_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.
 i2p_address (const i2p_address &rhs) noexcept
 ~i2p_address ()=default
i2p_address & operator= (const i2p_address &rhs) noexcept
bool is_unknown () const noexcept
bool equal (const i2p_address &rhs) const noexcept
bool less (const i2p_address &rhs) const noexcept
bool is_same_host (const i2p_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 i2p_address unknown () noexcept
static expect< i2p_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

b32 i2p address; internal format not condensed/decoded.

Definition at line 51 of file i2p_address.h.

Constructor & Destructor Documentation

◆ i2p_address() [1/2]

net::i2p_address::i2p_address ( )
noexcept

An object with port() == 0 and host_str() == unknown_str().

Definition at line 99 of file i2p_address.cpp.

100 : port_(0)
101 {
102 static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size");
103 std::memcpy(host_, unknown_host, sizeof(unknown_host));
104 std::memset(host_ + sizeof(unknown_host), 0, sizeof(host_) - sizeof(unknown_host));
105 }

◆ i2p_address() [2/2]

net::i2p_address::i2p_address ( const i2p_address & rhs)
noexcept

Definition at line 145 of file i2p_address.cpp.

146 : port_(rhs.port_)
147 {
148 std::memcpy(host_, rhs.host_, sizeof(host_));
149 }

◆ ~i2p_address()

net::i2p_address::~i2p_address ( )
default
Here is the call graph for this function:

Member Function Documentation

◆ _load()

bool net::i2p_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 123 of file i2p_address.cpp.

124 {
125 i2p_serialized in{};
126 if (in._load(src, hparent) && in.host.size() < sizeof(host_) && (in.host == unknown_host || !host_check(in.host).has_error()))
127 {
128 std::memcpy(host_, in.host.data(), in.host.size());
129 std::memset(host_ + in.host.size(), 0, sizeof(host_) - in.host.size());
130 port_ = in.port;
131 return true;
132 }
133 static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size");
134 std::memcpy(host_, unknown_host, sizeof(unknown_host)); // include null terminator
135 port_ = 0;
136 return false;
137 }

◆ buffer_size()

constexpr std::size_t net::i2p_address::buffer_size ( )
inlinestaticconstexprnoexcept
Returns
Size of internal buffer for host.

Definition at line 61 of file i2p_address.h.

61{ return sizeof(host_); }
Here is the caller graph for this function:

◆ equal()

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

Definition at line 167 of file i2p_address.cpp.

168 {
169 return port_ == rhs.port_ && is_same_host(rhs);
170 }
bool is_same_host(const i2p_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::i2p_address::get_type_id ( )
inlinestaticconstexprnoexcept

Definition at line 112 of file i2p_address.h.

Here is the caller graph for this function:

◆ get_zone()

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

Definition at line 117 of file i2p_address.h.

118 {
120 }

◆ host_str()

const char * net::i2p_address::host_str ( ) const
inlinenoexcept
Returns
Null-terminated x.b32.i2p value or unknown_str().

Definition at line 104 of file i2p_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::i2p_address::is_blockable ( ) const
inlinenoexcept
Returns
!is_unknown().

Definition at line 123 of file i2p_address.h.

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

◆ is_local()

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

Definition at line 110 of file i2p_address.h.

110{ return false; }

◆ is_loopback()

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

Definition at line 109 of file i2p_address.h.

109{ return false; }

◆ is_same_host()

bool net::i2p_address::is_same_host ( const i2p_address & rhs) const
noexcept
Returns
True if i2p addresses are identical.

Definition at line 177 of file i2p_address.cpp.

178 {
179 return std::strcmp(host_str(), rhs.host_str()) == 0;
180 }
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::i2p_address::is_unknown ( ) const
noexcept
Returns
True if default constructed or via unknown().

Definition at line 161 of file i2p_address.cpp.

162 {
163 static_assert(1 <= sizeof(host_), "host size too small");
164 return host_[0] == '<'; // character is not allowed otherwise
165 }
Here is the caller graph for this function:

◆ less()

bool net::i2p_address::less ( const i2p_address & rhs) const
noexcept

Definition at line 172 of file i2p_address.cpp.

173 {
174 return std::strcmp(host_str(), rhs.host_str()) < 0 || port() < rhs.port();
175 }
std::uint16_t port() const noexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make()

expect< i2p_address > net::i2p_address::make ( boost::string_ref address,
std::uint16_t default_port = 0 )
static

Parse address in b32 i2p format (i.e. x.b32.i2p:80) with default_port being used if port is not specified in address.

Definition at line 107 of file i2p_address.cpp.

108 {
109 boost::string_ref host = address.substr(0, address.rfind(':'));
110 const boost::string_ref port =
111 address.substr(host.size() + (host.size() == address.size() ? 0 : 1));
112
113 ELECTRONEUM_CHECK(host_check(host));
114
115 std::uint16_t porti = default_port;
116 if (!port.empty() && !epee::string_tools::get_xtype_from_string(porti, std::string{port}))
118
119 static_assert(b32_length + sizeof(tld) == sizeof(i2p_address::host_), "bad internal host size");
120 return i2p_address{host, porti};
121 }
#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=()

i2p_address & net::i2p_address::operator= ( const i2p_address & rhs)
noexcept

Definition at line 151 of file i2p_address.cpp.

152 {
153 if (this != std::addressof(rhs))
154 {
155 port_ = rhs.port_;
156 std::memcpy(host_, rhs.host_, sizeof(host_));
157 }
158 return *this;
159 }

◆ port()

std::uint16_t net::i2p_address::port ( ) const
inlinenoexcept
Returns
Port value or 0 if unspecified.

Definition at line 107 of file i2p_address.h.

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

◆ store()

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

Store in epee p2p format.

Definition at line 139 of file i2p_address.cpp.

140 {
141 const i2p_serialized out{std::string{host_}, port_};
142 return out.store(dest, hparent);
143 }
CXA_THROW_INFO_T void(* dest)(void *))

◆ str()

std::string net::i2p_address::str ( ) const
Returns
x.b32.i2p or x.b32.i2p:z if port() != 0.

Definition at line 182 of file i2p_address.cpp.

183 {
184 const std::size_t host_length = std::strlen(host_str());
185 const std::size_t port_length =
186 port_ == 0 ? 0 : std::numeric_limits<std::uint16_t>::digits10 + 2;
187
188 std::string out{};
189 out.reserve(host_length + port_length);
190 out.assign(host_str(), host_length);
191
192 if (port_ != 0)
193 {
194 out.push_back(':');
195 namespace karma = boost::spirit::karma;
196 karma::generate(std::back_inserter(out), karma::ushort_, port());
197 }
198 return out;
199 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unknown()

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

Definition at line 70 of file i2p_address.h.

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

◆ unknown_str()

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

Definition at line 94 of file i2p_address.cpp.

95 {
96 return unknown_host;
97 }
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/i2p_address.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/net/i2p_address.cpp