Bitcoin ABC  0.24.7
P2P Digital Currency
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
avalanche::PeerManager Class Reference

#include <peermanager.h>

Collaboration diagram for avalanche::PeerManager:
[legend]

Public Member Functions

bool addNode (NodeId nodeid, const ProofId &proofid)
 Node API. More...
 
bool removeNode (NodeId nodeid)
 
bool updateNextRequestTime (NodeId nodeid, TimePoint timeout)
 
NodeId selectNode ()
 
template<typename Callable >
bool forNode (NodeId nodeid, Callable &&func) const
 
template<typename Callable >
void forEachNode (const Peer &peer, Callable &&func) const
 
bool registerProof (const ProofRef &proof)
 Proof and Peer related API. More...
 
bool exists (const ProofId &proofid) const
 
template<typename Callable >
bool forPeer (const ProofId &proofid, Callable &&func) const
 
template<typename Callable >
void forEachPeer (Callable &&func) const
 
void updatedBlockTip ()
 Update the peer set when a new block is connected. More...
 
void addUnbroadcastProof (const ProofId &proofid)
 Proof broadcast API. More...
 
void removeUnbroadcastProof (const ProofId &proofid)
 
auto getUnbroadcastProofs () const
 
bool removePeer (const PeerId peerid)
 Remove an existing peer. More...
 
PeerId selectPeer () const
 Randomly select a peer to poll. More...
 
uint64_t compact ()
 Trigger maintenance of internal data structures. More...
 
bool verify () const
 Perform consistency check on internal data structures. More...
 
uint64_t getSlotCount () const
 
uint64_t getFragmentation () const
 
ProofRef getProof (const ProofId &proofid) const
 
bool isBoundToPeer (const ProofId &proofid) const
 
bool isOrphan (const ProofId &proofid) const
 

Private Types

using PeerSet = boost::multi_index_container< Peer, bmi::indexed_by< bmi::hashed_unique< bmi::member< Peer, PeerId, &Peer::peerid > >, bmi::hashed_unique< bmi::tag< by_proofid >, proof_index< Peer >, SaltedProofIdHasher > >>
 Several nodes can make an avalanche peer. More...
 
using ProofPool = boost::multi_index_container< ProofPoolEntry, bmi::indexed_by< bmi::hashed_unique< bmi::tag< by_utxo >, bmi::const_mem_fun< ProofPoolEntry, const COutPoint &, &ProofPoolEntry::getUTXO >, SaltedOutpointHasher >, bmi::hashed_non_unique< bmi::tag< by_proofid >, proof_index< ProofPoolEntry >, SaltedProofIdHasher > >>
 Map a proof to each utxo. More...
 
using NodeSet = boost::multi_index_container< Node, bmi::indexed_by< bmi::hashed_unique< bmi::member< Node, NodeId, &Node::nodeid > >, bmi::ordered_non_unique< bmi::tag< next_request_time >, bmi::composite_key< Node, bmi::member< Node, PeerId, &Node::peerid >, bmi::member< Node, TimePoint, &Node::nextRequestTime > >> >>
 
using PendingNodeSet = boost::multi_index_container< PendingNode, bmi::indexed_by< bmi::hashed_non_unique< bmi::tag< by_proofid >, bmi::member< PendingNode, ProofId, &PendingNode::proofid >, SaltedProofIdHasher >, bmi::hashed_unique< bmi::tag< by_nodeid >, bmi::member< PendingNode, NodeId, &PendingNode::nodeid > >> >
 

Private Member Functions

bool createPeer (const ProofRef &proof)
 
bool addOrUpdateNode (const PeerSet::iterator &it, NodeId nodeid)
 
bool addNodeToPeer (const PeerSet::iterator &it)
 
bool removeNodeFromPeer (const PeerSet::iterator &it, uint32_t count=1)
 

Private Attributes

std::vector< Slotslots
 
uint64_t slotCount = 0
 
uint64_t fragmentation = 0
 
PeerId nextPeerId = 0
 
PeerSet peers
 
ProofPool validProofPool
 
NodeSet nodes
 
PendingNodeSet pendingNodes
 
OrphanProofPool orphanProofs {AVALANCHE_ORPHANPROOFPOOL_SIZE}
 Tracks proof which for which the UTXO are unavailable. More...
 
std::unordered_set< ProofId, SaltedProofIdHasherm_unbroadcast_proofids
 Track proof ids to broadcast. More...
 

Static Private Attributes

static constexpr int SELECT_PEER_MAX_RETRY = 3
 
