Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_AVALANCHE_PEERMANAGER_H | #ifndef BITCOIN_AVALANCHE_PEERMANAGER_H | ||||
#define BITCOIN_AVALANCHE_PEERMANAGER_H | #define BITCOIN_AVALANCHE_PEERMANAGER_H | ||||
#include <avalanche/node.h> | #include <avalanche/node.h> | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <avalanche/proofpool.h> | #include <avalanche/proofpool.h> | ||||
#include <avalanche/prooftreeelement.h> | |||||
#include <coins.h> | #include <coins.h> | ||||
#include <consensus/validation.h> | #include <consensus/validation.h> | ||||
#include <pubkey.h> | #include <pubkey.h> | ||||
#include <radix.h> | #include <radix.h> | ||||
#include <rcu.h> | #include <rcu.h> | ||||
#include <salteduint256hasher.h> | #include <salteduint256hasher.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | class PeerManager { | ||||
PeerId nextPeerId = 0; | PeerId nextPeerId = 0; | ||||
PeerSet peers; | PeerSet peers; | ||||
ProofPool validProofPool; | ProofPool validProofPool; | ||||
ProofPool conflictingProofPool; | ProofPool conflictingProofPool; | ||||
ProofPool orphanProofPool; | ProofPool orphanProofPool; | ||||
public: | |||||
struct ProofElement { | |||||
ProofRef proof; | |||||
ProofElement(const ProofRef &proofIn) : proof(proofIn) {} | |||||
Uint256KeyWrapper getId() const { return proof->getId(); } | |||||
IMPLEMENT_RCU_REFCOUNT(uint64_t); | |||||
}; | |||||
private: | private: | ||||
RadixTree<ProofElement> shareableProofs; | RadixTree<ProofTreeElement> shareableProofs; | ||||
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 186 Lines • ▼ Show 20 Lines | public: | ||||
uint64_t getSlotCount() const { return slotCount; } | uint64_t getSlotCount() const { return slotCount; } | ||||
uint64_t getFragmentation() const { return fragmentation; } | uint64_t getFragmentation() const { return fragmentation; } | ||||
ProofRef getProof(const ProofId &proofid) const; | ProofRef getProof(const ProofId &proofid) const; | ||||
bool isBoundToPeer(const ProofId &proofid) const; | bool isBoundToPeer(const ProofId &proofid) const; | ||||
bool isOrphan(const ProofId &proofid) const; | bool isOrphan(const ProofId &proofid) const; | ||||
bool isInConflictingPool(const ProofId &proofid) const; | bool isInConflictingPool(const ProofId &proofid) const; | ||||
RadixTree<ProofElement> getShareableProofsSnapshot() const { | RadixTree<ProofTreeElement> getShareableProofsSnapshot() const { | ||||
return shareableProofs; | return shareableProofs; | ||||
} | } | ||||
private: | private: | ||||
template <typename ProofContainer> | template <typename ProofContainer> | ||||
void moveToConflictingPool(const ProofContainer &proofs); | void moveToConflictingPool(const ProofContainer &proofs); | ||||
bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid); | bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid); | ||||
Show All 15 Lines |