Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | using NodeSet = boost::multi_index_container< | ||||
boost::multi_index::member<Node, NodeId, &Node::nodeid>>, | boost::multi_index::member<Node, NodeId, &Node::nodeid>>, | ||||
// sorted by peerid/nextRequestTime | // sorted by peerid/nextRequestTime | ||||
boost::multi_index::ordered_non_unique< | boost::multi_index::ordered_non_unique< | ||||
boost::multi_index::tag<next_request_time>, | boost::multi_index::tag<next_request_time>, | ||||
boost::multi_index::composite_key< | boost::multi_index::composite_key< | ||||
Node, | Node, | ||||
boost::multi_index::member<Node, PeerId, &Node::peerid>, | boost::multi_index::member<Node, PeerId, &Node::peerid>, | ||||
boost::multi_index::member<Node, TimePoint, | boost::multi_index::member<Node, TimePoint, | ||||
&Node::nextRequestTime>>>>>; | &Node::nextRequestTime>>>, | ||||
// sorted by peerid | |||||
boost::multi_index::ordered_non_unique< | |||||
boost::multi_index::member<Node, PeerId, &Node::peerid>>>>; | |||||
NodeSet nodes; | NodeSet nodes; | ||||
static constexpr int SELECT_PEER_MAX_RETRY = 3; | static constexpr int SELECT_PEER_MAX_RETRY = 3; | ||||
static constexpr int SELECT_NODE_MAX_RETRY = 3; | static constexpr int SELECT_NODE_MAX_RETRY = 3; | ||||
public: | public: | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | public: | ||||
* Perform consistency check on internal data structures. | * Perform consistency check on internal data structures. | ||||
*/ | */ | ||||
bool verify() const; | bool verify() const; | ||||
// Accssors. | // Accssors. | ||||
uint64_t getSlotCount() const { return slotCount; } | uint64_t getSlotCount() const { return slotCount; } | ||||
uint64_t getFragmentation() const { return fragmentation; } | uint64_t getFragmentation() const { return fragmentation; } | ||||
void getPeers(std::vector<Peer> &vpeers) const; | |||||
void getNodeIdsForPeer(PeerId peerId, std::vector<NodeId> &nodeids) const; | |||||
private: | private: | ||||
PeerSet::iterator fetchOrCreatePeer(const Proof &proof); | PeerSet::iterator fetchOrCreatePeer(const Proof &proof); | ||||
bool addNodeToPeer(const PeerSet::iterator &it); | bool addNodeToPeer(const PeerSet::iterator &it); | ||||
bool removeNodeFromPeer(const PeerSet::iterator &it, uint32_t count = 1); | bool removeNodeFromPeer(const PeerSet::iterator &it, uint32_t count = 1); | ||||
}; | }; | ||||
/** | /** | ||||
* This is an internal method that is exposed for testing purposes. | * This is an internal method that is exposed for testing purposes. | ||||
*/ | */ | ||||
PeerId selectPeerImpl(const std::vector<Slot> &slots, const uint64_t slot, | PeerId selectPeerImpl(const std::vector<Slot> &slots, const uint64_t slot, | ||||
const uint64_t max); | const uint64_t max); | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_PEERMANAGER_H | #endif // BITCOIN_AVALANCHE_PEERMANAGER_H |