static constexpr int SELECT_NODE_MAX_RETRY = 3
 

Friends

struct ::avalanche::TestPeerManager
 

Detailed Description

Definition at line 130 of file peermanager.h.

Member Typedef Documentation

◆ NodeSet

using avalanche::PeerManager::NodeSet = boost::multi_index_container< Node, bmi::indexed_by< bmi::hashed_unique<bmi::member<Node, NodeId, &Node::nodeid> >, bmi::ordered_non_unique< bmi::tag<next_request_time>, bmi::composite_key< Node, bmi::member<Node, PeerId, &Node::peerid>, bmi::member<Node, TimePoint, &Node::nextRequestTime> >> >>
private

Definition at line 179 of file peermanager.h.

◆ PeerSet

using avalanche::PeerManager::PeerSet = boost::multi_index_container< Peer, bmi::indexed_by< bmi::hashed_unique<bmi::member<Peer, PeerId, &Peer::peerid> >, bmi::hashed_unique<bmi::tag<by_proofid>, proof_index<Peer>, SaltedProofIdHasher> >>
private

Several nodes can make an avalanche peer.

In this case, all nodes are considered interchangeable parts of the same peer.

Definition at line 145 of file peermanager.h.

◆ PendingNodeSet

using avalanche::PeerManager::PendingNodeSet = boost::multi_index_container< PendingNode, bmi::indexed_by< bmi::hashed_non_unique< bmi::tag<by_proofid>, bmi::member<PendingNode, ProofId, &PendingNode::proofid>, SaltedProofIdHasher>, bmi::hashed_unique< bmi::tag<by_nodeid>, bmi::member<PendingNode, NodeId, &PendingNode::nodeid> >> >
private

Definition at line 194 of file peermanager.h.

◆ ProofPool

using avalanche::PeerManager::ProofPool = boost::multi_index_container< ProofPoolEntry, bmi::indexed_by< bmi::hashed_unique< bmi::tag<by_utxo>, bmi::const_mem_fun<ProofPoolEntry, const COutPoint &, &ProofPoolEntry::getUTXO>, SaltedOutpointHasher>, bmi::hashed_non_unique<bmi::tag<by_proofid>, proof_index<ProofPoolEntry>, SaltedProofIdHasher> >>
private

Map a proof to each utxo.

A proof can be mapped with several utxos.

Definition at line 165 of file peermanager.h.

Member Function Documentation

◆ addNode()

bool PeerManager::addNode ( NodeId  nodeid,
const ProofId proofid 
)

Node API.

Definition at line 17 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNodeToPeer()

bool PeerManager::addNodeToPeer ( const PeerSet::iterator &  it)
private

Definition at line 62 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOrUpdateNode()

bool PeerManager::addOrUpdateNode ( const PeerSet::iterator &  it,
NodeId  nodeid 
)
private

Definition at line 32 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addUnbroadcastProof()

void PeerManager::addUnbroadcastProof ( const ProofId proofid)

Proof broadcast API.

Definition at line 552 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compact()

uint64_t PeerManager::compact ( )

Trigger maintenance of internal data structures.

Returns how much slot space was saved after compaction.

Definition at line 370 of file peermanager.cpp.

Here is the caller graph for this function:

◆ createPeer()

bool PeerManager::createPeer ( const ProofRef proof)
private

Definition at line 254 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exists()

bool avalanche::PeerManager::exists ( const ProofId proofid) const
inline

Definition at line 242 of file peermanager.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ forEachNode()

template<typename Callable >
void avalanche::PeerManager::forEachNode ( const Peer peer,
Callable &&  func 
) const
inline

Definition at line 230 of file peermanager.h.

Here is the caller graph for this function:

◆ forEachPeer()

template<typename Callable >
void avalanche::PeerManager::forEachPeer ( Callable &&  func) const
inline

Definition at line 253 of file peermanager.h.

Here is the caller graph for this function:

◆ forNode()

template<typename Callable >
bool avalanche::PeerManager::forNode ( NodeId  nodeid,
Callable &&  func 
) const
inline

Definition at line 224 of file peermanager.h.

Here is the caller graph for this function:

◆ forPeer()

template<typename Callable >
bool avalanche::PeerManager::forPeer ( const ProofId proofid,
Callable &&  func 
) const
inline

Definition at line 247 of file peermanager.h.

Here is the caller graph for this function:

◆ getFragmentation()

uint64_t avalanche::PeerManager::getFragmentation ( ) const
inline

