Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 89 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; | |||||
namespace bmi = boost::multi_index; | namespace bmi = boost::multi_index; | ||||
class PeerManager { | class PeerManager { | ||||
std::vector<Slot> slots; | std::vector<Slot> slots; | ||||
uint64_t slotCount = 0; | uint64_t slotCount = 0; | ||||
uint64_t fragmentation = 0; | uint64_t fragmentation = 0; | ||||
/** | /** | ||||
* Several nodes can make an avalanche peer. In this case, all nodes are | * Several nodes can make an avalanche peer. In this case, all nodes are | ||||
* 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<proof_index>, proof_index, | bmi::hashed_unique<bmi::tag<proof_index>, 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; | ||||
std::unordered_map<COutPoint, PeerId, SaltedOutpointHasher> utxos; | std::unordered_map<COutPoint, PeerId, SaltedOutpointHasher> utxos; | ||||
using NodeSet = boost::multi_index_container< | using NodeSet = boost::multi_index_container< | ||||
Node, | Node, | ||||
▲ Show 20 Lines • Show All 157 Lines • Show Last 20 Lines |