Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
tor_address.h
Go to the documentation of this file.
1
// Copyright (c) 2018, The Monero Project
2
//
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without modification, are
6
// permitted provided that the following conditions are met:
7
//
8
// 1. Redistributions of source code must retain the above copyright notice, this list of
9
// conditions and the following disclaimer.
10
//
11
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12
// of conditions and the following disclaimer in the documentation and/or other
13
// materials provided with the distribution.
14
//
15
// 3. Neither the name of the copyright holder nor the names of its contributors may be
16
// used to endorse or promote products derived from this software without specific
17
// prior written permission.
18
//
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
#pragma once
30
31
#include <boost/utility/string_ref.hpp>
32
#include <cstdint>
33
#include <string>
34
35
#include "
common/expect.h
"
36
#include "
net/enums.h
"
37
#include "
net/error.h
"
38
39
namespace
epee
40
{
41
namespace
serialization
42
{
43
class
portable_storage
;
44
struct
section
;
45
}
46
}
47
48
namespace
net
49
{
51
class
tor_address
52
{
53
std::uint16_t port_;
54
char
host_[63];
// null-terminated
55
57
tor_address
(boost::string_ref host, std::uint16_t
port
)
noexcept
;
58
59
public
:
61
static
constexpr
std::size_t
buffer_size
() noexcept {
return
sizeof
(host_); }
62
64
static
const
char
*
unknown_str
() noexcept;
65
67
tor_address
() noexcept;
68
70
static tor_address
unknown
() noexcept {
return
tor_address{}; }
71
77
static
expect<tor_address>
make
(boost::string_ref
address
, std::uint16_t default_port = 0);
78
80
bool
_load
(
epee::serialization::portable_storage
& src,
epee::serialization::section
* hparent);
81
83
bool
store
(
epee::serialization::portable_storage
&
dest
,
epee::serialization::section
* hparent)
const
;
84
85
// Moves and copies are currently identical
86
87
tor_address
(
const
tor_address
& rhs)
noexcept
;
88
~tor_address
() =
default
;
89
tor_address&
operator=
(
const
tor_address& rhs)
noexcept
;
90
92
bool
is_unknown
() const noexcept;
93
94
bool
equal
(const tor_address& rhs) const noexcept;
95
bool
less
(const tor_address& rhs) const noexcept;
96
98
bool
is_same_host
(const tor_address& rhs) const noexcept;
99
101
std
::
string
str
() const;
102
104
const
char
*
host_str
() const noexcept {
return
host_; }
105
107
std::uint16_t
port
() const noexcept {
return
port_; }
108
109
static
constexpr
bool
is_loopback
() noexcept {
return
false
; }
110
static
constexpr
bool
is_local
() noexcept {
return
false
; }
111
112
static
constexpr
epee::net_utils::address_type
get_type_id
() noexcept
113
{
114
return
epee::net_utils::address_type::tor
;
115
}
116
117
static
constexpr
epee::net_utils::zone
get_zone
() noexcept
118
{
119
return
epee::net_utils::zone::tor
;
120
}
121
123
bool
is_blockable
() const noexcept {
return
!
is_unknown
(); }
124
};
125
126
inline
bool
operator==
(
const
tor_address
& lhs,
const
tor_address
& rhs)
noexcept
127
{
128
return
lhs.equal(rhs);
129
}
130
131
inline
bool
operator!=
(
const
tor_address
& lhs,
const
tor_address
& rhs)
noexcept
132
{
133
return
!lhs.equal(rhs);
134
}
135
136
inline
bool
operator<
(
const
tor_address
& lhs,
const
tor_address
& rhs)
noexcept
137
{
138
return
lhs.less(rhs);
139
}
140
}
// net
epee::serialization::portable_storage
Definition
portable_storage.h:51
expect
Definition
expect.h:133
net::tor_address
Tor onion address; internal format not condensed/decoded.
Definition
tor_address.h:52
net::tor_address::~tor_address
~tor_address()=default
net::tor_address::_load
bool _load(epee::serialization::portable_storage &src, epee::serialization::section *hparent)
Load from epee p2p format, and.
Definition
tor_address.cpp:125
net::tor_address::make
static expect< tor_address > make(boost::string_ref address, std::uint16_t default_port=0)
Definition
tor_address.cpp:108
net::tor_address::buffer_size
static constexpr std::size_t buffer_size() noexcept
Definition
tor_address.h:61
net::tor_address::is_local
static constexpr bool is_local() noexcept
Definition
tor_address.h:110
net::tor_address::less
bool less(const tor_address &rhs) const noexcept
Definition
tor_address.cpp:174
net::tor_address::unknown_str
static const char * unknown_str() noexcept
Definition
tor_address.cpp:95
net::tor_address::equal
bool equal(const tor_address &rhs) const noexcept
Definition
tor_address.cpp:169
net::tor_address::str
std::string str() const
Definition
tor_address.cpp:185
net::tor_address::get_zone
static constexpr epee::net_utils::zone get_zone() noexcept
Definition
tor_address.h:117
net::tor_address::get_type_id
static constexpr epee::net_utils::address_type get_type_id() noexcept
Definition
tor_address.h:112
net::tor_address::is_loopback
static constexpr bool is_loopback() noexcept
Definition
tor_address.h:109
net::tor_address::store
bool store(epee::serialization::portable_storage &dest, epee::serialization::section *hparent) const
Store in epee p2p format.
Definition
tor_address.cpp:141
net::tor_address::operator=
tor_address & operator=(const tor_address &rhs) noexcept
Definition
tor_address.cpp:153
net::tor_address::is_unknown
bool is_unknown() const noexcept
Definition
tor_address.cpp:163
net::tor_address::host_str
const char * host_str() const noexcept
Definition
tor_address.h:104
net::tor_address::port
std::uint16_t port() const noexcept
Definition
tor_address.h:107
net::tor_address::tor_address
tor_address() noexcept
An object with port() == 0 and host_str() == unknown_str().
Definition
tor_address.cpp:100
net::tor_address::is_blockable
bool is_blockable() const noexcept
Definition
tor_address.h:123
net::tor_address::unknown
static tor_address unknown() noexcept
Definition
tor_address.h:70
net::tor_address::is_same_host
bool is_same_host(const tor_address &rhs) const noexcept
Definition
tor_address.cpp:179
enums.h
expect.h
epee::net_utils::address_type
address_type
Definition
enums.h:39
epee::net_utils::address_type::tor
@ tor
Definition
enums.h:45
epee::net_utils::zone
zone
Definition
enums.h:49
epee::net_utils::zone::tor
@ tor
Definition
enums.h:53
epee::serialization
Definition
keyvalue_serialization_overloads.h:47
epee
Definition
ado_db_helper.h:67
net
Definition
net_utils_base.h:54
net::operator<
bool operator<(const i2p_address &lhs, const i2p_address &rhs) noexcept
Definition
i2p_address.h:136
net::operator!=
bool operator!=(const i2p_address &lhs, const i2p_address &rhs) noexcept
Definition
i2p_address.h:131
net::operator==
bool operator==(const i2p_address &lhs, const i2p_address &rhs) noexcept
Definition
i2p_address.h:126
std
STL namespace.
error.h
dest
CXA_THROW_INFO_T void(* dest)(void *))
Definition
stack_trace.cpp:91
epee::serialization::section
Definition
portable_storage_base.h:162
address
const char * address
Definition
multisig.cpp:37
src
net
tor_address.h
Generated on
for Electroneum by
1.17.0