Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
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 next_request_time {}; | struct next_request_time {}; | ||||
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; | ||||
OrphanProofPool orphanProofs{AVALANCHE_ORPHANPROOFPOOL_SIZE}; | OrphanProofPool orphanProofs{AVALANCHE_ORPHANPROOFPOOL_SIZE}; | ||||
/** | /** | ||||
* Track proof ids to broadcast | * Track proof ids to broadcast | ||||
*/ | */ | ||||
std::unordered_set<ProofId, SaltedProofIdHasher> m_unbroadcast_proofids; | std::unordered_set<ProofId, SaltedProofIdHasher> m_unbroadcast_proofids; | ||||
/** | /** | ||||
* 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, boost::multi_index::indexed_by< | Peer, bmi::indexed_by< | ||||
// index by peerid | // index by peerid | ||||
boost::multi_index::hashed_unique< | bmi::hashed_unique<bmi::member<Peer, PeerId, &Peer::peerid>>, | ||||
boost::multi_index::member<Peer, PeerId, &Peer::peerid>>, | |||||
// index by proof | // index by proof | ||||
boost::multi_index::hashed_unique< | bmi::hashed_unique<bmi::tag<proof_index>, proof_index, | ||||
boost::multi_index::tag<proof_index>, proof_index, | |||||
SaltedProofIdHasher>>>; | SaltedProofIdHasher>>>; | ||||
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, | ||||
boost::multi_index::indexed_by< | bmi::indexed_by< | ||||
// index by nodeid | // index by nodeid | ||||
boost::multi_index::hashed_unique< | bmi::hashed_unique<bmi::member<Node, NodeId, &Node::nodeid>>, | ||||
boost::multi_index::member<Node, NodeId, &Node::nodeid>>, | |||||
// sorted by peerid/nextRequestTime | // sorted by peerid/nextRequestTime | ||||
boost::multi_index::ordered_non_unique< | bmi::ordered_non_unique< | ||||
boost::multi_index::tag<next_request_time>, | bmi::tag<next_request_time>, | ||||
boost::multi_index::composite_key< | bmi::composite_key< | ||||
Node, | Node, bmi::member<Node, PeerId, &Node::peerid>, | ||||
boost::multi_index::member<Node, PeerId, &Node::peerid>, | bmi::member<Node, TimePoint, &Node::nextRequestTime>>>>>; | ||||
boost::multi_index::member<Node, TimePoint, | |||||
&Node::nextRequestTime>>>>>; | |||||
NodeSet nodes; | NodeSet nodes; | ||||
static constexpr int SELECT_PEER_MAX_RETRY = 3; | static constexpr int SELECT_PEER_MAX_RETRY = 3; | ||||
static constexpr int SELECT_NODE_MAX_RETRY = 3; | static constexpr int SELECT_NODE_MAX_RETRY = 3; | ||||
public: | public: | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |