Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | class PeerManager { | ||||
/** | /** | ||||
* Quorum management. | * Quorum management. | ||||
*/ | */ | ||||
uint32_t totalPeersScore = 0; | uint32_t totalPeersScore = 0; | ||||
uint32_t connectedPeersScore = 0; | uint32_t connectedPeersScore = 0; | ||||
public: | public: | ||||
PeerManager(CScheduler &scheduler); | |||||
/** | /** | ||||
* Node API. | * Node API. | ||||
*/ | */ | ||||
bool addNode(NodeId nodeid, const ProofId &proofid); | bool addNode(NodeId nodeid, const ProofId &proofid); | ||||
bool removeNode(NodeId nodeid); | bool removeNode(NodeId nodeid); | ||||
size_t getNodeCount() const { return nodes.size(); } | size_t getNodeCount() const { return nodes.size(); } | ||||
size_t getPendingNodeCount() const { return pendingNodes.size(); } | size_t getPendingNodeCount() const { return pendingNodes.size(); } | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | public: | ||||
bool rejectProof(const ProofId &proofid, | bool rejectProof(const ProofId &proofid, | ||||
RejectionMode mode = RejectionMode::DEFAULT); | RejectionMode mode = RejectionMode::DEFAULT); | ||||
bool exists(const ProofId &proofid) const { | bool exists(const ProofId &proofid) const { | ||||
return getProof(proofid) != nullptr; | return getProof(proofid) != nullptr; | ||||
} | } | ||||
void cleanupDanglingProofs(); | |||||
template <typename Callable> | template <typename Callable> | ||||
bool forPeer(const ProofId &proofid, Callable &&func) const { | bool forPeer(const ProofId &proofid, Callable &&func) const { | ||||
auto &pview = peers.get<by_proofid>(); | auto &pview = peers.get<by_proofid>(); | ||||
auto it = pview.find(proofid); | auto it = pview.find(proofid); | ||||
return it != pview.end() && func(*it); | return it != pview.end() && func(*it); | ||||
} | } | ||||
template <typename Callable> void forEachPeer(Callable &&func) const { | template <typename Callable> void forEachPeer(Callable &&func) const { | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
private: | private: | ||||
template <typename ProofContainer> | template <typename ProofContainer> | ||||
void moveToConflictingPool(const ProofContainer &proofs); | void moveToConflictingPool(const ProofContainer &proofs); | ||||
bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid); | bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid); | ||||
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); | ||||
void cleanupDanglingProofs(); | |||||
friend struct ::avalanche::TestPeerManager; | friend struct ::avalanche::TestPeerManager; | ||||
}; | }; | ||||
/** | /** | ||||
* Internal methods that are exposed for testing purposes. | * Internal methods that are 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 |