Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 142 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); | ||||
// Update when a node is to be polled next. | |||||
bool updateNextRequestTime(NodeId nodeid, TimePoint timeout); | |||||
template <typename Callable> | template <typename Callable> | ||||
bool forNode(NodeId nodeid, Callable &&func) const { | bool forNode(NodeId nodeid, Callable &&func) const { | ||||
auto it = nodes.find(nodeid); | auto it = nodes.find(nodeid); | ||||
return it != nodes.end() && func(*it); | return it != nodes.end() && func(*it); | ||||
} | } | ||||
template <typename Callable> | template <typename Callable> | ||||
void forEachNode(const Peer &peer, Callable &&func) const { | void forEachNode(const Peer &peer, Callable &&func) const { | ||||
auto &nview = nodes.get<next_request_time>(); | auto &nview = nodes.get<next_request_time>(); | ||||
auto range = nview.equal_range(peer.peerid); | auto range = nview.equal_range(peer.peerid); | ||||
for (auto it = range.first; it != range.second; ++it) { | for (auto it = range.first; it != range.second; ++it) { | ||||
func(*it); | func(*it); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Peer API. | |||||
*/ | |||||
bool registerProof(const std::shared_ptr<Proof> &proof); | |||||
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); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Randomly select a node to poll. | * Randomly select a node to poll. | ||||
*/ | */ | ||||
NodeId selectNode(); | NodeId selectNode(); | ||||
/** | /** | ||||
* Update when a node is to be polled next. | |||||
*/ | |||||
bool updateNextRequestTime(NodeId nodeid, TimePoint timeout); | |||||
/** | |||||
* Update the peer set when a new block is connected. | * Update the peer set when a new block is connected. | ||||
*/ | */ | ||||
void updatedBlockTip(); | void updatedBlockTip(); | ||||
/**************************************************** | /**************************************************** | ||||
* Functions which are public for testing purposes. * | * Functions which are public for testing purposes. * | ||||
****************************************************/ | ****************************************************/ | ||||
/** | /** | ||||
Show All 23 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; | ||||
void addUnbroadcastProof(const ProofId &proofid); | void addUnbroadcastProof(const ProofId &proofid); | ||||
void removeUnbroadcastProof(const ProofId &proofid); | void removeUnbroadcastProof(const ProofId &proofid); | ||||
void broadcastProofs(const CConnman &connman); | void broadcastProofs(const CConnman &connman); | ||||
Show All 16 Lines |