Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | struct Peer { | ||||
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(); } | ||||
}; | }; | ||||
struct score_index { | |||||
using result_type = uint32_t; | |||||
result_type operator()(const Peer &p) const { return p.getScore(); } | |||||
}; | |||||
struct next_request_time {}; | struct next_request_time {}; | ||||
struct PendingNode { | struct PendingNode { | ||||
ProofId proofid; | ProofId proofid; | ||||
NodeId nodeid; | NodeId nodeid; | ||||
PendingNode(ProofId proofid_, NodeId nodeid_) | PendingNode(ProofId proofid_, NodeId nodeid_) | ||||
: proofid(proofid_), nodeid(nodeid_){}; | : proofid(proofid_), nodeid(nodeid_){}; | ||||
}; | }; | ||||
struct by_proofid; | struct by_proofid; | ||||
struct by_nodeid; | struct by_nodeid; | ||||
struct by_score; | |||||
enum class ProofRegistrationResult { | enum class ProofRegistrationResult { | ||||
NONE = 0, | NONE = 0, | ||||
ALREADY_REGISTERED, | ALREADY_REGISTERED, | ||||
ORPHAN, | ORPHAN, | ||||
INVALID, | INVALID, | ||||
CONFLICTING, | CONFLICTING, | ||||
REJECTED, | REJECTED, | ||||
Show All 15 Lines | class PeerManager { | ||||
* considered interchangeable parts of the same peer. | * considered interchangeable parts of the same peer. | ||||
*/ | */ | ||||
using PeerSet = boost::multi_index_container< | using PeerSet = boost::multi_index_container< | ||||
Peer, bmi::indexed_by< | Peer, bmi::indexed_by< | ||||
// index by peerid | // index by peerid | ||||
bmi::hashed_unique<bmi::member<Peer, PeerId, &Peer::peerid>>, | bmi::hashed_unique<bmi::member<Peer, PeerId, &Peer::peerid>>, | ||||
// index by proof | // index by proof | ||||
bmi::hashed_unique<bmi::tag<by_proofid>, proof_index, | bmi::hashed_unique<bmi::tag<by_proofid>, proof_index, | ||||
SaltedProofIdHasher>>>; | SaltedProofIdHasher>, | ||||
// ordered by score, decreasing order | |||||
bmi::ordered_non_unique<bmi::tag<by_score>, score_index, | |||||
std::greater<uint32_t>>>>; | |||||
PeerId nextPeerId = 0; | PeerId nextPeerId = 0; | ||||
PeerSet peers; | PeerSet peers; | ||||
ProofPool validProofPool; | ProofPool validProofPool; | ||||
ProofPool conflictingProofPool; | ProofPool conflictingProofPool; | ||||
ProofPool orphanProofPool; | ProofPool orphanProofPool; | ||||
▲ Show 20 Lines • Show All 205 Lines • Show Last 20 Lines |