29 #ifndef _NET_UTILS_BASE_H_ 30 #define _NET_UTILS_BASE_H_ 32 #include <boost/uuid/uuid.hpp> 33 #include <boost/asio/io_service.hpp> 34 #include <boost/asio/ip/address_v6.hpp> 36 #include <type_traits> 43 #undef MONERO_DEFAULT_LOG_CATEGORY 44 #define MONERO_DEFAULT_LOG_CATEGORY "net" 47 #define MAKE_IP( a1, a2, a3, a4 ) (a1|(a2<<8)|(a3<<16)|(((uint32_t)a4)<<24)) 50 #if BOOST_VERSION >= 107000 51 #define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context()) 53 #define GET_IO_SERVICE(s) ((s).get_io_service()) 82 {
return ip() == other.ip(); }
110 {
return lhs.equal(rhs); }
112 {
return !lhs.equal(rhs); }
114 {
return lhs.less(rhs); }
116 {
return !rhs.less(lhs); }
118 {
return rhs.less(lhs); }
120 {
return !lhs.less(rhs); }
138 {
return subnet() == other.subnet(); }
157 {
return lhs.equal(rhs); }
159 {
return !lhs.equal(rhs); }
161 {
return lhs.less(rhs); }
163 {
return !rhs.less(lhs); }
165 {
return rhs.less(lhs); }
167 {
return !lhs.less(rhs); }
181 : m_address(
ip), m_port(
port)
188 {
return m_address == other.m_address; }
190 boost::asio::ip::address_v6
ip()
const noexcept {
return m_address; }
202 boost::asio::
ip::address_v6::bytes_type bytes = this_ref.m_address.to_bytes();
204 const_cast<
boost::asio::
ip::address_v6&>(this_ref.m_address) =
boost::asio::
ip::address_v6(bytes);
210 {
return lhs.equal(rhs); }
212 {
return !lhs.equal(rhs); }
214 {
return lhs.less(rhs); }
216 {
return !rhs.less(lhs); }
218 {
return rhs.less(lhs); }
220 {
return !lhs.less(rhs); }
255 {
return value.equal(cast(other)); }
258 {
return value.less(cast(other)); }
261 {
return value.is_same_host(cast(other)); }
273 std::shared_ptr<interface>
self;
275 template<
typename Type>
282 throw std::bad_cast{};
286 template<
typename T,
typename t_storage>
296 template<
typename T,
typename t_storage>
312 bool is_loopback()
const {
return self ?
self->is_loopback() :
false; }
313 bool is_local()
const {
return self ?
self->is_local() :
false; }
316 bool is_blockable()
const {
return self ?
self->is_blockable() :
false; }
318 template<
typename Type>
const Type &
as()
const {
return as_mutable<const Type>(); }
322 static constexpr
std::integral_constant<
bool, is_store> is_store_{};
331 return this_ref.template serialize_addr<ipv4_network_address>(is_store_, stg, hparent_section);
333 return this_ref.template serialize_addr<ipv6_network_address>(is_store_, stg, hparent_section);
335 return this_ref.template serialize_addr<net::tor_address>(is_store_, stg, hparent_section);
337 return this_ref.template serialize_addr<net::i2p_address>(is_store_, stg, hparent_section);
343 MERROR(
"Unsupported network address type: " << (
unsigned)
type);
349 {
return lhs.
equal(rhs); }
351 {
return !lhs.
equal(rhs); }
353 {
return lhs.
less(rhs); }
355 {
return !rhs.
less(lhs); }
357 {
return rhs.
less(lhs); }
359 {
return !lhs.
less(rhs); }
382 time_t last_recv = 0, time_t last_send = 0,
384 m_connection_id(connection_id),
385 m_remote_address(remote_address),
386 m_is_income(is_income),
387 m_started(
time(NULL)),
389 m_last_recv(last_recv),
390 m_last_send(last_send),
391 m_recv_cnt(recv_cnt),
392 m_send_cnt(send_cnt),
393 m_current_speed_down(0),
394 m_current_speed_up(0),
402 m_started(
time(NULL)),
408 m_current_speed_down(0),
409 m_current_speed_up(0),
416 set_details(
a.m_connection_id,
a.m_remote_address,
a.m_is_income,
a.m_ssl);
421 set_details(
a.m_connection_id,
a.m_remote_address,
a.m_is_income,
a.m_ssl);
426 template<
class t_protocol_handler>
442 virtual bool close()=0;
443 virtual bool send_done()=0;
444 virtual bool call_run_once_service_io()=0;
445 virtual bool request_callback()=0;
448 virtual bool add_ref()=0;
467 #define LOG_ERROR_CC(ct, message) MERROR(ct << message) 468 #define LOG_WARNING_CC(ct, message) MWARNING(ct << message) 469 #define LOG_INFO_CC(ct, message) MINFO(ct << message) 470 #define LOG_DEBUG_CC(ct, message) MDEBUG(ct << message) 471 #define LOG_TRACE_CC(ct, message) MTRACE(ct << message) 472 #define LOG_CC(level, ct, message) MLOG(level, ct << message) 474 #define LOG_PRINT_CC_L0(ct, message) LOG_PRINT_L0(ct << message) 475 #define LOG_PRINT_CC_L1(ct, message) LOG_PRINT_L1(ct << message) 476 #define LOG_PRINT_CC_L2(ct, message) LOG_PRINT_L2(ct << message) 477 #define LOG_PRINT_CC_L3(ct, message) LOG_PRINT_L3(ct << message) 478 #define LOG_PRINT_CC_L4(ct, message) LOG_PRINT_L4(ct << message) 480 #define LOG_PRINT_CCONTEXT_L0(message) LOG_PRINT_CC_L0(context, message) 481 #define LOG_PRINT_CCONTEXT_L1(message) LOG_PRINT_CC_L1(context, message) 482 #define LOG_PRINT_CCONTEXT_L2(message) LOG_PRINT_CC_L2(context, message) 483 #define LOG_PRINT_CCONTEXT_L3(message) LOG_PRINT_CC_L3(context, message) 484 #define LOG_ERROR_CCONTEXT(message) LOG_ERROR_CC(context, message) 486 #define CHECK_AND_ASSERT_MES_CC(condition, return_val, err_message) CHECK_AND_ASSERT_MES(condition, return_val, "[" << epee::net_utils::print_connection_context_short(context) << "]" << err_message) 491 #endif //_NET_UTILS_BASE_H_ double m_max_speed_down
Definition: net_utils_base.h:377
Definition: binary_utils.h:36
uint32_t m_ip
Definition: net_utils_base.h:68
uint64_t m_send_cnt
Definition: net_utils_base.h:374
const uint32_t T[512]
Definition: groestl_tables.h:36
uint16_t port() const noexcept
Definition: net_utils_base.h:191
virtual std::uint16_t port() const override
Definition: net_utils_base.h:270
static constexpr address_type get_type_id() noexcept
Definition: net_utils_base.h:146
constexpr ipv4_network_subnet(uint32_t ip, uint8_t mask) noexcept
Definition: net_utils_base.h:132
bool equal(const ipv4_network_address &other) const noexcept
Definition: net_utils_base.cpp:22
std::string print_connection_context_short(const connection_context_base &ctx)
Definition: net_utils_base.cpp:128
def release
Definition: support.py:307
uint64_t m_recv_cnt
Definition: net_utils_base.h:373
if(is_store)
Definition: net_utils_base.h:95
uint16_t m_port
Definition: net_utils_base.h:69
Definition: portable_binary_archive.hpp:29
constexpr uint16_t port() const noexcept
Definition: net_utils_base.h:85
bool operator!=(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:111
b32 i2p address; internal format not condensed/decoded.
Definition: i2p_address.h:51
constexpr uint32_t subnet() const noexcept
Definition: net_utils_base.h:141
Definition: net_utils_base.h:243
std::string host_str() const
Definition: net_utils_base.cpp:58
::std::string string
Definition: gtest-port.h:1097
Definition: net_utils_base.h:222
bool operator==(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:109
std::string host_str() const
Definition: net_utils_base.h:311
std::string str() const
Definition: net_utils_base.cpp:28
implementation(const T &src)
Definition: net_utils_base.h:247
bool is_same_host(const ipv6_network_address &other) const noexcept
Definition: net_utils_base.h:187
const time_t m_started
Definition: net_utils_base.h:369
Definition: net_utils_base.h:364
Definition: net_utils_base.h:66
int type
Definition: superscalar.cpp:50
Definition: net_utils_base.h:122
ipv6_network_address()
Definition: net_utils_base.h:176
unsigned short uint16_t
Definition: stdint.h:125
virtual ~i_service_endpoint() noexcept(false)
Definition: net_utils_base.h:451
static bool serialize_t_val_as_blob(const t_type &d, t_storage &stg, typename t_storage::hsection hparent_section, const char *pname)
Definition: keyvalue_serialization_overloads.h:51
static constexpr address_type get_type_id() noexcept
Definition: net_utils_base.h:196
std::string str() const
Definition: net_utils_base.h:310
Definition: keyvalue_serialization_overloads.h:322
std::string host_str() const
Definition: net_utils_base.cpp:31
T value
Definition: net_utils_base.h:245
static const T & cast(const interface &src) noexcept
Definition: net_utils_base.h:251
unsigned char uint8_t
Definition: stdint.h:124
#define KV_SERIALIZE(varialble)
Definition: keyvalue_serialization.h:118
zone get_zone() const
Definition: net_utils_base.h:315
section * hsection
Definition: portable_storage_base.h:174
double m_current_speed_up
Definition: net_utils_base.h:376
virtual ~interface()
Definition: net_utils_base.h:226
bool is_local() const
Definition: net_utils_base.h:313
static constexpr zone get_zone() noexcept
Definition: net_utils_base.h:147
std::uint16_t port() const
Definition: net_utils_base.h:317
address_type
Definition: enums.h:39
network_address(const T &src)
Definition: net_utils_base.h:305
virtual bool is_blockable() const override
Definition: net_utils_base.h:269
bool_constant< true > true_type
Definition: gtest-port.h:2210
constexpr bool is_same_host(const ipv4_network_subnet &other) const noexcept
Definition: net_utils_base.h:137
virtual bool is_same_host(const interface &other) const override
Definition: net_utils_base.h:260
static constexpr zone get_zone() noexcept
Definition: net_utils_base.h:197
const bool m_ssl
Definition: net_utils_base.h:370
double m_max_speed_up
Definition: net_utils_base.h:378
virtual std::string str() const override
Definition: net_utils_base.h:263
boost::asio::io_service io_service
Definition: levin.cpp:303
virtual bool less(const interface &other) const override
Definition: net_utils_base.h:257
bool serialize_addr(std::false_type, t_storage &stg, typename t_storage::hsection hparent)
Definition: net_utils_base.h:287
address_type get_type_id() const
Definition: net_utils_base.h:314
time_t m_last_recv
Definition: net_utils_base.h:371
static void close()
Definition: blockchain_blackball.cpp:279
virtual bool is_loopback() const override
Definition: net_utils_base.h:265
connection_context_base(boost::uuids::uuid connection_id, const network_address &remote_address, bool is_income, bool ssl, time_t last_recv=0, time_t last_send=0, uint64_t recv_cnt=0, uint64_t send_cnt=0)
Definition: net_utils_base.h:380
bool is_loopback() const
Definition: net_utils_base.h:312
constexpr uint32_t ip() const noexcept
Definition: net_utils_base.h:84
bool operator<=(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:115
const char * uuid
Definition: minissdp.c:598
unsigned int uint32_t
Definition: stdint.h:126
ipv6_network_address(const boost::asio::ip::address_v6 &ip, uint16_t port)
Definition: net_utils_base.h:180
Definition: net_utils_base.h:56
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
Definition: serialization.cpp:898
Represents a single connection from a client.
Definition: abstract_tcp_server2.h:86
bool less(const network_address &other) const
Definition: net_utils_base.cpp:78
Type & as_mutable() const
Definition: net_utils_base.h:276
static constexpr address_type get_type_id() noexcept
Definition: net_utils_base.h:90
unsigned __int64 uint64_t
Definition: stdint.h:136
Definition: net_utils_base.h:224
connection_context_base()
Definition: net_utils_base.h:399
Definition: byte_slice.h:68
#define false
Definition: stdbool.h:37
static constexpr bool is_blockable() noexcept
Definition: net_utils_base.h:198
static constexpr bool is_blockable() noexcept
Definition: net_utils_base.h:92
virtual zone get_zone() const override
Definition: net_utils_base.h:268
constexpr ipv4_network_address(uint32_t ip, uint16_t port) noexcept
Definition: net_utils_base.h:76
const network_address m_remote_address
Definition: net_utils_base.h:367
bool is_loopback() const
Definition: net_utils_base.cpp:59
boost::endian::big_uint32_t ip
Definition: socks.cpp:60
boost::endian::big_uint16_t port
Definition: socks.cpp:59
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
MAKE_LOGGABLE(connection_context_base, ct, os)
Definition: net_utils_base.h:461
boost::asio::ip::address_v6 ip() const noexcept
Definition: net_utils_base.h:190
bool operator>(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:117
uint32_t m_ip
Definition: net_utils_base.h:124
TODO: (mj-xmr) This will be reduced in an another PR.
Definition: byte_slice.h:39
uint32_t address
Definition: getifaddr.c:269
virtual address_type get_type_id() const override
Definition: net_utils_base.h:267
bool equal(const ipv4_network_subnet &other) const noexcept
Definition: net_utils_base.cpp:49
bool operator<(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:113
const bool m_is_income
Definition: net_utils_base.h:368
Definition: net_utils_base.h:439
const T & move(const T &t)
Definition: gtest-port.h:1317
Tor onion address; internal format not condensed/decoded.
Definition: tor_address.h:52
connection_context_base(const connection_context_base &a)
Definition: net_utils_base.h:414
const Type & as() const
Definition: net_utils_base.h:318
constexpr bool is_same_host(const ipv4_network_address &other) const noexcept
Definition: net_utils_base.h:81
double m_current_speed_down
Definition: net_utils_base.h:375
bool is_blockable() const
Definition: net_utils_base.h:316
constexpr ipv4_network_address() noexcept
Definition: net_utils_base.h:72
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
virtual bool is_local() const override
Definition: net_utils_base.h:266
virtual std::string host_str() const override
Definition: net_utils_base.h:264
static constexpr zone get_zone() noexcept
Definition: net_utils_base.h:91
time
Definition: gen_wide_data.py:40
uint8_t m_mask
Definition: net_utils_base.h:125
void set_details(boost::uuids::uuid connection_id, const network_address &remote_address, bool is_income, bool ssl)
Definition: net_utils_base.h:428
boost::asio::ip::address_v6 m_address
Definition: net_utils_base.h:172
bool_constant< false > false_type
Definition: gtest-port.h:2209
Definition: net_utils_base.h:169
virtual bool equal(const interface &other) const override
Definition: net_utils_base.h:254
zone
Definition: enums.h:49
std::string print_connection_context(const connection_context_base &ctx)
Definition: net_utils_base.cpp:121
time_t m_last_send
Definition: net_utils_base.h:372
connection_context_base & operator=(const connection_context_base &a)
Definition: net_utils_base.h:419
std::string str() const
Definition: net_utils_base.cpp:55
bool less(const ipv4_network_subnet &other) const noexcept
Definition: net_utils_base.cpp:52
bool operator>=(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:119
bool is_local() const
Definition: net_utils_base.cpp:33
bool serialize_addr(std::true_type, t_storage &stg, typename t_storage::hsection hparent) const
Definition: net_utils_base.h:297
#define END_KV_SERIALIZE_MAP()
Definition: keyvalue_serialization.h:116
bool is_loopback() const
Definition: net_utils_base.cpp:32
bool is_local() const
Definition: net_utils_base.cpp:60
Type
Type of JSON value.
Definition: rapidjson.h:623
bool less(const ipv4_network_address &other) const noexcept
Definition: net_utils_base.cpp:25
tuple message
Definition: gtest_output_test.py:331
#define const
Definition: ipfrdr.c:80
network_address()
Definition: net_utils_base.h:303
#define SWAP32LE
Definition: int-util.h:305
bool equal(const network_address &other) const
Definition: net_utils_base.cpp:67
const boost::uuids::uuid m_connection_id
Definition: net_utils_base.h:366
#define BEGIN_KV_SERIALIZE_MAP()
Definition: keyvalue_serialization.h:43
static constexpr bool is_blockable() noexcept
Definition: net_utils_base.h:148
uint16_t m_port
Definition: net_utils_base.h:173
bool matches(const ipv4_network_address &address) const
Definition: net_utils_base.cpp:61
#define inline
Definition: inline_c.h:34
constexpr ipv4_network_subnet() noexcept
Definition: net_utils_base.h:128