Electroneum
net_node.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2020, The Electroneum Project
2 // Copyrights(c) 2014-2019, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #pragma once
33 #include <array>
34 #include <atomic>
35 #include <boost/asio/io_service.hpp>
36 #include <boost/asio/ip/tcp.hpp>
37 #include <boost/thread.hpp>
38 #include <boost/optional/optional_fwd.hpp>
39 #include <boost/program_options/options_description.hpp>
40 #include <boost/program_options/variables_map.hpp>
41 #include <boost/uuid/uuid.hpp>
42 #include <functional>
43 #include <utility>
44 #include <vector>
45 
46 #include "cryptonote_config.h"
47 #include "warnings.h"
48 #include "net/abstract_tcp_server2.h"
49 #include "net/levin_protocol_handler.h"
50 #include "net/levin_protocol_handler_async.h"
51 #include "p2p_protocol_defs.h"
52 #include "storages/levin_abstract_invoke2.h"
53 #include "net_peerlist.h"
54 #include "math_helper.h"
55 #include "net_node_common.h"
56 #include "net/enums.h"
57 #include "net/fwd.h"
58 #include "common/command_line.h"
59 
62 
63 namespace nodetool
64 {
65  struct proxy
66  {
68  : max_connections(-1),
69  address(),
70  zone(epee::net_utils::zone::invalid)
71  {}
72 
73  std::int64_t max_connections;
74  boost::asio::ip::tcp::endpoint address;
75  epee::net_utils::zone zone;
76  };
77 
79  {
81  : max_connections(-1),
82  local_ip(),
83  local_port(),
84  our_address(),
85  default_remote()
86  {}
87 
88  std::int64_t max_connections;
89  std::string local_ip;
90  std::string local_port;
91  epee::net_utils::network_address our_address;
92  epee::net_utils::network_address default_remote;
93  };
94 
95  boost::optional<std::vector<proxy>> get_proxies(const boost::program_options::variables_map& vm);
96  boost::optional<std::vector<anonymous_inbound>> get_anonymous_inbounds(const boost::program_options::variables_map& vm);
97 
99  bool is_filtered_command(epee::net_utils::network_address const& address, int command);
100 
101  // hides boost::future and chrono stuff from mondo template file
102  boost::optional<boost::asio::ip::tcp::socket>
103  socks_connect_internal(const std::atomic<bool>& stop_signal, boost::asio::io_service& service, const boost::asio::ip::tcp::endpoint& proxy, const epee::net_utils::network_address& remote);
104 
105 
106  template<class base_type>
107  struct p2p_connection_context_t: base_type //t_payload_net_handler::connection_context //public net_utils::connection_context_base
108  {
109  p2p_connection_context_t(): peer_id(0), support_flags(0), m_in_timedsync(false) {}
110 
112  uint32_t support_flags;
114  };
115 
116  template<class t_payload_net_handler>
117  class node_server: public epee::levin::levin_commands_handler<p2p_connection_context_t<typename t_payload_net_handler::connection_context> >,
118  public i_p2p_endpoint<typename t_payload_net_handler::connection_context>,
119  public epee::net_utils::i_connection_filter
120  {
121  struct by_conn_id{};
122  struct by_peer_id{};
123  struct by_addr{};
124 
126 
129 
130  typedef epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<p2p_connection_context>> net_server;
131 
132  struct network_zone;
133  using connect_func = boost::optional<p2p_connection_context>(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
134 
135  struct config_t
136  {
138  : m_net_config(),
139  m_peer_id(crypto::rand<uint64_t>()),
140  m_support_flags(0)
141  {}
142 
144  uint64_t m_peer_id;
145  uint32_t m_support_flags;
146  };
147  typedef epee::misc_utils::struct_init<config_t> config;
148 
150  {
152  : m_connect(nullptr),
153  m_net_server(epee::net_utils::e_connection_type_P2P),
154  m_bind_ip(),
155  m_port(),
156  m_our_address(),
157  m_peerlist(),
158  m_config{},
159  m_proxy_address(),
160  m_current_number_of_out_peers(0),
161  m_current_number_of_in_peers(0),
162  m_can_pingback(false)
163  {
164  set_config_defaults();
165  }
166 
167  network_zone(boost::asio::io_service& public_service)
168  : m_connect(nullptr),
169  m_net_server(public_service, epee::net_utils::e_connection_type_P2P),
170  m_bind_ip(),
171  m_port(),
172  m_our_address(),
173  m_peerlist(),
174  m_config{},
175  m_proxy_address(),
176  m_current_number_of_out_peers(0),
177  m_current_number_of_in_peers(0),
178  m_can_pingback(false)
179  {
180  set_config_defaults();
181  }
182 
185  std::string m_bind_ip;
186  std::string m_port;
187  epee::net_utils::network_address m_our_address; // in anonymity networks
190  boost::asio::ip::tcp::endpoint m_proxy_address;
191  std::atomic<unsigned int> m_current_number_of_out_peers;
192  std::atomic<unsigned int> m_current_number_of_in_peers;
194 
195  private:
196  void set_config_defaults() noexcept
197  {
198  // at this moment we have a hardcoded config
199  m_config.m_net_config.handshake_interval = P2P_DEFAULT_HANDSHAKE_INTERVAL;
200  m_config.m_net_config.packet_max_size = P2P_DEFAULT_PACKET_MAX_SIZE;
201  m_config.m_net_config.config_id = 0;
202  m_config.m_net_config.connection_timeout = P2P_DEFAULT_CONNECTION_TIMEOUT;
203  m_config.m_net_config.ping_connection_timeout = P2P_DEFAULT_PING_CONNECTION_TIMEOUT;
204  m_config.m_net_config.send_peerlist_sz = P2P_DEFAULT_PEERS_IN_HANDSHAKE;
205  m_config.m_support_flags = 0; // only set in public zone
206  }
207  };
208 
209  public:
210  typedef t_payload_net_handler payload_net_handler;
211 
212  node_server(t_payload_net_handler& payload_handler)
213  : m_payload_handler(payload_handler),
214  m_external_port(0),
215  m_rpc_port(0),
216  m_allow_local_ip(false),
217  m_hide_my_port(false),
218  m_no_igd(false),
219  m_offline(false),
220  m_save_graph(false),
221  is_closing(false),
222  m_network_id()
223  {}
224  virtual ~node_server();
225 
226  static void init_options(boost::program_options::options_description& desc);
227 
228  bool run();
229  network_zone& add_zone(epee::net_utils::zone zone);
230  bool init(const boost::program_options::variables_map& vm);
231  bool deinit();
232  bool send_stop_signal();
233  uint32_t get_this_peer_port(){return m_listening_port;}
234  t_payload_net_handler& get_payload_object();
235 
236  // debug functions
237  bool log_peerlist();
238  bool log_connections();
239 
240  // These functions only return information for the "public" zone
241  virtual uint64_t get_public_connections_count();
242  size_t get_public_outgoing_connections_count();
243  size_t get_public_white_peers_count();
244  size_t get_public_gray_peers_count();
245  void get_public_peerlist(std::vector<peerlist_entry>& gray, std::vector<peerlist_entry>& white);
246  size_t get_zone_count() const { return m_network_zones.size(); }
247 
248  void change_max_out_public_peers(size_t count);
249  void change_max_in_public_peers(size_t count);
250  virtual bool block_host(const epee::net_utils::network_address &adress, time_t seconds = P2P_IP_BLOCKTIME);
251  virtual bool unblock_host(const epee::net_utils::network_address &address);
252  virtual std::map<std::string, time_t> get_blocked_hosts() { CRITICAL_REGION_LOCAL(m_blocked_hosts_lock); return m_blocked_hosts; }
253 
254  virtual void add_used_stripe_peer(const typename t_payload_net_handler::connection_context &context);
255  virtual void remove_used_stripe_peer(const typename t_payload_net_handler::connection_context &context);
256  virtual void clear_used_stripe_peers();
257 
258  private:
259  const std::vector<std::string> m_seed_nodes_list =
260  {
261  "seeds.electroneumseed.com",
262  "seeds.electroneumseed.info",
263  "seeds.electroneumseed.org",
264  "seeds.electroneumseed.net",
265  };
266 
267  bool islimitup=false;
268  bool islimitdown=false;
269 
270  typedef COMMAND_REQUEST_STAT_INFO_T<typename t_payload_net_handler::stat_info> COMMAND_REQUEST_STAT_INFO;
271 
272  CHAIN_LEVIN_INVOKE_MAP2(p2p_connection_context); //move levin_commands_handler interface invoke(...) callbacks into invoke map
273  CHAIN_LEVIN_NOTIFY_MAP2(p2p_connection_context); //move levin_commands_handler interface notify(...) callbacks into nothing
274 
275  BEGIN_INVOKE_MAP2(node_server)
276  if (is_filtered_command(context.m_remote_address, command))
277  return LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED;
278 
279  HANDLE_INVOKE_T2(COMMAND_HANDSHAKE, &node_server::handle_handshake)
280  HANDLE_INVOKE_T2(COMMAND_TIMED_SYNC, &node_server::handle_timed_sync)
281  HANDLE_INVOKE_T2(COMMAND_PING, &node_server::handle_ping)
282 #ifdef ALLOW_DEBUG_COMMANDS
283  HANDLE_INVOKE_T2(COMMAND_REQUEST_STAT_INFO, &node_server::handle_get_stat_info)
284  HANDLE_INVOKE_T2(COMMAND_REQUEST_NETWORK_STATE, &node_server::handle_get_network_state)
285  HANDLE_INVOKE_T2(COMMAND_REQUEST_PEER_ID, &node_server::handle_get_peer_id)
286 #endif
287  HANDLE_INVOKE_T2(COMMAND_REQUEST_SUPPORT_FLAGS, &node_server::handle_get_support_flags)
288  CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT(m_payload_handler, typename t_payload_net_handler::connection_context&)
289  END_INVOKE_MAP2()
290 
291  enum PeerType { anchor = 0, white, gray };
292 
293  //----------------- commands handlers ----------------------------------------------
294  int handle_handshake(int command, typename COMMAND_HANDSHAKE::request& arg, typename COMMAND_HANDSHAKE::response& rsp, p2p_connection_context& context);
295  int handle_timed_sync(int command, typename COMMAND_TIMED_SYNC::request& arg, typename COMMAND_TIMED_SYNC::response& rsp, p2p_connection_context& context);
296  int handle_ping(int command, COMMAND_PING::request& arg, COMMAND_PING::response& rsp, p2p_connection_context& context);
297 #ifdef ALLOW_DEBUG_COMMANDS
298  int handle_get_stat_info(int command, typename COMMAND_REQUEST_STAT_INFO::request& arg, typename COMMAND_REQUEST_STAT_INFO::response& rsp, p2p_connection_context& context);
299  int handle_get_network_state(int command, COMMAND_REQUEST_NETWORK_STATE::request& arg, COMMAND_REQUEST_NETWORK_STATE::response& rsp, p2p_connection_context& context);
300  int handle_get_peer_id(int command, COMMAND_REQUEST_PEER_ID::request& arg, COMMAND_REQUEST_PEER_ID::response& rsp, p2p_connection_context& context);
301 #endif
302  int handle_get_support_flags(int command, COMMAND_REQUEST_SUPPORT_FLAGS::request& arg, COMMAND_REQUEST_SUPPORT_FLAGS::response& rsp, p2p_connection_context& context);
303  bool init_config();
306  bool store_config();
307  bool check_trust(const proof_of_trust& tr, epee::net_utils::zone zone_type);
308 
309 
310  //----------------- levin_commands_handler -------------------------------------------------------------
311  virtual void on_connection_new(p2p_connection_context& context);
312  virtual void on_connection_close(p2p_connection_context& context);
313  virtual void callback(p2p_connection_context& context);
314  //----------------- i_p2p_endpoint -------------------------------------------------------------
315  virtual bool relay_notify_to_list(int command, const epee::span<const uint8_t> data_buff, std::vector<std::pair<epee::net_utils::zone, boost::uuids::uuid>> connections);
316  virtual bool invoke_command_to_peer(int command, const epee::span<const uint8_t> req_buff, std::string& resp_buff, const epee::net_utils::connection_context_base& context);
317  virtual bool invoke_notify_to_peer(int command, const epee::span<const uint8_t> req_buff, const epee::net_utils::connection_context_base& context);
318  virtual bool drop_connection(const epee::net_utils::connection_context_base& context);
319  virtual void request_callback(const epee::net_utils::connection_context_base& context);
320  virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f);
321  virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f);
322  virtual bool add_host_fail(const epee::net_utils::network_address &address);
323  //----------------- i_connection_filter --------------------------------------------------------
324  virtual bool is_remote_host_allowed(const epee::net_utils::network_address &address);
325  //-----------------------------------------------------------------------------------------------
326  bool parse_peer_from_string(epee::net_utils::network_address& pe, const std::string& node_addr, uint16_t default_port = 0);
327  bool handle_command_line(
328  const boost::program_options::variables_map& vm
329  );
330  bool idle_worker();
331  bool handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context);
332  bool get_local_node_data(basic_node_data& node_data, const network_zone& zone);
333  //bool get_local_handshake_data(handshake_data& hshd);
334 
335  bool merge_peerlist_with_local(const std::vector<peerlist_entry>& bs);
336  bool fix_time_delta(std::vector<peerlist_entry>& local_peerlist, time_t local_time, int64_t& delta);
337 
338  bool connections_maker();
339  bool peer_sync_idle_maker();
340  bool do_handshake_with_peer(peerid_type& pi, p2p_connection_context& context, bool just_take_peerlist = false);
341  bool do_peer_timed_sync(const epee::net_utils::connection_context_base& context, peerid_type peer_id);
342 
343  bool make_new_connection_from_anchor_peerlist(const std::vector<anchor_peerlist_entry>& anchor_peerlist);
344  bool make_new_connection_from_peerlist(network_zone& zone, bool use_white_list);
345  bool try_to_connect_and_handshake_with_new_peer(const epee::net_utils::network_address& na, bool just_take_peerlist = false, uint64_t last_seen_stamp = 0, PeerType peer_type = white, uint64_t first_seen_stamp = 0);
346  size_t get_random_index_with_fixed_probability(size_t max_index);
347  bool is_peer_used(const peerlist_entry& peer);
348  bool is_peer_used(const anchor_peerlist_entry& peer);
349  bool is_addr_connected(const epee::net_utils::network_address& peer);
350  void add_upnp_port_mapping(uint32_t port);
351  void delete_upnp_port_mapping(uint32_t port);
352  template<class t_callback>
353  bool try_ping(basic_node_data& node_data, p2p_connection_context& context, const t_callback &cb);
354  bool try_get_support_flags(const p2p_connection_context& context, std::function<void(p2p_connection_context&, const uint32_t&)> f);
355  bool make_expected_connections_count(network_zone& zone, PeerType peer_type, size_t expected_connections);
356  void cache_connect_fail_info(const epee::net_utils::network_address& addr);
357  bool is_addr_recently_failed(const epee::net_utils::network_address& addr);
358  bool is_priority_node(const epee::net_utils::network_address& na);
359  std::set<std::string> get_seed_nodes(cryptonote::network_type nettype) const;
360  bool connect_to_seed();
361 
362  template <class Container>
363  bool connect_to_peerlist(const Container& peers);
364 
365  template <class Container>
366  bool parse_peers_and_add_to_container(const boost::program_options::variables_map& vm, const command_line::arg_descriptor<std::vector<std::string> > & arg, Container& container);
367 
368  bool set_max_out_peers(network_zone& zone, int64_t max);
369  bool set_max_in_peers(network_zone& zone, int64_t max);
370  bool set_tos_flag(const boost::program_options::variables_map& vm, int limit);
371 
372  bool set_rate_up_limit(const boost::program_options::variables_map& vm, int64_t limit);
373  bool set_rate_down_limit(const boost::program_options::variables_map& vm, int64_t limit);
374  bool set_rate_limit(const boost::program_options::variables_map& vm, int64_t limit);
375 
376  bool has_too_many_connections(const epee::net_utils::network_address &address);
377  uint64_t get_connections_count();
378  size_t get_incoming_connections_count();
379  size_t get_incoming_connections_count(network_zone&);
380  size_t get_outgoing_connections_count();
381  size_t get_outgoing_connections_count(network_zone&);
382 
383  bool check_connection_and_handshake_with_peer(const epee::net_utils::network_address& na, uint64_t last_seen_stamp);
384  bool gray_peerlist_housekeeping();
385  bool check_incoming_connections();
386 
387  void kill() {
388  _info("Killing the net_node");
389  is_closing = true;
390  if(mPeersLoggerThread != nullptr)
391  mPeersLoggerThread->join(); // make sure the thread finishes
392  _info("Joined extra background net_node threads");
393  }
394 
395  //debug functions
396  std::string print_connections_container();
397 
398 
399  public:
400 
401  void set_save_graph(bool save_graph)
402  {
403  m_save_graph = save_graph;
404  epee::net_utils::connection_basic::set_save_graph(save_graph);
405  }
406 
407  void set_rpc_port(uint16_t rpc_port)
408  {
409  m_rpc_port = rpc_port;
410  }
411 
412  private:
413  std::string m_config_folder;
414 
418  uint32_t m_external_port;
419  uint16_t m_rpc_port;
422  bool m_no_igd;
423  bool m_offline;
424  std::atomic<bool> m_save_graph;
425  std::atomic<bool> is_closing;
426  std::unique_ptr<boost::thread> mPeersLoggerThread;
427  //critical_section m_connections_lock;
428  //connections_indexed_container m_connections;
429 
430  t_payload_net_handler& m_payload_handler;
432 
433  epee::math_helper::once_a_time_seconds<P2P_DEFAULT_HANDSHAKE_INTERVAL> m_peer_handshake_idle_maker_interval;
434  epee::math_helper::once_a_time_seconds<1> m_connections_maker_interval;
435  epee::math_helper::once_a_time_seconds<60*30, false> m_peerlist_store_interval;
436  epee::math_helper::once_a_time_seconds<60> m_gray_peerlist_housekeeping_interval;
437  epee::math_helper::once_a_time_seconds<3600, false> m_incoming_connections_interval;
438 
439 #ifdef ALLOW_DEBUG_COMMANDS
440  uint64_t m_last_stat_request_time;
441 #endif
442  std::list<epee::net_utils::network_address> m_priority_peers;
443  std::vector<epee::net_utils::network_address> m_exclusive_peers;
444  std::vector<epee::net_utils::network_address> m_seed_nodes;
446  std::vector<nodetool::peerlist_entry> m_command_line_peers;
447  uint64_t m_peer_livetime;
448  //keep connections to initiate some interactions
449 
450 
451  static boost::optional<p2p_connection_context> public_connect(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
452  static boost::optional<p2p_connection_context> socks_connect(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
453 
454 
455  /* A `std::map` provides constant iterators and key/value pointers even with
456  inserts/erases to _other_ elements. This makes the configuration step easier
457  since references can safely be stored on the stack. Do not insert/erase
458  after configuration and before destruction, lock safety would need to be
459  added. `std::map::operator[]` WILL insert! */
460  std::map<epee::net_utils::zone, network_zone> m_network_zones;
461 
462 
463  std::map<epee::net_utils::network_address, time_t> m_conn_fails_cache;
464  epee::critical_section m_conn_fails_cache_lock;
465 
466  epee::critical_section m_blocked_hosts_lock;
467  std::map<std::string, time_t> m_blocked_hosts;
468 
469  epee::critical_section m_host_fails_score_lock;
470  std::map<std::string, uint64_t> m_host_fails_score;
471 
473  std::array<std::list<epee::net_utils::network_address>, 1 << CRYPTONOTE_PRUNING_LOG_STRIPES> m_used_stripe_peers;
474 
477 
478  epee::net_utils::ssl_support_t m_ssl_support;
479  };
480 
495 
501 
505 
507 }
508 
509 POP_WARNINGS
510 
static void init(std::string cache_filename)
Definition: blockchain_blackball.cpp:224
Definition: net_node.h:120
virtual std::map< std::string, time_t > get_blocked_hosts()
Definition: net_node.h:252
peerlist_storage m_peerlist_storage
Definition: net_node.h:431
std::atomic< bool > m_save_graph
Definition: net_node.h:424
std::map< epee::net_utils::zone, network_zone > m_network_zones
Definition: net_node.h:460
bool m_first_connection_maker_call
Definition: net_node.h:416
std::vector< nodetool::peerlist_entry > m_command_line_peers
Definition: net_node.h:446
epee::critical_section m_conn_fails_cache_lock
Definition: net_node.h:464
epee::misc_utils::struct_init< config_t > config
Definition: net_node.h:147
uint64_t m_peer_livetime
Definition: net_node.h:447
boost::optional< p2p_connection_context >(network_zone &, epee::net_utils::network_address const &, epee::net_utils::ssl_support_t) connect_func
Definition: net_node.h:133
std::list< epee::net_utils::network_address > m_priority_peers
Definition: net_node.h:442
boost::mutex m_used_stripe_peers_mutex
Definition: net_node.h:472
bool m_offline
Definition: net_node.h:423
std::string m_config_folder
Definition: net_node.h:413
uint32_t get_this_peer_port()
Definition: net_node.h:233
void kill()
Definition: net_node.h:387
PeerType
Definition: net_node.h:291
std::unique_ptr< boost::thread > mPeersLoggerThread
Definition: net_node.h:426
std::atomic< bool > is_closing
Definition: net_node.h:425
std::map< epee::net_utils::network_address, time_t > m_conn_fails_cache
Definition: net_node.h:463
std::map< std::string, time_t > m_blocked_hosts
Definition: net_node.h:467
CHAIN_LEVIN_NOTIFY_MAP2(p2p_connection_context)
bool m_allow_local_ip
Definition: net_node.h:420
epee::net_utils::boosted_tcp_server< epee::levin::async_protocol_handler< p2p_connection_context > > net_server
Definition: net_node.h:130
void cache_connect_fail_info(const epee::net_utils::network_address &addr)
epee::critical_section m_blocked_hosts_lock
Definition: net_node.h:466
epee::math_helper::once_a_time_seconds< 60 *30, false > m_peerlist_store_interval
Definition: net_node.h:435
epee::math_helper::once_a_time_seconds< 1 > m_connections_maker_interval
Definition: net_node.h:434
epee::math_helper::once_a_time_seconds< P2P_DEFAULT_HANDSHAKE_INTERVAL > m_peer_handshake_idle_maker_interval
Definition: net_node.h:433
epee::critical_section m_host_fails_score_lock
Definition: net_node.h:469
epee::math_helper::once_a_time_seconds< 60 > m_gray_peerlist_housekeeping_interval
Definition: net_node.h:436
bool m_fallback_seed_nodes_added
Definition: net_node.h:445
std::vector< epee::net_utils::network_address > m_seed_nodes
Definition: net_node.h:444
bool merge_peerlist_with_local(const std::vector< peerlist_entry > &bs)
uint16_t m_rpc_port
Definition: net_node.h:419
uint32_t m_external_port
Definition: net_node.h:418
COMMAND_REQUEST_STAT_INFO_T< typename t_payload_net_handler::stat_info > COMMAND_REQUEST_STAT_INFO
Definition: net_node.h:270
bool m_no_igd
Definition: net_node.h:422
epee::math_helper::once_a_time_seconds< 3600, false > m_incoming_connections_interval
Definition: net_node.h:437
t_payload_net_handler payload_net_handler
Definition: net_node.h:210
size_t get_zone_count() const
Definition: net_node.h:246
std::map< std::string, uint64_t > m_host_fails_score
Definition: net_node.h:470
COMMAND_HANDSHAKE_T< typename t_payload_net_handler::payload_type > COMMAND_HANDSHAKE
Definition: net_node.h:127
boost::uuids::uuid m_network_id
Definition: net_node.h:475
COMMAND_TIMED_SYNC_T< typename t_payload_net_handler::payload_type > COMMAND_TIMED_SYNC
Definition: net_node.h:128
void set_save_graph(bool save_graph)
Definition: net_node.h:401
bool parse_peer_from_string(epee::net_utils::network_address &pe, const std::string &node_addr, uint16_t default_port=0)
cryptonote::network_type m_nettype
Definition: net_node.h:476
p2p_connection_context_t< typename t_payload_net_handler::connection_context > p2p_connection_context
Definition: net_node.h:125
t_payload_net_handler & m_payload_handler
Definition: net_node.h:430
bool m_hide_my_port
Definition: net_node.h:421
epee::net_utils::ssl_support_t m_ssl_support
Definition: net_node.h:478
uint32_t m_listening_port
Definition: net_node.h:417
CHAIN_LEVIN_INVOKE_MAP2(p2p_connection_context)
std::array< std::list< epee::net_utils::network_address >, 1<< CRYPTONOTE_PRUNING_LOG_STRIPES > m_used_stripe_peers
Definition: net_node.h:473
bool m_have_address
Definition: net_node.h:415
std::vector< epee::net_utils::network_address > m_exclusive_peers
Definition: net_node.h:443
bool check_trust(const proof_of_trust &tr, epee::net_utils::zone zone_type)
node_server(t_payload_net_handler &payload_handler)
Definition: net_node.h:212
void set_rpc_port(uint16_t rpc_port)
Definition: net_node.h:407
Definition: net_peerlist.h:100
Definition: net_peerlist.h:63
#define tr(x)
Definition: common_defines.h:4
#define P2P_DEFAULT_PACKET_MAX_SIZE
Definition: cryptonote_config.h:124
#define P2P_DEFAULT_LIMIT_RATE_DOWN
Definition: cryptonote_config.h:135
#define P2P_IP_BLOCKTIME
Definition: cryptonote_config.h:138
#define P2P_DEFAULT_PEERS_IN_HANDSHAKE
Definition: cryptonote_config.h:125
#define CRYPTONOTE_PRUNING_LOG_STRIPES
Definition: cryptonote_config.h:184
#define P2P_DEFAULT_CONNECTION_TIMEOUT
Definition: cryptonote_config.h:126
#define P2P_DEFAULT_LIMIT_RATE_UP
Definition: cryptonote_config.h:134
#define P2P_DEFAULT_PING_CONNECTION_TIMEOUT
Definition: cryptonote_config.h:128
#define P2P_DEFAULT_HANDSHAKE_INTERVAL
Definition: cryptonote_config.h:123
PUSH_WARNINGS
Definition: hash-ops.h:54
Definition: cryptonote_config.h:190
crypto namespace.
Definition: crypto.cpp:58
void rand(size_t N, uint8_t *bytes)
Definition: crypto.h:197
network_type
Definition: cryptonote_config.h:243
void init_options(boost::program_options::options_description &hidden_options, boost::program_options::options_description &normal_options)
Definition: posix_daemonizer.inl:57
Definition: cryptonote_format_utils.h:44
mdb_size_t count(MDB_cursor *cur)
Definition: value_stream.cpp:39
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
Definition: net_node.cpp:110
const command_line::arg_descriptor< std::vector< std::string > > arg_p2p_add_priority_node
Definition: net_node.cpp:128
bool is_filtered_command(const epee::net_utils::network_address &address, int command)
Definition: net_node.cpp:273
boost::uuids::uuid uuid
Definition: net_node_common.h:43
const command_line::arg_descriptor< int > arg_tos_flag
Definition: net_node.cpp:140
const command_line::arg_descriptor< uint32_t > arg_p2p_external_port
Definition: net_node.cpp:125
const int64_t default_limit_up
Definition: net_node.h:481
const command_line::arg_descriptor< bool > arg_offline
uint64_t peerid_type
Definition: p2p_protocol_defs.h:51
const command_line::arg_descriptor< bool > arg_no_igd
Definition: net_node.cpp:137
const command_line::arg_descriptor< int64_t > arg_limit_rate
Definition: net_node.cpp:144
const command_line::arg_descriptor< std::string, false, true, 2 > arg_p2p_bind_port
Definition: net_node.cpp:112
const command_line::arg_descriptor< bool > arg_no_sync
Definition: net_node.cpp:135
boost::optional< std::vector< anonymous_inbound > > get_anonymous_inbounds(boost::program_options::variables_map const &vm)
Definition: net_node.cpp:206
const command_line::arg_descriptor< bool > arg_p2p_allow_local_ip
Definition: net_node.cpp:126
const command_line::arg_descriptor< int64_t > arg_limit_rate_down
Definition: net_node.cpp:143
const command_line::arg_descriptor< std::string > arg_p2p_bind_ip
Definition: net_node.cpp:111
const command_line::arg_descriptor< int64_t > arg_limit_rate_up
Definition: net_node.cpp:142
boost::optional< std::vector< proxy > > get_proxies(boost::program_options::variables_map const &vm)
Definition: net_node.cpp:148
const command_line::arg_descriptor< std::vector< std::string > > arg_anonymous_inbound
Definition: net_node.cpp:133
const command_line::arg_descriptor< int64_t > arg_out_peers
Definition: net_node.cpp:138
boost::optional< boost::asio::ip::tcp::socket > socks_connect_internal(const std::atomic< bool > &stop_signal, boost::asio::io_service &service, const boost::asio::ip::tcp::endpoint &proxy, const epee::net_utils::network_address &remote)
Definition: net_node.cpp:293
const command_line::arg_descriptor< bool > arg_p2p_hide_my_port
Definition: net_node.cpp:134
const command_line::arg_descriptor< bool > arg_save_graph
Definition: net_node.cpp:146
const command_line::arg_descriptor< int64_t > arg_in_peers
Definition: net_node.cpp:139
const command_line::arg_descriptor< std::vector< std::string > > arg_p2p_seed_node
Definition: net_node.cpp:131
const command_line::arg_descriptor< std::vector< std::string > > arg_proxy
Definition: net_node.cpp:132
const command_line::arg_descriptor< std::vector< std::string > > arg_p2p_add_peer
Definition: net_node.cpp:127
const int64_t default_limit_down
Definition: net_node.h:482
const command_line::arg_descriptor< std::vector< std::string > > arg_p2p_add_exclusive_node
Definition: net_node.cpp:129
#define false
Definition: stdbool.h:38
Definition: command_line.h:54
Definition: p2p_protocol_defs.h:189
Definition: p2p_protocol_defs.h:313
epee::misc_utils::struct_init< request_t > request
Definition: p2p_protocol_defs.h:330
epee::misc_utils::struct_init< response_t > response
Definition: p2p_protocol_defs.h:342
Definition: p2p_protocol_defs.h:253
Definition: p2p_protocol_defs.h:95
Definition: net_node.h:79
std::string local_ip
Definition: net_node.h:89
anonymous_inbound()
Definition: net_node.h:80
std::string local_port
Definition: net_node.h:90
epee::net_utils::network_address our_address
Definition: net_node.h:91
epee::net_utils::network_address default_remote
Definition: net_node.h:92
std::int64_t max_connections
Definition: net_node.h:88
Definition: p2p_protocol_defs.h:165
Definition: net_node_common.h:48
Definition: p2p_protocol_defs.h:145
Definition: net_node.h:123
Definition: net_node.h:121
Definition: net_node.h:122
Definition: net_node.h:136
network_config m_net_config
Definition: net_node.h:143
config_t()
Definition: net_node.h:137
uint64_t m_peer_id
Definition: net_node.h:144
uint32_t m_support_flags
Definition: net_node.h:145
Definition: net_node.h:150
std::atomic< unsigned int > m_current_number_of_out_peers
Definition: net_node.h:191
void set_config_defaults() noexcept
Definition: net_node.h:196
net_server m_net_server
Definition: net_node.h:184
std::atomic< unsigned int > m_current_number_of_in_peers
Definition: net_node.h:192
std::string m_bind_ip
Definition: net_node.h:185
boost::asio::ip::tcp::endpoint m_proxy_address
Definition: net_node.h:190
network_zone()
Definition: net_node.h:151
bool m_can_pingback
Definition: net_node.h:193
std::string m_port
Definition: net_node.h:186
epee::net_utils::network_address m_our_address
Definition: net_node.h:187
network_zone(boost::asio::io_service &public_service)
Definition: net_node.h:167
peerlist_manager m_peerlist
Definition: net_node.h:188
config m_config
Definition: net_node.h:189
connect_func * m_connect
Definition: net_node.h:183
Definition: net_node.h:108
uint32_t support_flags
Definition: net_node.h:112
peerid_type peer_id
Definition: net_node.h:111
p2p_connection_context_t()
Definition: net_node.h:109
bool m_in_timedsync
Definition: net_node.h:113
Definition: p2p_protocol_defs.h:75
Definition: net_node.h:66
proxy()
Definition: net_node.h:67
epee::net_utils::zone zone
Definition: net_node.h:75
boost::asio::ip::tcp::endpoint address
Definition: net_node.h:74
std::int64_t max_connections
Definition: net_node.h:73
DISABLE_VS_WARNINGS(4244 4345 4503) using namespace crypto