Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | struct Peer { | ||||
PeerId peerid; | PeerId peerid; | ||||
uint32_t index = -1; | uint32_t index = -1; | ||||
uint32_t node_count = 0; | uint32_t node_count = 0; | ||||
ProofRef proof; | ProofRef proof; | ||||
// The network stack uses timestamp in seconds, so we oblige. | // The network stack uses timestamp in seconds, so we oblige. | ||||
std::chrono::seconds registration_time; | std::chrono::seconds registration_time; | ||||
std::chrono::seconds nextPossibleConflictTime; | |||||
Peer(PeerId peerid_, ProofRef proof_) | Peer(PeerId peerid_, ProofRef proof_) | ||||
: peerid(peerid_), proof(std::move(proof_)), | : peerid(peerid_), proof(std::move(proof_)), | ||||
registration_time(GetTime<std::chrono::seconds>()) {} | registration_time(GetTime<std::chrono::seconds>()), | ||||
nextPossibleConflictTime(registration_time) {} | |||||
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 100 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. | ||||
*/ | */ | ||||
/** | |||||
* Update the time before which a proof is not allowed to have conflicting | |||||
* UTXO with this peer's proof. | |||||
*/ | |||||
bool updateNextPossibleConflictTime(PeerId peerid, | |||||
const std::chrono::seconds &nextTime); | |||||
bool registerProof(const ProofRef &proof); | bool registerProof(const ProofRef &proof); | ||||
bool exists(const ProofId &proofid) const { | bool exists(const ProofId &proofid) const { | ||||
return getProof(proofid) != nullptr; | return getProof(proofid) != nullptr; | ||||
} | } | ||||
template <typename Callable> | template <typename Callable> | ||||
bool forPeer(const ProofId &proofid, Callable &&func) const { | bool forPeer(const ProofId &proofid, Callable &&func) const { | ||||
auto &pview = peers.get<by_proofid>(); | auto &pview = peers.get<by_proofid>(); | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |