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

#include <peermanager.h>

Public Member Functions

bool addNode (NodeId nodeid, const Proof &proof, const Delegation &delegation)
 Node API. More...
 
bool removeNode (NodeId nodeid)
 
bool forNode (NodeId nodeid, std::function< bool(const Node &n)> func) const
 
bool updateNextRequestTime (NodeId nodeid, TimePoint timeout)
 
NodeId selectNode ()
 Randomly select a node to poll. More...
 
void updatedBlockTip ()
 Update the peer set when a nw block is connected. More...
 
PeerId getPeerId (const Proof &proof)
 Provide the PeerId associated with the given proof. More...
 
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 datastructures. More...
 
bool verify () const
 Perform consistency check on internal data structures. More...
 
uint64_t getSlotCount () const
 
uint64_t getFragmentation () const
 

Private Types

using PeerSet = boost::multi_index_container< Peer, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::member< Peer, PeerId, &Peer::peerid > >, boost::multi_index::hashed_unique< boost::multi_index::tag< proof_index >, proof_index, SaltedProofIdHasher > >>
 Several nodes can make an avalanche peer. More...
 
using NodeSet = boost::multi_index_container< Node, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::member< Node, NodeId, &Node::nodeid > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< next_request_time >, boost::multi_index::composite_key< Node, boost::multi_index::member< Node, PeerId, &Node::peerid >, boost::multi_index::member< Node, TimePoint, &Node::nextRequestTime > >> >>
 

Private Member Functions

PeerSet::iterator fetchOrCreatePeer (const Proof &proof)
 
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
 
std::unordered_map< COutPoint, PeerId, SaltedOutpointHasherutxos
 
NodeSet nodes
 

Static Private Attributes

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

Detailed Description

Definition at line 89 of file peermanager.h.

Member Typedef Documentation

◆ NodeSet

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

Definition at line 126 of file peermanager.h.

◆ PeerSet

using avalanche::PeerManager::PeerSet = boost::multi_index_container< Peer, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::member<Peer, PeerId, &Peer::peerid> >, boost::multi_index::hashed_unique< boost::multi_index::tag<proof_index>, proof_index, 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 106 of file peermanager.h.

Member Function Documentation

◆ addNode()

bool PeerManager::addNode ( NodeId  nodeid,
const Proof proof,
const Delegation delegation 
)

Node API.

Definition at line 16 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 59 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 datastructures.

Returns how much slot space was saved after compaction.

Definition at line 288 of file peermanager.cpp.

Here is the caller graph for this function:

◆ fetchOrCreatePeer()

PeerManager::PeerSet::iterator PeerManager::fetchOrCreatePeer ( const Proof proof)
private

Definition at line 189 of file peermanager.cpp.

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

◆ forNode()

bool PeerManager::forNode ( NodeId  nodeid,
std::function< bool(const Node &n)>  func 
) const

Definition at line 125 of file peermanager.cpp.

◆ getFragmentation()

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

Definition at line 186 of file peermanager.h.

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

◆ getPeerId()

PeerId PeerManager::getPeerId ( const Proof proof)

Provide the PeerId associated with the given proof.

If the peer does not exists, then it is created.

Definition at line 183 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 185 of file peermanager.h.

Here is the caller graph for this function:

◆ removeNode()

bool PeerManager::removeNode ( NodeId  nodeid)

Definition at line 76 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 92 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 245 of file peermanager.cpp.

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

◆ selectNode()

NodeId PeerManager::selectNode ( )

Randomly select a node to poll.

Definition at line 140 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 272 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 nw block is connected.

Definition at line 163 of file peermanager.cpp.

Here is the call graph for this function:

◆ updateNextRequestTime()

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

Definition at line 131 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 320 of file peermanager.cpp.

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

Member Data Documentation

◆ fragmentation

uint64_t avalanche::PeerManager::fragmentation = 0
private

Definition at line 92 of file peermanager.h.

◆ nextPeerId

PeerId avalanche::PeerManager::nextPeerId = 0
private

Definition at line 108 of file peermanager.h.

◆ nodes

NodeSet avalanche::PeerManager::nodes
private

Definition at line 128 of file peermanager.h.

◆ peers

PeerSet avalanche::PeerManager::peers
private

Definition at line 109 of file peermanager.h.

◆ SELECT_NODE_MAX_RETRY

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

Definition at line 131 of file peermanager.h.

◆ SELECT_PEER_MAX_RETRY

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

Definition at line 130 of file peermanager.h.

◆ slotCount

uint64_t avalanche::PeerManager::slotCount = 0
private

Definition at line 91 of file peermanager.h.

◆ slots

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

Definition at line 90 of file peermanager.h.

◆ utxos

std::unordered_map<COutPoint, PeerId, SaltedOutpointHasher> avalanche::PeerManager::utxos
private

Definition at line 111 of file peermanager.h.


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