Definition at line 298 of file peermanager.h.

Here is the caller graph for this function:

◆ getProof()

ProofRef PeerManager::getProof ( const ProofId proofid) const

Definition at line 230 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSlotCount()

uint64_t avalanche::PeerManager::getSlotCount ( ) const
inline

Definition at line 297 of file peermanager.h.

Here is the caller graph for this function:

◆ getUnbroadcastProofs()

auto avalanche::PeerManager::getUnbroadcastProofs ( ) const
inline

Definition at line 269 of file peermanager.h.

Here is the caller graph for this function:

◆ isBoundToPeer()

bool PeerManager::isBoundToPeer ( const ProofId proofid) const

Definition at line 245 of file peermanager.cpp.

Here is the caller graph for this function:

◆ isOrphan()

bool PeerManager::isOrphan ( const ProofId proofid) const

Definition at line 250 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerProof()

bool PeerManager::registerProof ( const ProofRef proof)

Proof and Peer related API.

Definition at line 150 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeNode()

bool PeerManager::removeNode ( NodeId  nodeid)

Definition at line 79 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeNodeFromPeer()

bool PeerManager::removeNodeFromPeer ( const PeerSet::iterator &  it,
uint32_t  count = 1 
)
private

Definition at line 97 of file peermanager.cpp.

Here is the caller graph for this function:

◆ removePeer()

bool PeerManager::removePeer ( const PeerId  peerid)

Remove an existing peer.

Definition at line 318 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeUnbroadcastProof()

void PeerManager::removeUnbroadcastProof ( const ProofId proofid)

Definition at line 559 of file peermanager.cpp.

Here is the caller graph for this function:

◆ selectNode()

NodeId PeerManager::selectNode ( )

Definition at line 174 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectPeer()

PeerId PeerManager::selectPeer ( ) const

Randomly select a peer to poll.

Definition at line 354 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updatedBlockTip()

void PeerManager::updatedBlockTip ( )

Update the peer set when a new block is connected.

Definition at line 197 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateNextRequestTime()

bool PeerManager::updateNextRequestTime ( NodeId  nodeid,
TimePoint  timeout 
)

Definition at line 136 of file peermanager.cpp.

Here is the caller graph for this function:

◆ verify()

bool PeerManager::verify ( ) const

Perform consistency check on internal data structures.

Definition at line 402 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ ::avalanche::TestPeerManager

friend struct ::avalanche::TestPeerManager
friend

Definition at line 310 of file peermanager.h.

Member Data Documentation

◆ fragmentation

uint64_t avalanche::PeerManager::fragmentation = 0
private

Definition at line 133 of file peermanager.h.

◆ m_unbroadcast_proofids

std::unordered_set<ProofId, SaltedProofIdHasher> avalanche::PeerManager::m_unbroadcast_proofids
private

Track proof ids to broadcast.

Definition at line 208 of file peermanager.h.

◆ nextPeerId

PeerId avalanche::PeerManager::nextPeerId = 0
private

Definition at line 147 of file peermanager.h.

◆ nodes

NodeSet avalanche::PeerManager::nodes
private

Definition at line 181 of file peermanager.h.

◆ orphanProofs

OrphanProofPool avalanche::PeerManager::orphanProofs {AVALANCHE_ORPHANPROOFPOOL_SIZE}
private

Tracks proof which for which the UTXO are unavailable.

Definition at line 203 of file peermanager.h.

◆ peers

PeerSet avalanche::PeerManager::peers
private

Definition at line 148 of file peermanager.h.

◆ pendingNodes

PendingNodeSet avalanche::PeerManager::pendingNodes
private

Definition at line 195 of file peermanager.h.

◆ SELECT_NODE_MAX_RETRY

constexpr int avalanche::PeerManager::SELECT_NODE_MAX_RETRY = 3
staticconstexprprivate

Definition at line 198 of file peermanager.h.

◆ SELECT_PEER_MAX_RETRY

constexpr int avalanche::PeerManager::SELECT_PEER_MAX_RETRY = 3
staticconstexprprivate

Definition at line 197 of file peermanager.h.

◆ slotCount

uint64_t avalanche::PeerManager::slotCount = 0
private

Definition at line 132 of file peermanager.h.

◆ slots

std::vector<Slot> avalanche::PeerManager::slots
private

Definition at line 131 of file peermanager.h.

◆ validProofPool

ProofPool avalanche::PeerManager::validProofPool
private

Definition at line 167 of file peermanager.h.


The documentation for this class was generated from the following files: