39#include <boost/multi_index_container.hpp>
40#include <boost/multi_index/ordered_index.hpp>
41#include <boost/multi_index/identity.hpp>
42#include <boost/multi_index/member.hpp>
43#include <boost/optional/optional.hpp>
44#include <boost/range/adaptor/reversed.hpp>
57 std::vector<peerlist_entry>
white;
58 std::vector<peerlist_entry>
gray;
59 std::vector<anchor_peerlist_entry>
anchor;
70 static boost::optional<peerlist_storage>
open(std::istream& src,
const bool new_format);
73 static boost::optional<peerlist_storage>
open(
const std::string& path);
105 bool merge_peerlist(
const std::vector<peerlist_entry>& outer_bs,
const std::function<
bool(
const peerlist_entry&)> &f = NULL);
107 void get_peerlist(std::vector<peerlist_entry>& pl_gray, std::vector<peerlist_entry>& pl_white);
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,
bool trust_last_seen =
false);
120 bool get_and_empty_anchor_peerlist(std::vector<anchor_peerlist_entry>& apl);
123 template<
typename F>
size_t filter(
bool white,
const F &f);
164 typedef boost::multi_index_container<
166 boost::multi_index::indexed_by<
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> >,
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> >
174 typedef boost::multi_index_container<
176 boost::multi_index::indexed_by<
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> >,
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> >
189 friend class boost::serialization::access;
205 sorted_index.erase(sorted_index.begin());
214 sorted_index.erase(sorted_index.begin());
222 peers_indexed::index<by_time>::type& by_time_index = peerlist.get<
by_time>();
223 auto by_time_it = --by_time_index.end();
224 std::advance(by_time_it, -
static_cast<long long>(n));
297 bs_head.reserve(pick_depth);
298 for(
const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index))
300 if(cnt++ >= pick_depth)
303 bs_head.push_back(vl);
309 if (bs_head.size() >
depth)
310 bs_head.resize(
depth);
311 for (
auto &e: bs_head)
318 template<
typename F>
inline
323 for(
const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index))
343 CATCH_ENTRY_L0(
"peerlist_manager::set_peer_just_seen()",
false);
366 if (by_addr_it_wt->pruning_seed && ple.
pruning_seed == 0)
368 if (by_addr_it_wt->rpc_port && ple.
rpc_port == 0)
369 new_ple.
rpc_port = by_addr_it_wt->rpc_port;
370 if (!trust_last_seen)
371 new_ple.
last_seen = by_addr_it_wt->last_seen;
381 CATCH_ENTRY_L0(
"peerlist_manager::append_with_peer_white()",
false);
408 if (by_addr_it_gr->pruning_seed && ple.
pruning_seed == 0)
410 if (by_addr_it_gr->rpc_port && ple.
rpc_port == 0)
411 new_ple.
rpc_port = by_addr_it_gr->rpc_port;
412 new_ple.
last_seen = by_addr_it_gr->last_seen;
416 CATCH_ENTRY_L0(
"peerlist_manager::append_with_peer_gray()",
false);
434 CATCH_ENTRY_L0(
"peerlist_manager::append_with_peer_anchor()",
false);
453 CATCH_ENTRY_L0(
"peerlist_manager::get_random_gray_peer()",
false);
471 CATCH_ENTRY_L0(
"peerlist_manager::remove_from_peer_white()",
false);
489 CATCH_ENTRY_L0(
"peerlist_manager::remove_from_peer_gray()",
false);
510 CATCH_ENTRY_L0(
"peerlist_manager::get_and_empty_anchor_peerlist()",
false);
520 anchor_peers_indexed::index_iterator<by_addr>::type iterator =
m_peers_anchor.get<
by_addr>().find(addr);
528 CATCH_ENTRY_L0(
"peerlist_manager::remove_from_peer_anchor()",
false);
537 auto i = sorted_index.begin();
538 while (i != sorted_index.end())
542 i = sorted_index.erase(i);
548 CATCH_ENTRY_L0(
"peerlist_manager::filter()", filtered);
Definition net_utils_base.h:225
#define P2P_LOCAL_GRAY_PEERLIST_LIMIT
Definition cryptonote_config.h:137
#define P2P_LOCAL_WHITE_PEERLIST_LIMIT
Definition cryptonote_config.h:136
#define P2P_DEFAULT_PEERS_IN_HANDSHAKE
Definition cryptonote_config.h:142
#define const
Definition ipfrdr.c:80
static void init()
Definition logging.cpp:42
uint32_t address
Definition getifaddr.c:269
std::enable_if< std::is_unsigned< T >::value, T >::type rand_idx(T sz)
Definition crypto.h:204
TODO: (mj-xmr) This will be reduced in an another PR.
Definition byte_slice.h:40
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
#define F(w, k)
Definition sha512-blocks.c:61
static __thread int depth
Definition threadpool.cpp:34
CXA_THROW_INFO_T void(* dest)(void *))
Definition stack_trace.cpp:91
unsigned short uint16_t
Definition stdint.h:125
unsigned int uint32_t
Definition stdint.h:126
AddressType adr
Definition p2p_protocol_defs.h:104
uint32_t pruning_seed
Definition p2p_protocol_defs.h:77
AddressType adr
Definition p2p_protocol_defs.h:74
uint16_t rpc_port
Definition p2p_protocol_defs.h:78
peerid_type id
Definition p2p_protocol_defs.h:75
int64_t last_seen
Definition p2p_protocol_defs.h:76
uint32_t rpc_credits_per_hash
Definition p2p_protocol_defs.h:79
#define CRITICAL_REGION_LOCAL(x)
Definition syncobj.h:153