Electroneum
Loading...
Searching...
No Matches
net_utils_base.cpp
Go to the documentation of this file.
1
3
4#include <boost/uuid/uuid_io.hpp>
5
6#include "string_tools.h"
7#include "net/local_ip.h"
8
9namespace 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
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
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
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
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
constexpr bool is_same_host(const ipv4_network_address &other) const noexcept
bool less(const ipv4_network_address &other) const noexcept
constexpr uint16_t port() const noexcept
constexpr uint32_t ip() const noexcept
bool equal(const ipv4_network_address &other) const noexcept
constexpr ipv4_network_address() noexcept
bool equal(const network_address &other) const
bool less(const network_address &other) const
bool is_same_host(const network_address &other) const
zone zone_from_string(boost::string_ref value) noexcept
const char * zone_to_string(zone value) noexcept
bool is_ip_loopback(uint32_t ip)
Definition local_ip.h:58
std::string print_connection_context_short(const connection_context_base &ctx)
std::string print_connection_context(const connection_context_base &ctx)
bool is_ip_local(uint32_t ip)
Definition local_ip.h:35
std::string get_ip_string_from_int32(uint32_t ip)
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225