Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | class PeerManager { | ||||
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: | ||||
/** | /** | ||||
* Provide the peer associated with the given proof. If the peer does not | * Node API. | ||||
* exists, then it is created. | |||||
*/ | */ | ||||
PeerId getPeer(const Proof &proof); | bool addNode(NodeId nodeid, const Proof &proof, const CPubKey &pubkey); | ||||
bool removeNode(NodeId nodeid); | |||||
bool forNode(NodeId nodeid, std::function<bool(const Node &n)> func) const; | |||||
bool updateNextRequestTime(NodeId nodeid, TimePoint timeout); | |||||
/** | /** | ||||
* Remove an existing peer. | * Randomly select a node to poll/ | ||||
* This is not meant for public consumption. | |||||
*/ | */ | ||||
bool removePeer(const PeerId peerid); | NodeId selectNode(); | ||||
/** | /** | ||||
* Node API. | * Update the peer set when a nw block is connected. | ||||
*/ | */ | ||||
bool addNode(NodeId nodeid, const Proof &proof, const CPubKey &pubkey); | void updatedBlockTip(); | ||||
bool removeNode(NodeId nodeid); | |||||
NodeId selectNode(); | /**************************************************** | ||||
* Functions which are public for testing purposes. * | |||||
****************************************************/ | |||||
/** | |||||
* Provide the PeerId associated with the given proof. If the peer does not | |||||
* exists, then it is created. | |||||
*/ | |||||
PeerId getPeerId(const Proof &proof); | |||||
bool forNode(NodeId nodeid, std::function<bool(const Node &n)> func) const; | /** | ||||
bool updateNextRequestTime(NodeId nodeid, TimePoint timeout); | * Remove an existing peer. | ||||
* This is not meant for public consumption. | |||||
*/ | |||||
bool removePeer(const PeerId peerid); | |||||
/** | /** | ||||
* Exposed for tests. | * Exposed for tests. | ||||
*/ | */ | ||||
PeerId selectPeer() const; | PeerId selectPeer() const; | ||||
/** | /** | ||||
* Trigger maintenance of internal datastructures. | * Trigger maintenance of internal datastructures. | ||||
* Returns how much slot space was saved after compaction. | * Returns how much slot space was saved after compaction. | ||||
*/ | */ | ||||
uint64_t compact(); | uint64_t compact(); | ||||
/** | /** | ||||
* Perform consistency check on internal data structures. | * Perform consistency check on internal data structures. | ||||
* Mostly useful for tests. | * Mostly useful for tests. | ||||
*/ | */ | ||||
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; } | ||||
/** | private: | ||||
* Update the peer set when a nw block is connected. | PeerSet::iterator fetchOrCreatePeer(const Proof &proof); | ||||
*/ | |||||
void updatedBlockTip(); | |||||
}; | }; | ||||
/** | /** | ||||
* 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 |