Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show All 14 Lines | |||||
#include <boost/multi_index/composite_key.hpp> | #include <boost/multi_index/composite_key.hpp> | ||||
#include <boost/multi_index/hashed_index.hpp> | #include <boost/multi_index/hashed_index.hpp> | ||||
#include <boost/multi_index/member.hpp> | #include <boost/multi_index/member.hpp> | ||||
#include <boost/multi_index/ordered_index.hpp> | #include <boost/multi_index/ordered_index.hpp> | ||||
#include <boost/multi_index_container.hpp> | #include <boost/multi_index_container.hpp> | ||||
#include <chrono> | #include <chrono> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <optional> | |||||
#include <vector> | #include <vector> | ||||
namespace avalanche { | namespace avalanche { | ||||
class Delegation; | class Delegation; | ||||
struct Slot { | struct Slot { | ||||
private: | private: | ||||
Show All 32 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 97 Lines • ▼ Show 20 Lines | public: | ||||
// Accessors. | // 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; | ||||
std::optional<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 |