Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
net_utils_base.cpp
Go to the documentation of this file.
1
2
#include "
net/net_utils_base.h
"
3
4
#include <boost/uuid/uuid_io.hpp>
5
6
#include "
string_tools.h
"
7
#include "
net/local_ip.h
"
8
9
namespace
epee
{
namespace
net_utils
10
{
11
bool
ipv4_network_address::equal
(
const
ipv4_network_address
& other)
const
noexcept
12
{
return
is_same_host
(other) &&
port
() == other.port(); }
13
14
bool
ipv4_network_address::less
(
const
ipv4_network_address
& other)
const
noexcept
15
{
return
is_same_host
(other) ?
port
() < other.port() :
ip
() < other.ip(); }
16
17
std::string
ipv4_network_address::str
()
const
18
{
return
string_tools::get_ip_string_from_int32
(
ip
()) +
":"
+ std::to_string(
port
()); }
19
20
std::string
ipv4_network_address::host_str
()
const
{
return
string_tools::get_ip_string_from_int32
(
ip
()); }
21
bool
ipv4_network_address::is_loopback
()
const
{
return
net_utils::is_ip_loopback
(
ip
()); }
22
bool
ipv4_network_address::is_local
()
const
{
return
net_utils::is_ip_local
(
ip
()); }
23
24
25
bool
network_address::equal
(
const
network_address
& other)
const
26
{
27
// clang typeid workaround
28
network_address::interface
const
*
const
self_ = self.get();
29
network_address::interface
const
*
const
other_self = other.self.get();
30
if
(self_ == other_self)
return
true
;
31
if
(!self_ || !other_self)
return
false
;
32
if
(
typeid
(*self_) !=
typeid
(*other_self))
return
false
;
33
return
self_->equal(*other_self);
34
}
35
36
bool
network_address::less
(
const
network_address
& other)
const
37
{
38
// clang typeid workaround
39
network_address::interface
const
*
const
self_ = self.get();
40
network_address::interface
const
*
const
other_self = other.self.get();
41
if
(self_ == other_self)
return
false
;
42
if
(!self_ || !other_self)
return
self ==
nullptr
;
43
if
(
typeid
(*self_) !=
typeid
(*other_self))
44
return
self_->get_type_id() < other_self->get_type_id();
45
return
self_->less(*other_self);
46
}
47
48
bool
network_address::is_same_host
(
const
network_address
& other)
const
49
{
50
// clang typeid workaround
51
network_address::interface
const
*
const
self_ = self.get();
52
network_address::interface
const
*
const
other_self = other.self.get();
53
if
(self_ == other_self)
return
true
;
54
if
(!self_ || !other_self)
return
false
;
55
if
(
typeid
(*self_) !=
typeid
(*other_self))
return
false
;
56
return
self_->is_same_host(*other_self);
57
}
58
59
std::string
print_connection_context
(
const
connection_context_base
& ctx)
60
{
61
std::stringstream ss;
62
ss << ctx.
m_remote_address
.
str
() <<
" "
<< ctx.
m_connection_id
<< (ctx.
m_is_income
?
" INC"
:
" OUT"
);
63
return
ss.str();
64
}
65
66
std::string
print_connection_context_short
(
const
connection_context_base
& ctx)
67
{
68
std::stringstream ss;
69
ss << ctx.
m_remote_address
.
str
() << (ctx.
m_is_income
?
" INC"
:
" OUT"
);
70
return
ss.str();
71
}
72
73
const
char
*
zone_to_string
(
zone
value
)
noexcept
74
{
75
switch
(
value
)
76
{
77
case
zone::public_
:
78
return
"public"
;
79
case
zone::i2p
:
80
return
"i2p"
;
81
case
zone::tor
:
82
return
"tor"
;
83
default
:
84
break
;
85
}
86
return
"invalid"
;
87
}
88
89
zone
zone_from_string
(
const
boost::string_ref
value
)
noexcept
90
{
91
if
(
value
==
"public"
)
92
return
zone::public_
;
93
if
(
value
==
"i2p"
)
94
return
zone::i2p
;
95
if
(
value
==
"tor"
)
96
return
zone::tor
;
97
return
zone::invalid
;
98
}
99
}}
100
epee::net_utils::ipv4_network_address::is_loopback
bool is_loopback() const
Definition
net_utils_base.cpp:21
epee::net_utils::ipv4_network_address::is_same_host
constexpr bool is_same_host(const ipv4_network_address &other) const noexcept
Definition
net_utils_base.h:78
epee::net_utils::ipv4_network_address::less
bool less(const ipv4_network_address &other) const noexcept
Definition
net_utils_base.cpp:14
epee::net_utils::ipv4_network_address::is_local
bool is_local() const
Definition
net_utils_base.cpp:22
epee::net_utils::ipv4_network_address::port
constexpr uint16_t port() const noexcept
Definition
net_utils_base.h:82
epee::net_utils::ipv4_network_address::ip
constexpr uint32_t ip() const noexcept
Definition
net_utils_base.h:81
epee::net_utils::ipv4_network_address::equal
bool equal(const ipv4_network_address &other) const noexcept
Definition
net_utils_base.cpp:11
epee::net_utils::ipv4_network_address::host_str
std::string host_str() const
Definition
net_utils_base.cpp:20
epee::net_utils::ipv4_network_address::str
std::string str() const
Definition
net_utils_base.cpp:17
epee::net_utils::ipv4_network_address::ipv4_network_address
constexpr ipv4_network_address() noexcept
Definition
net_utils_base.h:69
epee::net_utils::network_address::equal
bool equal(const network_address &other) const
Definition
net_utils_base.cpp:25
epee::net_utils::network_address::str
std::string str() const
Definition
net_utils_base.h:196
epee::net_utils::network_address::less
bool less(const network_address &other) const
Definition
net_utils_base.cpp:36
epee::net_utils::network_address::network_address
network_address()
Definition
net_utils_base.h:189
epee::net_utils::network_address::is_same_host
bool is_same_host(const network_address &other) const
Definition
net_utils_base.cpp:48
local_ip.h
epee::net_utils
Definition
gzip_encoding.h:40
epee::net_utils::zone_from_string
zone zone_from_string(boost::string_ref value) noexcept
Definition
net_utils_base.cpp:89
epee::net_utils::zone_to_string
const char * zone_to_string(zone value) noexcept
Definition
net_utils_base.cpp:73
epee::net_utils::zone
zone
Definition
enums.h:49
epee::net_utils::zone::public_
@ public_
Definition
enums.h:51
epee::net_utils::zone::i2p
@ i2p
Definition
enums.h:52
epee::net_utils::zone::tor
@ tor
Definition
enums.h:53
epee::net_utils::zone::invalid
@ invalid
Definition
enums.h:50
epee::net_utils::is_ip_loopback
bool is_ip_loopback(uint32_t ip)
Definition
local_ip.h:58
epee::net_utils::print_connection_context_short
std::string print_connection_context_short(const connection_context_base &ctx)
Definition
net_utils_base.cpp:66
epee::net_utils::print_connection_context
std::string print_connection_context(const connection_context_base &ctx)
Definition
net_utils_base.cpp:59
epee::net_utils::is_ip_local
bool is_ip_local(uint32_t ip)
Definition
local_ip.h:35
epee::string_tools::get_ip_string_from_int32
std::string get_ip_string_from_int32(uint32_t ip)
Definition
string_tools.cpp:42
epee
Definition
ado_db_helper.h:67
net_utils_base.h
value
const GenericPointer< typename T::ValueType > T2 value
Definition
pointer.h:1225
string_tools.h
epee::net_utils::connection_context_base
Definition
net_utils_base.h:248
epee::net_utils::connection_context_base::m_is_income
const bool m_is_income
Definition
net_utils_base.h:251
epee::net_utils::connection_context_base::m_connection_id
const boost::uuids::uuid m_connection_id
Definition
net_utils_base.h:249
epee::net_utils::connection_context_base::m_remote_address
const network_address m_remote_address
Definition
net_utils_base.h:250
contrib
epee
src
net_utils_base.cpp
Generated on
for Electroneum by
1.17.0