Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | struct Peer { | ||||
uint32_t index = -1; | uint32_t index = -1; | ||||
uint32_t node_count = 0; | uint32_t node_count = 0; | ||||
Proof proof; | Proof proof; | ||||
Peer(PeerId peerid_, Proof proof_) | Peer(PeerId peerid_, Proof proof_) | ||||
: peerid(peerid_), proof(std::move(proof_)) {} | : peerid(peerid_), proof(std::move(proof_)) {} | ||||
const Proof &getProof() const { return proof; } | |||||
const ProofId &getProofId() const { return proof.getId(); } | const ProofId &getProofId() const { return proof.getId(); } | ||||
uint32_t getScore() const { return proof.getScore(); } | uint32_t getScore() const { return proof.getScore(); } | ||||
}; | }; | ||||
struct proof_index { | struct proof_index { | ||||
using result_type = ProofId; | using result_type = ProofId; | ||||
result_type operator()(const Peer &p) const { return p.proof.getId(); } | result_type operator()(const Peer &p) const { return p.proof.getId(); } | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | public: | ||||
bool removePeer(const PeerId peerid); | bool removePeer(const PeerId peerid); | ||||
/** | /** | ||||
* Randomly select a peer to poll. | * Randomly select a peer to poll. | ||||
*/ | */ | ||||
PeerId selectPeer() const; | PeerId selectPeer() const; | ||||
/** | /** | ||||
* Trigger maintenance of internal datastructures. | * Trigger maintenance of internal data structures. | ||||
* 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. | ||||
*/ | */ | ||||
bool verify() const; | bool verify() const; | ||||
// Accssors. | // Accessors. | ||||
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; | ||||
const Proof *getProof(const ProofId &proofid) 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 |