Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | |||||
public: | public: | ||||
/** | /** | ||||
* 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); | ||||
bool forNode(NodeId nodeid, std::function<bool(const Node &n)> func) const; | // Update when a node is to be polled next. | ||||
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(); | ||||
template <typename Callable> | |||||
bool forNode(NodeId nodeid, Callable &&func) const { | |||||
auto it = nodes.find(nodeid); | |||||
return it != nodes.end() && func(*it); | |||||
} | |||||
template <typename Callable> | |||||
void forEachNode(const Peer &peer, Callable &&func) const { | |||||
auto &nview = nodes.get<next_request_time>(); | |||||
auto range = nview.equal_range(peer.peerid); | |||||
for (auto it = range.first; it != range.second; ++it) { | |||||
func(*it); | |||||
} | |||||
} | |||||
/** | |||||
* Proof and Peer related API. | |||||
*/ | |||||
template <typename Callable> void forEachPeer(Callable &&func) const { | |||||
for (const auto &p : peers) { | |||||
func(p); | |||||
} | |||||
} | |||||
/** | /** | ||||
* Update the peer set when a new block is connected. | * Update the peer set when a new block is connected. | ||||
*/ | */ | ||||
void updatedBlockTip(); | void updatedBlockTip(); | ||||
/** | /** | ||||
* Proof broadcast API. | * Proof broadcast API. | ||||
*/ | */ | ||||
Show All 30 Lines | public: | ||||
* Perform consistency check on internal data structures. | * Perform consistency check on internal data structures. | ||||
*/ | */ | ||||
bool verify() const; | bool verify() const; | ||||
// 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<NodeId> getNodeIdsForPeer(PeerId peerId) const; | |||||
std::shared_ptr<Proof> getProof(const ProofId &proofid) const; | std::shared_ptr<Proof> getProof(const ProofId &proofid) const; | ||||
std::chrono::seconds getProofRegistrationTime(const ProofId &proofid) const; | std::chrono::seconds getProofRegistrationTime(const ProofId &proofid) const; | ||||
bool isOrphan(const ProofId &id) const; | bool isOrphan(const ProofId &id) const; | ||||
std::shared_ptr<Proof> getOrphan(const ProofId &id) const; | std::shared_ptr<Proof> getOrphan(const ProofId &id) const; | ||||
private: | private: | ||||
PeerSet::iterator fetchOrCreatePeer(const std::shared_ptr<Proof> &proof); | PeerSet::iterator fetchOrCreatePeer(const std::shared_ptr<Proof> &proof); | ||||
Show All 14 Lines |