Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | class PeerManager { | ||||
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: | ||||
/** | /** | ||||
* Node API. | * Node API. | ||||
*/ | */ | ||||
bool addNode(NodeId nodeid, const Proof &proof, | bool addNode(NodeId nodeid, Proof proof, const Delegation &delegation); | ||||
const Delegation &delegation); | |||||
bool removeNode(NodeId nodeid); | bool removeNode(NodeId nodeid); | ||||
bool forNode(NodeId nodeid, std::function<bool(const Node &n)> func) const; | bool forNode(NodeId nodeid, std::function<bool(const Node &n)> func) const; | ||||
bool updateNextRequestTime(NodeId nodeid, TimePoint timeout); | bool updateNextRequestTime(NodeId nodeid, TimePoint timeout); | ||||
/** | /** | ||||
* Randomly select a node to poll. | * Randomly select a node to poll. | ||||
*/ | */ | ||||
NodeId selectNode(); | NodeId selectNode(); | ||||
/** | /** | ||||
* Update the peer set when a nw block is connected. | * Update the peer set when a nw block is connected. | ||||
*/ | */ | ||||
void updatedBlockTip(); | void updatedBlockTip(); | ||||
/**************************************************** | /**************************************************** | ||||
* Functions which are public for testing purposes. * | * Functions which are public for testing purposes. * | ||||
****************************************************/ | ****************************************************/ | ||||
/** | /** | ||||
* Provide the PeerId associated with the given proof. If the peer does not | * Provide the PeerId associated with the given proof. If the peer does not | ||||
* exists, then it is created. | * exists, then it is created. | ||||
*/ | */ | ||||
PeerId getPeerId(const Proof &proof); | PeerId getPeerId(Proof proof); | ||||
/** | /** | ||||
* Remove an existing peer. | * Remove an existing peer. | ||||
*/ | */ | ||||
bool removePeer(const PeerId peerid); | bool removePeer(const PeerId peerid); | ||||
/** | /** | ||||
* Randomly select a peer to poll. | * Randomly select a peer to poll. | ||||
Show All 14 Lines | public: | ||||
// 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; } | ||||
std::vector<Peer> getPeers() const; | std::vector<Peer> getPeers() const; | ||||
std::vector<NodeId> getNodeIdsForPeer(PeerId peerId) const; | std::vector<NodeId> getNodeIdsForPeer(PeerId peerId) const; | ||||
private: | private: | ||||
PeerSet::iterator fetchOrCreatePeer(const Proof &proof); | PeerSet::iterator fetchOrCreatePeer(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 |