Monero
net_peerlist.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2020, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30 
31 #pragma once
32 
33 #include <iosfwd>
34 #include <list>
35 #include <string>
36 #include <vector>
37 
38 #include <boost/multi_index_container.hpp>
39 #include <boost/multi_index/ordered_index.hpp>
40 #include <boost/multi_index/identity.hpp>
41 #include <boost/multi_index/member.hpp>
42 #include <boost/optional/optional.hpp>
43 #include <boost/range/adaptor/reversed.hpp>
44 
45 
46 #include "crypto/crypto.h"
47 #include "cryptonote_config.h"
48 #include "net/enums.h"
49 #include "net/local_ip.h"
50 #include "p2p_protocol_defs.h"
51 #include "syncobj.h"
52 
53 namespace nodetool
54 {
56  {
57  std::vector<peerlist_entry> white;
58  std::vector<peerlist_entry> gray;
59  std::vector<anchor_peerlist_entry> anchor;
60  };
61 
63  {
64  public:
66  : m_types{}
67  {}
68 
70  static boost::optional<peerlist_storage> open(std::istream& src, const bool new_format);
71 
73  static boost::optional<peerlist_storage> open(const std::string& path);
74 
76  peerlist_storage(const peerlist_storage&) = delete;
77 
78  ~peerlist_storage() noexcept;
79 
81  peerlist_storage& operator=(const peerlist_storage&) = delete;
82 
84  bool store(std::ostream& dest, const peerlist_types& other) const;
85 
87  bool store(const std::string& path, const peerlist_types& other) const;
88 
90  peerlist_types take_zone(epee::net_utils::zone zone);
91 
92  private:
94  };
95 
96  /************************************************************************/
97  /* */
98  /************************************************************************/
100  {
101  public:
102  bool init(peerlist_types&& peers, bool allow_local_ip);
103  size_t get_white_peers_count(){CRITICAL_REGION_LOCAL(m_peerlist_lock); return m_peers_white.size();}
104  size_t get_gray_peers_count(){CRITICAL_REGION_LOCAL(m_peerlist_lock); return m_peers_gray.size();}
105  bool merge_peerlist(const std::vector<peerlist_entry>& outer_bs, const std::function<bool(const peerlist_entry&)> &f = NULL);
106  bool get_peerlist_head(std::vector<peerlist_entry>& bs_head, bool anonymize, uint32_t depth = P2P_DEFAULT_PEERS_IN_HANDSHAKE);
107  void get_peerlist(std::vector<peerlist_entry>& pl_gray, std::vector<peerlist_entry>& pl_white);
108  void get_peerlist(peerlist_types& peers);
109  bool get_white_peer_by_index(peerlist_entry& p, size_t i);
110  bool get_gray_peer_by_index(peerlist_entry& p, size_t i);
111  template<typename F> bool foreach(bool white, const F &f);
112  void evict_host_from_peerlist(bool white, const peerlist_entry& pr);
113  bool append_with_peer_white(const peerlist_entry& pr);
114  bool append_with_peer_gray(const peerlist_entry& pr);
115  bool append_with_peer_anchor(const anchor_peerlist_entry& ple);
116  bool set_peer_just_seen(peerid_type peer, const epee::net_utils::network_address& addr, uint32_t pruning_seed, uint16_t rpc_port, uint32_t rpc_credits_per_hash);
117  bool is_host_allowed(const epee::net_utils::network_address &address);
118  bool get_random_gray_peer(peerlist_entry& pe);
119  bool remove_from_peer_gray(const peerlist_entry& pe);
120  bool get_and_empty_anchor_peerlist(std::vector<anchor_peerlist_entry>& apl);
121  bool remove_from_peer_anchor(const epee::net_utils::network_address& addr);
122  bool remove_from_peer_white(const peerlist_entry& pe);
123  template<typename F> size_t filter(bool white, const F &f); // f returns true: drop, false: keep
124 
125  private:
126  struct by_time{};
127  struct by_id{};
128  struct by_addr{};
129 
131  {
132  modify_all_but_id(const peerlist_entry& ple):m_ple(ple){}
134  {
135  e.id = m_ple.id;
136  }
137  private:
139  };
140 
141  struct modify_all
142  {
143  modify_all(const peerlist_entry& ple):m_ple(ple){}
145  {
146  e = m_ple;
147  }
148  private:
150  };
151 
153  {
154  modify_last_seen(time_t last_seen):m_last_seen(last_seen){}
156  {
157  e.last_seen = m_last_seen;
158  }
159  private:
160  time_t m_last_seen;
161  };
162 
163 
164  typedef boost::multi_index_container<
166  boost::multi_index::indexed_by<
167  // access by peerlist_entry::net_adress
168  boost::multi_index::ordered_unique<boost::multi_index::tag<by_addr>, boost::multi_index::member<peerlist_entry,epee::net_utils::network_address,&peerlist_entry::adr> >,
169  // sort by peerlist_entry::last_seen<
170  boost::multi_index::ordered_non_unique<boost::multi_index::tag<by_time>, boost::multi_index::member<peerlist_entry,int64_t,&peerlist_entry::last_seen> >
171  >
173 
174  typedef boost::multi_index_container<
176  boost::multi_index::indexed_by<
177  // access by anchor_peerlist_entry::net_adress
178  boost::multi_index::ordered_unique<boost::multi_index::tag<by_addr>, boost::multi_index::member<anchor_peerlist_entry,epee::net_utils::network_address,&anchor_peerlist_entry::adr> >,
179  // sort by anchor_peerlist_entry::first_seen
180  boost::multi_index::ordered_non_unique<boost::multi_index::tag<by_time>, boost::multi_index::member<anchor_peerlist_entry,int64_t,&anchor_peerlist_entry::first_seen> >
181  >
183 
184  private:
185  void trim_white_peerlist();
186  void trim_gray_peerlist();
187 
188  friend class boost::serialization::access;
189  epee::critical_section m_peerlist_lock;
190  std::string m_config_folder;
192 
193 
197  };
198  //--------------------------------------------------------------------------------------------------
200  {
201  while(m_peers_gray.size() > P2P_LOCAL_GRAY_PEERLIST_LIMIT)
202  {
203  peers_indexed::index<by_time>::type& sorted_index=m_peers_gray.get<by_time>();
204  sorted_index.erase(sorted_index.begin());
205  }
206  }
207  //--------------------------------------------------------------------------------------------------
209  {
210  while(m_peers_white.size() > P2P_LOCAL_WHITE_PEERLIST_LIMIT)
211  {
212  peers_indexed::index<by_time>::type& sorted_index=m_peers_white.get<by_time>();
213  sorted_index.erase(sorted_index.begin());
214  }
215  }
216  //--------------------------------------------------------------------------------------------------
217  inline
218  bool peerlist_manager::merge_peerlist(const std::vector<peerlist_entry>& outer_bs, const std::function<bool(const peerlist_entry&)> &f)
219  {
220  CRITICAL_REGION_LOCAL(m_peerlist_lock);
221  for(const peerlist_entry& be: outer_bs)
222  {
223  if (!f || f(be))
224  append_with_peer_gray(be);
225  }
226  // delete extra elements
227  trim_gray_peerlist();
228  return true;
229  }
230  //--------------------------------------------------------------------------------------------------
231  inline
233  {
234  CRITICAL_REGION_LOCAL(m_peerlist_lock);
235  if(i >= m_peers_white.size())
236  return false;
237 
238  peers_indexed::index<by_time>::type& by_time_index = m_peers_white.get<by_time>();
239  p = *epee::misc_utils::move_it_backward(--by_time_index.end(), i);
240  return true;
241  }
242  //--------------------------------------------------------------------------------------------------
243  inline
245  {
246  CRITICAL_REGION_LOCAL(m_peerlist_lock);
247  if(i >= m_peers_gray.size())
248  return false;
249 
250  peers_indexed::index<by_time>::type& by_time_index = m_peers_gray.get<by_time>();
251  p = *epee::misc_utils::move_it_backward(--by_time_index.end(), i);
252  return true;
253  }
254  //--------------------------------------------------------------------------------------------------
255  inline
256  bool peerlist_manager::is_host_allowed(const epee::net_utils::network_address &address)
257  {
258  //never allow loopback ip
259  if(address.is_loopback())
260  return false;
261 
262  if(!m_allow_local_ip && address.is_local())
263  return false;
264 
265  return true;
266  }
267  //--------------------------------------------------------------------------------------------------
268  inline
269  bool peerlist_manager::get_peerlist_head(std::vector<peerlist_entry>& bs_head, bool anonymize, uint32_t depth)
270  {
271  CRITICAL_REGION_LOCAL(m_peerlist_lock);
272  peers_indexed::index<by_time>::type& by_time_index=m_peers_white.get<by_time>();
273  uint32_t cnt = 0;
274 
275  // picks a random set of peers within the whole set, rather pick the first depth elements.
276  // The intent is that if someone asks twice, they can't easily tell:
277  // - this address was not in the first list, but is in the second, so the only way this can be
278  // is if its last_seen was recently reset, so this means the target node recently had a new
279  // connection to that address
280  // - this address was in the first list, and not in the second, which means either the address
281  // was moved to the gray list (if it's not accessible, which the attacker can check if
282  // the address accepts incoming connections) or it was the oldest to still fit in the 250 items,
283  // so its last_seen is old.
284  //
285  // See Cao, Tong et al. "Exploring the Monero Peer-to-Peer Network". https://eprint.iacr.org/2019/411
286  //
287  const uint32_t pick_depth = anonymize ? m_peers_white.size() : depth;
288  bs_head.reserve(pick_depth);
289  for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index))
290  {
291  if(cnt++ >= pick_depth)
292  break;
293 
294  bs_head.push_back(vl);
295  }
296 
297  if (anonymize)
298  {
299  std::shuffle(bs_head.begin(), bs_head.end(), crypto::random_device{});
300  if (bs_head.size() > depth)
301  bs_head.resize(depth);
302  for (auto &e: bs_head)
303  e.last_seen = 0;
304  }
305 
306  return true;
307  }
308  //--------------------------------------------------------------------------------------------------
309  template<typename F> inline
310  bool peerlist_manager::foreach(bool white, const F &f)
311  {
312  CRITICAL_REGION_LOCAL(m_peerlist_lock);
313  peers_indexed::index<by_time>::type& by_time_index = white ? m_peers_white.get<by_time>() : m_peers_gray.get<by_time>();
314  for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index))
315  if (!f(vl))
316  return false;
317  return true;
318  }
319  //--------------------------------------------------------------------------------------------------
320  inline
321  bool peerlist_manager::set_peer_just_seen(peerid_type peer, const epee::net_utils::network_address& addr, uint32_t pruning_seed, uint16_t rpc_port, uint32_t rpc_credits_per_hash)
322  {
323  TRY_ENTRY();
324  CRITICAL_REGION_LOCAL(m_peerlist_lock);
325  //find in white list
326  peerlist_entry ple;
327  ple.adr = addr;
328  ple.id = peer;
329  ple.last_seen = time(NULL);
330  ple.pruning_seed = pruning_seed;
331  ple.rpc_port = rpc_port;
332  ple.rpc_credits_per_hash = rpc_credits_per_hash;
333  return append_with_peer_white(ple);
334  CATCH_ENTRY_L0("peerlist_manager::set_peer_just_seen()", false);
335  }
336  //--------------------------------------------------------------------------------------------------
337  inline
339  {
340  TRY_ENTRY();
341  if(!is_host_allowed(ple.adr))
342  return true;
343 
344  CRITICAL_REGION_LOCAL(m_peerlist_lock);
345  //find in white list
346  auto by_addr_it_wt = m_peers_white.get<by_addr>().find(ple.adr);
347  if(by_addr_it_wt == m_peers_white.get<by_addr>().end())
348  {
349  //put new record into white list
350  evict_host_from_peerlist(true, ple);
351  m_peers_white.insert(ple);
352  trim_white_peerlist();
353  }else
354  {
355  //update record in white list
356  peerlist_entry new_ple = ple;
357  if (by_addr_it_wt->pruning_seed && ple.pruning_seed == 0) // guard against older nodes not passing pruning info around
358  new_ple.pruning_seed = by_addr_it_wt->pruning_seed;
359  if (by_addr_it_wt->rpc_port && ple.rpc_port == 0) // guard against older nodes not passing RPC port around
360  new_ple.rpc_port = by_addr_it_wt->rpc_port;
361  new_ple.last_seen = by_addr_it_wt->last_seen; // do not overwrite the last seen timestamp, incoming peer list are untrusted
362  m_peers_white.replace(by_addr_it_wt, new_ple);
363  }
364  //remove from gray list, if need
365  auto by_addr_it_gr = m_peers_gray.get<by_addr>().find(ple.adr);
366  if(by_addr_it_gr != m_peers_gray.get<by_addr>().end())
367  {
368  m_peers_gray.erase(by_addr_it_gr);
369  }
370  return true;
371  CATCH_ENTRY_L0("peerlist_manager::append_with_peer_white()", false);
372  }
373  //--------------------------------------------------------------------------------------------------
374  inline
376  {
377  TRY_ENTRY();
378  if(!is_host_allowed(ple.adr))
379  return true;
380 
381  CRITICAL_REGION_LOCAL(m_peerlist_lock);
382  //find in white list
383  auto by_addr_it_wt = m_peers_white.get<by_addr>().find(ple.adr);
384  if(by_addr_it_wt != m_peers_white.get<by_addr>().end())
385  return true;
386 
387  //update gray list
388  auto by_addr_it_gr = m_peers_gray.get<by_addr>().find(ple.adr);
389  if(by_addr_it_gr == m_peers_gray.get<by_addr>().end())
390  {
391  //put new record into white list
392  m_peers_gray.insert(ple);
393  trim_gray_peerlist();
394  }else
395  {
396  //update record in gray list
397  peerlist_entry new_ple = ple;
398  if (by_addr_it_gr->pruning_seed && ple.pruning_seed == 0) // guard against older nodes not passing pruning info around
399  new_ple.pruning_seed = by_addr_it_gr->pruning_seed;
400  if (by_addr_it_gr->rpc_port && ple.rpc_port == 0) // guard against older nodes not passing RPC port around
401  new_ple.rpc_port = by_addr_it_gr->rpc_port;
402  new_ple.last_seen = by_addr_it_gr->last_seen; // do not overwrite the last seen timestamp, incoming peer list are untrusted
403  m_peers_gray.replace(by_addr_it_gr, new_ple);
404  }
405  return true;
406  CATCH_ENTRY_L0("peerlist_manager::append_with_peer_gray()", false);
407  }
408  //--------------------------------------------------------------------------------------------------
409  inline
411  {
412  TRY_ENTRY();
413 
414  CRITICAL_REGION_LOCAL(m_peerlist_lock);
415 
416  auto by_addr_it_anchor = m_peers_anchor.get<by_addr>().find(ple.adr);
417 
418  if(by_addr_it_anchor == m_peers_anchor.get<by_addr>().end()) {
419  m_peers_anchor.insert(ple);
420  }
421 
422  return true;
423 
424  CATCH_ENTRY_L0("peerlist_manager::append_with_peer_anchor()", false);
425  }
426  //--------------------------------------------------------------------------------------------------
427  inline
429  {
430  TRY_ENTRY();
431 
432  CRITICAL_REGION_LOCAL(m_peerlist_lock);
433 
434  if (m_peers_gray.empty()) {
435  return false;
436  }
437 
438  size_t random_index = crypto::rand_idx(m_peers_gray.size());
439 
440  peers_indexed::index<by_time>::type& by_time_index = m_peers_gray.get<by_time>();
441  pe = *epee::misc_utils::move_it_backward(--by_time_index.end(), random_index);
442 
443  return true;
444 
445  CATCH_ENTRY_L0("peerlist_manager::get_random_gray_peer()", false);
446  }
447  //--------------------------------------------------------------------------------------------------
448  inline
450  {
451  TRY_ENTRY();
452 
453  CRITICAL_REGION_LOCAL(m_peerlist_lock);
454 
455  peers_indexed::index_iterator<by_addr>::type iterator = m_peers_white.get<by_addr>().find(pe.adr);
456 
457  if (iterator != m_peers_white.get<by_addr>().end()) {
458  m_peers_white.erase(iterator);
459  }
460 
461  return true;
462 
463  CATCH_ENTRY_L0("peerlist_manager::remove_from_peer_white()", false);
464  }
465  //--------------------------------------------------------------------------------------------------
466  inline
468  {
469  TRY_ENTRY();
470 
471  CRITICAL_REGION_LOCAL(m_peerlist_lock);
472 
473  peers_indexed::index_iterator<by_addr>::type iterator = m_peers_gray.get<by_addr>().find(pe.adr);
474 
475  if (iterator != m_peers_gray.get<by_addr>().end()) {
476  m_peers_gray.erase(iterator);
477  }
478 
479  return true;
480 
481  CATCH_ENTRY_L0("peerlist_manager::remove_from_peer_gray()", false);
482  }
483  //--------------------------------------------------------------------------------------------------
484  inline
485  bool peerlist_manager::get_and_empty_anchor_peerlist(std::vector<anchor_peerlist_entry>& apl)
486  {
487  TRY_ENTRY();
488 
489  CRITICAL_REGION_LOCAL(m_peerlist_lock);
490 
491  auto begin = m_peers_anchor.get<by_time>().begin();
492  auto end = m_peers_anchor.get<by_time>().end();
493 
494  std::for_each(begin, end, [&apl](const anchor_peerlist_entry &a) {
495  apl.push_back(a);
496  });
497 
498  m_peers_anchor.get<by_time>().clear();
499 
500  return true;
501 
502  CATCH_ENTRY_L0("peerlist_manager::get_and_empty_anchor_peerlist()", false);
503  }
504  //--------------------------------------------------------------------------------------------------
505  inline
506  bool peerlist_manager::remove_from_peer_anchor(const epee::net_utils::network_address& addr)
507  {
508  TRY_ENTRY();
509 
510  CRITICAL_REGION_LOCAL(m_peerlist_lock);
511 
512  anchor_peers_indexed::index_iterator<by_addr>::type iterator = m_peers_anchor.get<by_addr>().find(addr);
513 
514  if (iterator != m_peers_anchor.get<by_addr>().end()) {
515  m_peers_anchor.erase(iterator);
516  }
517 
518  return true;
519 
520  CATCH_ENTRY_L0("peerlist_manager::remove_from_peer_anchor()", false);
521  }
522  //--------------------------------------------------------------------------------------------------
523  template<typename F> size_t peerlist_manager::filter(bool white, const F &f)
524  {
525  size_t filtered = 0;
526  TRY_ENTRY();
527  CRITICAL_REGION_LOCAL(m_peerlist_lock);
528  peers_indexed::index<by_addr>::type& sorted_index = white ? m_peers_gray.get<by_addr>() : m_peers_white.get<by_addr>();
529  auto i = sorted_index.begin();
530  while (i != sorted_index.end())
531  {
532  if (f(*i))
533  {
534  i = sorted_index.erase(i);
535  ++filtered;
536  }
537  else
538  ++i;
539  }
540  CATCH_ENTRY_L0("peerlist_manager::filter()", filtered);
541  return filtered;
542  }
543  //--------------------------------------------------------------------------------------------------
544 }
545 
size_t get_white_peers_count()
Definition: net_peerlist.h:103
int64_t last_seen
Definition: p2p_protocol_defs.h:75
Definition: net_peerlist.h:141
std::vector< peerlist_entry > white
Definition: net_peerlist.h:57
bool foreach(bool white, const F &f)
Definition: net_peerlist.h:310
bool append_with_peer_anchor(const anchor_peerlist_entry &ple)
Definition: net_peerlist.h:410
uint16_t rpc_port
Definition: p2p_protocol_defs.h:77
bool get_and_empty_anchor_peerlist(std::vector< anchor_peerlist_entry > &apl)
Definition: net_peerlist.h:485
static void init(std::string cache_filename)
Definition: blockchain_blackball.cpp:221
AddressType adr
Definition: p2p_protocol_defs.h:73
CXA_THROW_INFO_T void(* dest)(void *))
Definition: stack_trace.cpp:90
#define F(w, k)
Definition: sha512-blocks.c:61
static boost::optional< peerlist_storage > open(std::istream &src, const bool new_format)
Definition: net_peerlist.cpp:161
bool remove_from_peer_white(const peerlist_entry &pe)
Definition: net_peerlist.h:449
std::vector< peerlist_entry > gray
Definition: net_peerlist.h:58
peerlist_entry_base< epee::net_utils::network_address > peerlist_entry
Definition: p2p_protocol_defs.h:98
AddressType adr
Definition: p2p_protocol_defs.h:103
time_t m_last_seen
Definition: net_peerlist.h:160
bool remove_from_peer_anchor(const epee::net_utils::network_address &addr)
Definition: net_peerlist.h:506
modify_all(const peerlist_entry &ple)
Definition: net_peerlist.h:143
uint32_t pruning_seed
Definition: p2p_protocol_defs.h:76
Definition: blockchain_ancestry.cpp:71
modify_all_but_id(const peerlist_entry &ple)
Definition: net_peerlist.h:132
const peerlist_entry & m_ple
Definition: net_peerlist.h:149
void operator()(peerlist_entry &e)
Definition: net_peerlist.h:155
bool append_with_peer_gray(const peerlist_entry &pr)
Definition: net_peerlist.h:375
const
Definition: build_protob.py:9
modify_last_seen(time_t last_seen)
Definition: net_peerlist.h:154
Definition: net_peerlist.h:126
Definition: net_peerlist.h:127
void operator()(peerlist_entry &e)
Definition: net_peerlist.h:144
Definition: crypto.h:171
boost::multi_index_container< anchor_peerlist_entry, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< by_addr >, boost::multi_index::member< anchor_peerlist_entry, epee::net_utils::network_address,&anchor_peerlist_entry::adr > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< by_time >, boost::multi_index::member< anchor_peerlist_entry, int64_t,&anchor_peerlist_entry::first_seen > > > > anchor_peers_indexed
Definition: net_peerlist.h:182
std::vector< anchor_peerlist_entry > anchor
Definition: net_peerlist.h:59
std::enable_if< std::is_unsigned< T >::value, T >::type rand_idx(T sz)
Definition: crypto.h:191
bool get_white_peer_by_index(peerlist_entry &p, size_t i)
Definition: net_peerlist.h:232
~peerlist_storage() noexcept
Definition: net_peerlist.cpp:222
bool set_peer_just_seen(peerid_type peer, const epee::net_utils::network_address &addr, uint32_t pruning_seed, uint16_t rpc_port, uint32_t rpc_credits_per_hash)
Definition: net_peerlist.h:321
Definition: net_peerlist.h:55
static __thread int depth
Definition: threadpool.cpp:34
#define P2P_DEFAULT_PEERS_IN_HANDSHAKE
Definition: cryptonote_config.h:136
peerid_type id
Definition: p2p_protocol_defs.h:74
Definition: net_peerlist.h:62
default
Definition: build_protob.py:9
size_t get_gray_peers_count()
Definition: net_peerlist.h:104
Definition: p2p_protocol_defs.h:101
bool remove_from_peer_gray(const peerlist_entry &pe)
Definition: net_peerlist.h:467
uint64_t peerid_type
Definition: p2p_protocol_defs.h:48
anchor_peers_indexed m_peers_anchor
Definition: net_peerlist.h:196
void operator()(peerlist_entry &e)
Definition: net_peerlist.h:133
Definition: net_peerlist.h:152
#define P2P_LOCAL_GRAY_PEERLIST_LIMIT
Definition: cryptonote_config.h:131
Definition: net_peerlist.h:99
size_t filter(bool white, const F &f)
Definition: net_peerlist.h:523
const peerlist_entry & m_ple
Definition: net_peerlist.h:138
bool is_host_allowed(const epee::net_utils::network_address &address)
Definition: net_peerlist.h:256
bool get_random_gray_peer(peerlist_entry &pe)
Definition: net_peerlist.h:428
Definition: cryptonote_format_utils.h:43
void trim_white_peerlist()
Definition: net_peerlist.h:208
anchor_peerlist_entry_base< epee::net_utils::network_address > anchor_peerlist_entry
Definition: p2p_protocol_defs.h:119
std::string m_config_folder
Definition: net_peerlist.h:190
string a
Definition: MakeCryptoOps.py:15
bool merge_peerlist(const std::vector< peerlist_entry > &outer_bs, const std::function< bool(const peerlist_entry &)> &f=NULL)
Definition: net_peerlist.h:218
bool append_with_peer_white(const peerlist_entry &pr)
Definition: net_peerlist.h:338
Definition: levin_notify.h:51
void trim_gray_peerlist()
Definition: net_peerlist.h:199
uint32_t rpc_credits_per_hash
Definition: p2p_protocol_defs.h:78
bool get_gray_peer_by_index(peerlist_entry &p, size_t i)
Definition: net_peerlist.h:244
peerlist_types take_zone(epee::net_utils::zone zone)
Definition: net_peerlist.cpp:250
Definition: net_peerlist.h:128
peerlist_types m_types
Definition: net_peerlist.h:93
peers_indexed m_peers_white
Definition: net_peerlist.h:195
epee::critical_section m_peerlist_lock
Definition: net_peerlist.h:189
bool m_allow_local_ip
Definition: net_peerlist.h:191
boost::multi_index_container< peerlist_entry, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< by_addr >, boost::multi_index::member< peerlist_entry, epee::net_utils::network_address,&peerlist_entry::adr > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< by_time >, boost::multi_index::member< peerlist_entry, int64_t,&peerlist_entry::last_seen > > > > peers_indexed
Definition: net_peerlist.h:172
Definition: net_peerlist.h:130
peerlist_storage()
Definition: net_peerlist.h:65
peers_indexed m_peers_gray
Definition: net_peerlist.h:194
#define P2P_LOCAL_WHITE_PEERLIST_LIMIT
Definition: cryptonote_config.h:130
bool get_peerlist_head(std::vector< peerlist_entry > &bs_head, bool anonymize, uint32_t depth=P2P_DEFAULT_PEERS_IN_HANDSHAKE)
Definition: net_peerlist.h:269
bool store(std::ostream &dest, const peerlist_types &other) const
Save peers from this and other in stream dest.
Definition: net_peerlist.cpp:225
Definition: p2p_protocol_defs.h:71