Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | struct Peer { | ||||
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>()) {} | ||||
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 ProofPoolEntry { | ||||
COutPoint utxo; | |||||
deadalnix: The outpoint is already in the proof, no need to copy it. | |||||
FabienAuthorUnsubmitted Done Inline ActionsI don't know how to avoid the copy here, if possible at all. Fabien: I don't know how to avoid the copy here, if possible at all.
I want a container that use the… | |||||
ProofRef proof; | |||||
ProofPoolEntry(const COutPoint &_utxo, const ProofRef &_proof) | |||||
: utxo(_utxo), proof(_proof) {} | |||||
}; | |||||
struct by_utxo; | |||||
template <typename StructWithProof> 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 StructWithProof &s) const { | ||||
return s.proof->getId(); | |||||
} | |||||
}; | }; | ||||
struct next_request_time {}; | struct next_request_time {}; | ||||
struct PendingNode { | struct PendingNode { | ||||
ProofId proofid; | ProofId proofid; | ||||
NodeId nodeid; | NodeId nodeid; | ||||
Show All 15 Lines | class PeerManager { | ||||
* 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<by_proofid>, proof_index, | bmi::hashed_unique<bmi::tag<by_proofid>, proof_index<Peer>, | ||||
SaltedProofIdHasher>>>; | SaltedProofIdHasher>>>; | ||||
PeerId nextPeerId = 0; | PeerId nextPeerId = 0; | ||||
PeerSet peers; | PeerSet peers; | ||||
std::unordered_map<COutPoint, ProofRef, SaltedOutpointHasher> utxos; | /** | ||||
* Map a proof to each utxo. A proof can be mapped with several utxos. | |||||
*/ | |||||
using ProofPool = boost::multi_index_container< | |||||
ProofPoolEntry, | |||||
bmi::indexed_by< | |||||
// index by utxo | |||||
bmi::hashed_unique< | |||||
bmi::tag<by_utxo>, | |||||
bmi::member<ProofPoolEntry, COutPoint, &ProofPoolEntry::utxo>, | |||||
SaltedOutpointHasher>, | |||||
// index by proofid | |||||
bmi::hashed_non_unique<bmi::tag<by_proofid>, | |||||
proof_index<ProofPoolEntry>, | |||||
SaltedProofIdHasher>>>; | |||||
ProofPool validProofPool; | |||||
using NodeSet = boost::multi_index_container< | using NodeSet = boost::multi_index_container< | ||||
Node, | Node, | ||||
bmi::indexed_by< | bmi::indexed_by< | ||||
// index by nodeid | // index by nodeid | ||||
bmi::hashed_unique<bmi::member<Node, NodeId, &Node::nodeid>>, | bmi::hashed_unique<bmi::member<Node, NodeId, &Node::nodeid>>, | ||||
// sorted by peerid/nextRequestTime | // sorted by peerid/nextRequestTime | ||||
bmi::ordered_non_unique< | bmi::ordered_non_unique< | ||||
▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines |
The outpoint is already in the proof, no need to copy it.