Monero
net_utils_base.h
Go to the documentation of this file.
1 // Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of the Andrey N. Sabelnikov nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 
28 
29 #ifndef _NET_UTILS_BASE_H_
30 #define _NET_UTILS_BASE_H_
31 
32 #include <boost/uuid/uuid.hpp>
33 #include <boost/asio/io_context.hpp>
34 #include <boost/asio/ip/address_v6.hpp>
35 #include <typeinfo>
36 #include <type_traits>
37 #include "byte_slice.h"
38 #include "enums.h"
39 #include "misc_log_ex.h"
41 #include "int-util.h"
42 
43 #undef MONERO_DEFAULT_LOG_CATEGORY
44 #define MONERO_DEFAULT_LOG_CATEGORY "net"
45 
46 #ifndef MAKE_IP
47 #define MAKE_IP( a1, a2, a3, a4 ) (a1|(a2<<8)|(a3<<16)|(((uint32_t)a4)<<24))
48 #endif
49 
50 /* Use the below function carefully. The executor and io_context are slightly
51  different concepts. */
52 #if BOOST_VERSION >= 107000
53  #define MONERO_GET_EXECUTOR(type) type . get_executor()
54 #else
55  #define MONERO_GET_EXECUTOR(type) type . get_io_context()
56 #endif
57 
58 namespace net
59 {
60  class tor_address;
61  class i2p_address;
62 }
63 
64 namespace epee
65 {
66 namespace net_utils
67 {
69  {
72 
73  public:
74  constexpr ipv4_network_address() noexcept
75  : ipv4_network_address(0, 0)
76  {}
77 
79  : m_ip(ip), m_port(port) {}
80 
81  bool equal(const ipv4_network_address& other) const noexcept;
82  bool less(const ipv4_network_address& other) const noexcept;
83  constexpr bool is_same_host(const ipv4_network_address& other) const noexcept
84  { return ip() == other.ip(); }
85 
86  constexpr uint32_t ip() const noexcept { return m_ip; }
87  constexpr uint16_t port() const noexcept { return m_port; }
88  std::string str() const;
89  std::string host_str() const;
90  bool is_loopback() const;
91  bool is_local() const;
92  static constexpr address_type get_type_id() noexcept { return address_type::ipv4; }
93  static constexpr zone get_zone() noexcept { return zone::public_; }
94  static constexpr bool is_blockable() noexcept { return true; }
95 
97  if (is_store)
98  {
99  uint32_t ip = SWAP32LE(this_ref.m_ip);
100  epee::serialization::selector<is_store>::serialize(ip, stg, hparent_section, "m_ip");
101  }
102  else
103  {
105  const_cast<ipv4_network_address&>(this_ref).m_ip = SWAP32LE(this_ref.m_ip);
106  }
109  };
110 
111  inline bool operator==(const ipv4_network_address& lhs, const ipv4_network_address& rhs) noexcept
112  { return lhs.equal(rhs); }
113  inline bool operator!=(const ipv4_network_address& lhs, const ipv4_network_address& rhs) noexcept
114  { return !lhs.equal(rhs); }
115  inline bool operator<(const ipv4_network_address& lhs, const ipv4_network_address& rhs) noexcept
116  { return lhs.less(rhs); }
117  inline bool operator<=(const ipv4_network_address& lhs, const ipv4_network_address& rhs) noexcept
118  { return !rhs.less(lhs); }
119  inline bool operator>(const ipv4_network_address& lhs, const ipv4_network_address& rhs) noexcept
120  { return rhs.less(lhs); }
121  inline bool operator>=(const ipv4_network_address& lhs, const ipv4_network_address& rhs) noexcept
122  { return !lhs.less(rhs); }
123 
125  {
128 
129  public:
130  constexpr ipv4_network_subnet() noexcept
131  : ipv4_network_subnet(0, 0)
132  {}
133 
134  constexpr ipv4_network_subnet(uint32_t ip, uint8_t mask) noexcept
135  : m_ip(ip), m_mask(mask) {}
136 
137  bool equal(const ipv4_network_subnet& other) const noexcept;
138  bool less(const ipv4_network_subnet& other) const noexcept;
139  constexpr bool is_same_host(const ipv4_network_subnet& other) const noexcept
140  { return subnet() == other.subnet(); }
141  bool matches(const ipv4_network_address &address) const;
142 
143  constexpr uint32_t subnet() const noexcept { return m_ip & ~(0xffffffffull << m_mask); }
144  std::string str() const;
145  std::string host_str() const;
146  bool is_loopback() const;
147  bool is_local() const;
148  static constexpr address_type get_type_id() noexcept { return address_type::invalid; }
149  static constexpr zone get_zone() noexcept { return zone::public_; }
150  static constexpr bool is_blockable() noexcept { return true; }
151 
156  };
157 
158  inline bool operator==(const ipv4_network_subnet& lhs, const ipv4_network_subnet& rhs) noexcept
159  { return lhs.equal(rhs); }
160  inline bool operator!=(const ipv4_network_subnet& lhs, const ipv4_network_subnet& rhs) noexcept
161  { return !lhs.equal(rhs); }
162  inline bool operator<(const ipv4_network_subnet& lhs, const ipv4_network_subnet& rhs) noexcept
163  { return lhs.less(rhs); }
164  inline bool operator<=(const ipv4_network_subnet& lhs, const ipv4_network_subnet& rhs) noexcept
165  { return !rhs.less(lhs); }
166  inline bool operator>(const ipv4_network_subnet& lhs, const ipv4_network_subnet& rhs) noexcept
167  { return rhs.less(lhs); }
168  inline bool operator>=(const ipv4_network_subnet& lhs, const ipv4_network_subnet& rhs) noexcept
169  { return !lhs.less(rhs); }
170 
172  {
173  protected:
174  boost::asio::ip::address_v6 m_address;
176 
177  public:
179  : ipv6_network_address(boost::asio::ip::address_v6::loopback(), 0)
180  {}
181 
182  ipv6_network_address(const boost::asio::ip::address_v6& ip, uint16_t port)
183  : m_address(ip), m_port(port)
184  {
185  }
186 
187  bool equal(const ipv6_network_address& other) const noexcept;
188  bool less(const ipv6_network_address& other) const noexcept;
189  bool is_same_host(const ipv6_network_address& other) const noexcept
190  { return m_address == other.m_address; }
191 
192  boost::asio::ip::address_v6 ip() const noexcept { return m_address; }
193  uint16_t port() const noexcept { return m_port; }
194  std::string str() const;
195  std::string host_str() const;
196  bool is_loopback() const;
197  bool is_local() const;
198  static constexpr address_type get_type_id() noexcept { return address_type::ipv6; }
199  static constexpr zone get_zone() noexcept { return zone::public_; }
200  static constexpr bool is_blockable() noexcept { return true; }
201 
202  static const uint8_t ID = 2;
204  boost::asio::ip::address_v6::bytes_type bytes = this_ref.m_address.to_bytes();
205  epee::serialization::selector<is_store>::serialize_t_val_as_blob(bytes, stg, hparent_section, "addr");
206  const_cast<boost::asio::ip::address_v6&>(this_ref.m_address) = boost::asio::ip::address_v6(bytes);
207  KV_SERIALIZE(m_port)
209  };
210 
211  inline bool operator==(const ipv6_network_address& lhs, const ipv6_network_address& rhs) noexcept
212  { return lhs.equal(rhs); }
213  inline bool operator!=(const ipv6_network_address& lhs, const ipv6_network_address& rhs) noexcept
214  { return !lhs.equal(rhs); }
215  inline bool operator<(const ipv6_network_address& lhs, const ipv6_network_address& rhs) noexcept
216  { return lhs.less(rhs); }
217  inline bool operator<=(const ipv6_network_address& lhs, const ipv6_network_address& rhs) noexcept
218  { return !rhs.less(lhs); }
219  inline bool operator>(const ipv6_network_address& lhs, const ipv6_network_address& rhs) noexcept
220  { return rhs.less(lhs); }
221  inline bool operator>=(const ipv6_network_address& lhs, const ipv6_network_address& rhs) noexcept
222  { return !lhs.less(rhs); }
223 
225  {
226  struct interface
227  {
228  virtual ~interface() {};
229 
230  virtual bool equal(const interface&) const = 0;
231  virtual bool less(const interface&) const = 0;
232  virtual bool is_same_host(const interface&) const = 0;
233 
234  virtual std::string str() const = 0;
235  virtual std::string host_str() const = 0;
236  virtual bool is_loopback() const = 0;
237  virtual bool is_local() const = 0;
238  virtual address_type get_type_id() const = 0;
239  virtual zone get_zone() const = 0;
240  virtual bool is_blockable() const = 0;
241  virtual std::uint16_t port() const = 0;
242  };
243 
244  template<typename T>
245  struct implementation final : interface
246  {
248 
249  implementation(const T& src) : value(src) {}
250  ~implementation() = default;
251 
252  // Type-checks for cast are done in cpp
253  static const T& cast(const interface& src) noexcept
254  { return static_cast<const implementation<T>&>(src).value; }
255 
256  virtual bool equal(const interface& other) const override
257  { return value.equal(cast(other)); }
258 
259  virtual bool less(const interface& other) const override
260  { return value.less(cast(other)); }
261 
262  virtual bool is_same_host(const interface& other) const override
263  { return value.is_same_host(cast(other)); }
264 
265  virtual std::string str() const override { return value.str(); }
266  virtual std::string host_str() const override { return value.host_str(); }
267  virtual bool is_loopback() const override { return value.is_loopback(); }
268  virtual bool is_local() const override { return value.is_local(); }
269  virtual address_type get_type_id() const override { return value.get_type_id(); }
270  virtual zone get_zone() const override { return value.get_zone(); }
271  virtual bool is_blockable() const override { return value.is_blockable(); }
272  virtual std::uint16_t port() const override { return value.port(); }
273  };
274 
275  std::shared_ptr<interface> self;
276 
277  template<typename Type>
278  Type& as_mutable() const
279  {
280  // types `implmentation<Type>` and `implementation<const Type>` are unique
281  using Type_ = typename std::remove_const<Type>::type;
282  network_address::interface* const self_ = self.get(); // avoid clang warning in typeid
283  if (!self_ || typeid(implementation<Type_>) != typeid(*self_))
284  throw std::bad_cast{};
285  return static_cast<implementation<Type_>*>(self_)->value;
286  }
287 
288  template<typename T, typename t_storage>
289  bool serialize_addr(std::false_type, t_storage& stg, typename t_storage::hsection hparent)
290  {
291  T addr{};
292  if (!epee::serialization::selector<false>::serialize(addr, stg, hparent, "addr"))
293  return false;
294  *this = std::move(addr);
295  return true;
296  }
297 
298  template<typename T, typename t_storage>
299  bool serialize_addr(std::true_type, t_storage& stg, typename t_storage::hsection hparent) const
300  {
301  return epee::serialization::selector<true>::serialize(as<T>(), stg, hparent, "addr");
302  }
303 
304  public:
305  network_address() : self(nullptr) {}
306  template<typename T>
307  network_address(const T& src)
308  : self(std::make_shared<implementation<T>>(src)) {}
309  bool equal(const network_address &other) const;
310  bool less(const network_address &other) const;
311  bool is_same_host(const network_address &other) const;
312  std::string str() const { return self ? self->str() : "<none>"; }
313  std::string host_str() const { return self ? self->host_str() : "<none>"; }
314  bool is_loopback() const { return self ? self->is_loopback() : false; }
315  bool is_local() const { return self ? self->is_local() : false; }
316  address_type get_type_id() const { return self ? self->get_type_id() : address_type::invalid; }
317  zone get_zone() const { return self ? self->get_zone() : zone::invalid; }
318  bool is_blockable() const { return self ? self->is_blockable() : false; }
319  std::uint16_t port() const { return self ? self->port() : 0; }
320  template<typename Type> const Type &as() const { return as_mutable<const Type>(); }
321 
323  // need to `#include "net/[i2p|tor]_address.h"` when serializing `network_address`
324  static constexpr std::integral_constant<bool, is_store> is_store_{};
325 
326  std::uint8_t type = std::uint8_t(is_store ? this_ref.get_type_id() : address_type::invalid);
327  if (!epee::serialization::selector<is_store>::serialize(type, stg, hparent_section, "type"))
328  return false;
329 
330  switch (address_type(type))
331  {
332  case address_type::ipv4:
333  return this_ref.template serialize_addr<ipv4_network_address>(is_store_, stg, hparent_section);
334  case address_type::ipv6:
335  return this_ref.template serialize_addr<ipv6_network_address>(is_store_, stg, hparent_section);
336  case address_type::tor:
337  return this_ref.template serialize_addr<net::tor_address>(is_store_, stg, hparent_section);
338  case address_type::i2p:
339  return this_ref.template serialize_addr<net::i2p_address>(is_store_, stg, hparent_section);
341  default:
342  break;
343  }
344 
345  MERROR("Unsupported network address type: " << (unsigned)type);
346  return false;
348  };
349 
350  inline bool operator==(const network_address& lhs, const network_address& rhs)
351  { return lhs.equal(rhs); }
352  inline bool operator!=(const network_address& lhs, const network_address& rhs)
353  { return !lhs.equal(rhs); }
354  inline bool operator<(const network_address& lhs, const network_address& rhs)
355  { return lhs.less(rhs); }
356  inline bool operator<=(const network_address& lhs, const network_address& rhs)
357  { return !rhs.less(lhs); }
358  inline bool operator>(const network_address& lhs, const network_address& rhs)
359  { return rhs.less(lhs); }
360  inline bool operator>=(const network_address& lhs, const network_address& rhs)
361  { return !lhs.less(rhs); }
362 
363  /************************************************************************/
364  /* */
365  /************************************************************************/
367  {
370  const bool m_is_income;
371  const time_t m_started;
372  const bool m_ssl;
373  time_t m_last_recv;
374  time_t m_last_send;
381 
383  const network_address &remote_address, bool is_income, bool ssl,
384  time_t last_recv = 0, time_t last_send = 0,
385  uint64_t recv_cnt = 0, uint64_t send_cnt = 0):
386  m_connection_id(connection_id),
387  m_remote_address(remote_address),
388  m_is_income(is_income),
389  m_started(time(NULL)),
390  m_ssl(ssl),
391  m_last_recv(last_recv),
392  m_last_send(last_send),
393  m_recv_cnt(recv_cnt),
394  m_send_cnt(send_cnt),
395  m_current_speed_down(0),
396  m_current_speed_up(0),
397  m_max_speed_down(0),
398  m_max_speed_up(0)
399  {}
400 
401  connection_context_base(): m_connection_id(),
402  m_remote_address(),
403  m_is_income(false),
404  m_started(time(NULL)),
405  m_ssl(false),
406  m_last_recv(0),
407  m_last_send(0),
408  m_recv_cnt(0),
409  m_send_cnt(0),
410  m_current_speed_down(0),
411  m_current_speed_up(0),
412  m_max_speed_down(0),
413  m_max_speed_up(0)
414  {}
415 
417  {
418  set_details(a.m_connection_id, a.m_remote_address, a.m_is_income, a.m_ssl);
419  }
420 
422  {
423  set_details(a.m_connection_id, a.m_remote_address, a.m_is_income, a.m_ssl);
424  return *this;
425  }
426 
427  private:
428  template<class t_protocol_handler>
429  friend class connection;
430  void set_details(boost::uuids::uuid connection_id, const network_address &remote_address, bool is_income, bool ssl)
431  {
432  this->~connection_context_base();
433  new(this) connection_context_base(connection_id, remote_address, is_income, ssl);
434  }
435 
436  };
437 
438  /************************************************************************/
439  /* */
440  /************************************************************************/
442  {
443  virtual bool do_send(byte_slice message)=0;
444  virtual bool close()=0;
445  virtual bool send_done()=0;
446  virtual bool call_run_once_service_io()=0;
447  virtual bool request_callback()=0;
448  virtual boost::asio::io_context& get_io_context()=0;
449  //protect from deletion connection object(with protocol instance) during external call "invoke"
450  virtual bool add_ref()=0;
451  virtual bool release()=0;
452  protected:
453  virtual ~i_service_endpoint() noexcept(false) {}
454  };
455 
456 
457  //some helpers
458 
459 
460  std::string print_connection_context(const connection_context_base& ctx);
461  std::string print_connection_context_short(const connection_context_base& ctx);
462 
464 {
465  os << "[" << epee::net_utils::print_connection_context_short(ct) << "] ";
466  return os;
467 }
468 
469 #define LOG_ERROR_CC(ct, message) MERROR(ct << message)
470 #define LOG_WARNING_CC(ct, message) MWARNING(ct << message)
471 #define LOG_INFO_CC(ct, message) MINFO(ct << message)
472 #define LOG_DEBUG_CC(ct, message) MDEBUG(ct << message)
473 #define LOG_TRACE_CC(ct, message) MTRACE(ct << message)
474 #define LOG_CC(level, ct, message) MLOG(level, ct << message)
475 
476 #define LOG_PRINT_CC_L0(ct, message) LOG_PRINT_L0(ct << message)
477 #define LOG_PRINT_CC_L1(ct, message) LOG_PRINT_L1(ct << message)
478 #define LOG_PRINT_CC_L2(ct, message) LOG_PRINT_L2(ct << message)
479 #define LOG_PRINT_CC_L3(ct, message) LOG_PRINT_L3(ct << message)
480 #define LOG_PRINT_CC_L4(ct, message) LOG_PRINT_L4(ct << message)
481 
482 #define LOG_PRINT_CCONTEXT_L0(message) LOG_PRINT_CC_L0(context, message)
483 #define LOG_PRINT_CCONTEXT_L1(message) LOG_PRINT_CC_L1(context, message)
484 #define LOG_PRINT_CCONTEXT_L2(message) LOG_PRINT_CC_L2(context, message)
485 #define LOG_PRINT_CCONTEXT_L3(message) LOG_PRINT_CC_L3(context, message)
486 #define LOG_ERROR_CCONTEXT(message) LOG_ERROR_CC(context, message)
487 
488 #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)
489 
490 }
491 }
492 
493 #endif //_NET_UTILS_BASE_H_
double m_max_speed_down
Definition: net_utils_base.h:379
Definition: binary_utils.h:36
uint32_t m_ip
Definition: net_utils_base.h:70
uint64_t m_send_cnt
Definition: net_utils_base.h:376
const uint32_t T[512]
Definition: groestl_tables.h:36
uint16_t port() const noexcept
Definition: net_utils_base.h:193
virtual std::uint16_t port() const override
Definition: net_utils_base.h:272
static constexpr address_type get_type_id() noexcept
Definition: net_utils_base.h:148
constexpr ipv4_network_subnet(uint32_t ip, uint8_t mask) noexcept
Definition: net_utils_base.h:134
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:375
if(is_store)
Definition: net_utils_base.h:97
uint16_t m_port
Definition: net_utils_base.h:71
Definition: portable_binary_archive.hpp:29
constexpr uint16_t port() const noexcept
Definition: net_utils_base.h:87
bool operator!=(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:113
b32 i2p address; internal format not condensed/decoded.
Definition: i2p_address.h:51
constexpr uint32_t subnet() const noexcept
Definition: net_utils_base.h:143
Definition: net_utils_base.h:245
std::string host_str() const
Definition: net_utils_base.cpp:58
::std::string string
Definition: gtest-port.h:1097
Definition: net_utils_base.h:224
bool operator==(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:111
std::string host_str() const
Definition: net_utils_base.h:313
std::string str() const
Definition: net_utils_base.cpp:28
implementation(const T &src)
Definition: net_utils_base.h:249
bool is_same_host(const ipv6_network_address &other) const noexcept
Definition: net_utils_base.h:189
const time_t m_started
Definition: net_utils_base.h:371
Definition: net_utils_base.h:366
Definition: net_utils_base.h:68
int type
Definition: superscalar.cpp:50
Definition: net_utils_base.h:124
Definition: enums.h:67
ipv6_network_address()
Definition: net_utils_base.h:178
unsigned short uint16_t
Definition: stdint.h:125
virtual ~i_service_endpoint() noexcept(false)
Definition: net_utils_base.h:453
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:53
static constexpr address_type get_type_id() noexcept
Definition: net_utils_base.h:198
std::string str() const
Definition: net_utils_base.h:312
Definition: keyvalue_serialization_overloads.h:324
std::string host_str() const
Definition: net_utils_base.cpp:31
T value
Definition: net_utils_base.h:247
static const T & cast(const interface &src) noexcept
Definition: net_utils_base.h:253
unsigned char uint8_t
Definition: stdint.h:124
#define KV_SERIALIZE(varialble)
Definition: keyvalue_serialization.h:120
zone get_zone() const
Definition: net_utils_base.h:317
section * hsection
Definition: portable_storage_base.h:174
double m_current_speed_up
Definition: net_utils_base.h:378
virtual ~interface()
Definition: net_utils_base.h:228
bool is_local() const
Definition: net_utils_base.h:315
static constexpr zone get_zone() noexcept
Definition: net_utils_base.h:149
std::uint16_t port() const
Definition: net_utils_base.h:319
address_type
Definition: enums.h:39
network_address(const T &src)
Definition: net_utils_base.h:307
virtual bool is_blockable() const override
Definition: net_utils_base.h:271
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:139
virtual bool is_same_host(const interface &other) const override
Definition: net_utils_base.h:262
static constexpr zone get_zone() noexcept
Definition: net_utils_base.h:199
const bool m_ssl
Definition: net_utils_base.h:372
double m_max_speed_up
Definition: net_utils_base.h:380
virtual std::string str() const override
Definition: net_utils_base.h:265
virtual bool less(const interface &other) const override
Definition: net_utils_base.h:259
bool serialize_addr(std::false_type, t_storage &stg, typename t_storage::hsection hparent)
Definition: net_utils_base.h:289
address_type get_type_id() const
Definition: net_utils_base.h:316
time_t m_last_recv
Definition: net_utils_base.h:373
static void close()
Definition: blockchain_blackball.cpp:279
virtual bool is_loopback() const override
Definition: net_utils_base.h:267
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:382
bool is_loopback() const
Definition: net_utils_base.h:314
constexpr uint32_t ip() const noexcept
Definition: net_utils_base.h:86
bool operator<=(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:117
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:182
Definition: net_utils_base.h:58
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:95
bool less(const network_address &other) const
Definition: net_utils_base.cpp:78
Type & as_mutable() const
Definition: net_utils_base.h:278
static constexpr address_type get_type_id() noexcept
Definition: net_utils_base.h:92
unsigned __int64 uint64_t
Definition: stdint.h:136
Definition: net_utils_base.h:226
connection_context_base()
Definition: net_utils_base.h:401
Definition: byte_slice.h:68
#define false
Definition: stdbool.h:37
static constexpr bool is_blockable() noexcept
Definition: net_utils_base.h:200
static constexpr bool is_blockable() noexcept
Definition: net_utils_base.h:94
virtual zone get_zone() const override
Definition: net_utils_base.h:270
constexpr ipv4_network_address(uint32_t ip, uint16_t port) noexcept
Definition: net_utils_base.h:78
const network_address m_remote_address
Definition: net_utils_base.h:369
bool is_loopback() const
Definition: net_utils_base.cpp:59
boost::endian::big_uint32_t ip
Definition: socks.cpp:62
boost::endian::big_uint16_t port
Definition: socks.cpp:61
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:463
boost::asio::ip::address_v6 ip() const noexcept
Definition: net_utils_base.h:192
bool operator>(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:119
uint32_t m_ip
Definition: net_utils_base.h:126
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:269
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:115
const bool m_is_income
Definition: net_utils_base.h:370
Definition: net_utils_base.h:441
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:416
const Type & as() const
Definition: net_utils_base.h:320
constexpr bool is_same_host(const ipv4_network_address &other) const noexcept
Definition: net_utils_base.h:83
double m_current_speed_down
Definition: net_utils_base.h:377
bool is_blockable() const
Definition: net_utils_base.h:318
constexpr ipv4_network_address() noexcept
Definition: net_utils_base.h:74
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
virtual bool is_local() const override
Definition: net_utils_base.h:268
virtual std::string host_str() const override
Definition: net_utils_base.h:266
static constexpr zone get_zone() noexcept
Definition: net_utils_base.h:93
time
Definition: gen_wide_data.py:40
uint8_t m_mask
Definition: net_utils_base.h:127
void set_details(boost::uuids::uuid connection_id, const network_address &remote_address, bool is_income, bool ssl)
Definition: net_utils_base.h:430
boost::asio::ip::address_v6 m_address
Definition: net_utils_base.h:174
bool_constant< false > false_type
Definition: gtest-port.h:2209
Definition: net_utils_base.h:171
virtual bool equal(const interface &other) const override
Definition: net_utils_base.h:256
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:374
connection_context_base & operator=(const connection_context_base &a)
Definition: net_utils_base.h:421
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:121
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:299
#define END_KV_SERIALIZE_MAP()
Definition: keyvalue_serialization.h:118
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:305
#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:368
#define BEGIN_KV_SERIALIZE_MAP()
Definition: keyvalue_serialization.h:43
static constexpr bool is_blockable() noexcept
Definition: net_utils_base.h:150
uint16_t m_port
Definition: net_utils_base.h:175
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:130