Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | void forEachNode(const Peer &peer, Callable &&func) const { | ||||
for (auto it = range.first; it != range.second; ++it) { | for (auto it = range.first; it != range.second; ++it) { | ||||
func(*it); | func(*it); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Proof and Peer related API. | * Proof and Peer related API. | ||||
*/ | */ | ||||
bool registerProof(const std::shared_ptr<Proof> &proof); | |||||
bool exists(const ProofId &proofid) const { | bool exists(const ProofId &proofid) const { | ||||
return getProof(proofid) != nullptr; | return getProof(proofid) != nullptr; | ||||
} | } | ||||
template <typename Callable> | |||||
bool forPeer(const ProofId &proofid, Callable &&func) const { | |||||
auto &pview = peers.get<proof_index>(); | |||||
auto it = pview.find(proofid); | |||||
return it != pview.end() && func(*it); | |||||
} | |||||
template <typename Callable> void forEachPeer(Callable &&func) const { | template <typename Callable> void forEachPeer(Callable &&func) const { | ||||
for (const auto &p : peers) { | for (const auto &p : peers) { | ||||
func(p); | func(p); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Update the peer set when a new block is connected. | * Update the peer set when a new block is connected. | ||||
Show All 37 Lines | public: | ||||
*/ | */ | ||||
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::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; | |||||
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); | ||||
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); | ||||
Show All 12 Lines |