5 #ifndef BITCOIN_AVALANCHE_PEERMANAGER_H 6 #define BITCOIN_AVALANCHE_PEERMANAGER_H 15 #include <boost/multi_index/composite_key.hpp> 16 #include <boost/multi_index/hashed_index.hpp> 17 #include <boost/multi_index/member.hpp> 18 #include <boost/multi_index/ordered_index.hpp> 19 #include <boost/multi_index_container.hpp> 36 Slot(uint64_t startIn, uint32_t scoreIn,
PeerId peeridIn)
37 : start(startIn), score(scoreIn), peerid(peeridIn) {}
40 return Slot(startIn, score, peerid);
43 return Slot(start, scoreIn, peerid);
46 return Slot(start, score, peeridIn);
64 uint32_t node_count = 0;
69 : peerid(peerid_), proof(
std::move(proof_)) {}
91 uint64_t slotCount = 0;
92 uint64_t fragmentation = 0;
98 using PeerSet = boost::multi_index_container<
99 Peer, boost::multi_index::indexed_by<
101 boost::multi_index::hashed_unique<
102 boost::multi_index::member<Peer, PeerId, &Peer::peerid>>,
104 boost::multi_index::hashed_unique<
111 std::unordered_map<COutPoint, PeerId, SaltedOutpointHasher>
utxos;
113 using NodeSet = boost::multi_index_container<
115 boost::multi_index::indexed_by<
117 boost::multi_index::hashed_unique<
118 boost::multi_index::member<Node, NodeId, &Node::nodeid>>,
120 boost::multi_index::ordered_non_unique<
121 boost::multi_index::tag<next_request_time>,
122 boost::multi_index::composite_key<
124 boost::multi_index::member<Node, PeerId, &Node::peerid>,
125 boost::multi_index::member<Node,
TimePoint,
130 static constexpr
int SELECT_PEER_MAX_RETRY = 3;
131 static constexpr
int SELECT_NODE_MAX_RETRY = 3;
139 bool removeNode(
NodeId nodeid);
141 bool forNode(
NodeId nodeid, std::function<
bool(
const Node &n)> func)
const;
142 bool updateNextRequestTime(
NodeId nodeid, TimePoint timeout);
152 void updatedBlockTip();
171 PeerId selectPeer()
const;
189 PeerSet::iterator fetchOrCreatePeer(
const Proof &proof);
190 bool addNodeToPeer(
const PeerSet::iterator &it);
191 bool removeNodeFromPeer(
const PeerSet::iterator &it, uint32_t
count = 1);
202 #endif // BITCOIN_AVALANCHE_PEERMANAGER_H
uint32_t getScore() const
uint64_t getFragmentation() const
boost::multi_index_container< Peer, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::member< Peer, PeerId, &Peer::peerid > >, boost::multi_index::hashed_unique< boost::multi_index::tag< proof_index >, proof_index, SaltedProofIdHasher > >> PeerSet
Several nodes can make an avalanche peer.
uint32_t getScore() const
result_type operator()(const Peer &p) const
Slot withScore(uint64_t scoreIn) const
PeerId selectPeerImpl(const std::vector< Slot > &slots, const uint64_t slot, const uint64_t max)
This is an internal method that is exposed for testing purposes.
Peer(PeerId peerid_, Proof proof_)
uint64_t getStart() const
bool precedes(uint64_t slot) const
bool follows(uint64_t slot) const
boost::multi_index_container< Node, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::member< Node, NodeId, &Node::nodeid > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< next_request_time >, boost::multi_index::composite_key< Node, boost::multi_index::member< Node, PeerId, &Node::peerid >, boost::multi_index::member< Node, TimePoint, &Node::nextRequestTime > >> >> NodeSet
uint32_t getScore() const
Slot withStart(uint64_t startIn) const
Slot(uint64_t startIn, uint32_t scoreIn, PeerId peeridIn)
Slot withPeerId(PeerId peeridIn) const
bool contains(uint64_t slot) const
const ProofId & getId() const
TimePoint nextRequestTime
std::vector< Slot > slots
std::chrono::time_point< std::chrono::steady_clock > TimePoint
std::unordered_map< COutPoint, PeerId, SaltedOutpointHasher > utxos
uint64_t getSlotCount() const
size_t operator()(const ProofId &proofid) const
const ProofId & getProofId() const