[#PeerManager] = PeerManager :mrdocs: Drives the peer‐to‐peer message processing and relay logic for a node. == Synopsis Declared in `<net_processing.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class PeerManager : public xref:CValidationInterface.adoc[CValidationInterface] , public xref:NetEventsInterface.adoc[NetEventsInterface] ---- == Base Classes [cols="1,4"] |=== | Name| Description | `xref:CValidationInterface.adoc[CValidationInterface]` | Implement this to subscribe to events generated in validation and mempool | `xref:NetEventsInterface.adoc[NetEventsInterface]` | Interface for message handling |=== == Types [cols="1,4"] |=== | Name| Description | xref:PeerManager/Options.adoc[`Options`] | Tunable options controlling peer manager behavior. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:PeerManager/2destructor.adoc[`~PeerManager`] [.small]#[destructor]# [.small]#[virtual]# | Destroy the peer manager. | xref:PeerManager/AbortPrivateBroadcast.adoc[`AbortPrivateBroadcast`] [.small]#[virtual]# | Abort private broadcast attempts for transactions currently being privately broadcast. | xref:PeerManager/CheckForStaleTipAndEvictPeers.adoc[`CheckForStaleTipAndEvictPeers`] [.small]#[virtual]# | Evict extra outbound peers. If we think our tip may be stale, connect to an extra outbound. Public for unit testing. | xref:PeerManager/FetchBlock.adoc[`FetchBlock`] [.small]#[virtual]# | Attempt to manually fetch block from a given peer. We must already have the header. | xref:NetEventsInterface/FinalizeNode.adoc[`FinalizeNode`] [.small]#[virtual]# | Handle removal of a peer (clear state). | xref:PeerManager/GetDesirableServiceFlags.adoc[`GetDesirableServiceFlags`] [.small]#[virtual]# | Gets the set of service flags which are "desirable" for a given peer. | xref:PeerManager/GetInfo.adoc[`GetInfo`] [.small]#[virtual]# | Get peer manager info. | xref:PeerManager/GetNodeStateStats.adoc[`GetNodeStateStats`] [.small]#[virtual]# | Get statistics from node state | xref:PeerManager/GetOrphanTransactions.adoc[`GetOrphanTransactions`] [.small]#[virtual]# | Get information about transactions currently held in the orphan pool. | xref:PeerManager/GetPrivateBroadcastInfo.adoc[`GetPrivateBroadcastInfo`] [.small]#[virtual]# | Get info about transactions currently being privately broadcast. | xref:NetEventsInterface/HasAllDesirableServiceFlags.adoc[`HasAllDesirableServiceFlags`] [.small]#[virtual]# | Callback to determine whether the given set of service flags are sufficient for a peer to be "relevant". | xref:NetEventsInterface/InitializeNode.adoc[`InitializeNode`] [.small]#[virtual]# | Initialize a peer (setup state). | xref:PeerManager/InitiateTxBroadcastPrivate.adoc[`InitiateTxBroadcastPrivate`] [.small]#[virtual]# | Initiate a private transaction broadcast. This is done asynchronously via short‐lived connections to peers on privacy networks. | xref:PeerManager/InitiateTxBroadcastToAll.adoc[`InitiateTxBroadcastToAll`] [.small]#[virtual]# | Initiate a transaction broadcast to eligible peers. Queue the witness transaction id to the inbound and outbound inv backlogs. Later, depending on `‐txsendrate`, the peer's next inventory send time and if the transaction is in the mempool, an `INV` about it may be sent to the peer. | xref:NetEventsInterface/ProcessMessages.adoc[`ProcessMessages`] [.small]#[virtual]# | Process protocol messages received from a given node | xref:NetEventsInterface/SendMessages.adoc[`SendMessages`] [.small]#[virtual]# | Send queued protocol messages to a given node. | xref:PeerManager/SendPings.adoc[`SendPings`] [.small]#[virtual]# | Send ping message to all peers | xref:PeerManager/SetBestBlock.adoc[`SetBestBlock`] [.small]#[virtual]# | Set the height of the best block and its time (seconds since epoch). | xref:PeerManager/StartScheduledTasks.adoc[`StartScheduledTasks`] [.small]#[virtual]# | Begin running background tasks, should only be called once | xref:PeerManager/UnitTestMisbehaving.adoc[`UnitTestMisbehaving`] [.small]#[virtual]# | Apply misbehavior scoring to a peer directly. Public for unit testing. | xref:PeerManager/UpdateLastBlockAnnounceTime.adoc[`UpdateLastBlockAnnounceTime`] [.small]#[virtual]# | This function is used for testing the stale tip eviction logic, see denialofservice_tests.cpp |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:PeerManager/make.adoc[`make`] | Create a PeerManager instance wired to the node's networking and validation components. |=== == Static Data Members [cols="1,4"] |=== | Name| Description | xref:NetEventsInterface/g_msgproc_mutex.adoc[`g_msgproc_mutex`] | Mutex for anything that is only accessed via the msg processing thread |=== == Protected Member Functions [cols="1,4"] |=== | Name| Description | xref:CValidationInterface/ActiveTipChange.adoc[`ActiveTipChange`] [.small]#[virtual]# | Notifies listeners any time the block chain tip changes, synchronously. | xref:CValidationInterface/BlockChecked.adoc[`BlockChecked`] [.small]#[virtual]# | Notifies listeners of a block validation result. If the provided BlockValidationState IsValid, the provided block is guaranteed to be the current best block at the time the callback was generated (not necessarily now). | xref:CValidationInterface/BlockConnected.adoc[`BlockConnected`] [.small]#[virtual]# | Notifies listeners of a block being connected. | xref:CValidationInterface/BlockDisconnected.adoc[`BlockDisconnected`] [.small]#[virtual]# | Notifies listeners of a block being disconnected Provides the block that was disconnected. | xref:CValidationInterface/ChainStateFlushed.adoc[`ChainStateFlushed`] [.small]#[virtual]# | Notifies listeners of the new active block chain on‐disk. | xref:CValidationInterface/MempoolTransactionsRemovedForBlock.adoc[`MempoolTransactionsRemovedForBlock`] [.small]#[virtual]# | Notifies listeners of transactions removed from the mempool as as a result of new block being connected. MempoolTransactionsRemovedForBlock will be fired before BlockConnected. | xref:CValidationInterface/NewPoWValidBlock.adoc[`NewPoWValidBlock`] [.small]#[virtual]# | Notifies listeners that a block which builds directly on our current tip has been received and connected to the headers tree, though not validated yet. | xref:CValidationInterface/TransactionAddedToMempool.adoc[`TransactionAddedToMempool`] [.small]#[virtual]# | Notifies listeners of a transaction having been added to mempool. | xref:CValidationInterface/TransactionRemovedFromMempool.adoc[`TransactionRemovedFromMempool`] [.small]#[virtual]# | Notifies listeners of a transaction leaving mempool. | xref:CValidationInterface/UpdatedBlockTip.adoc[`UpdatedBlockTip`] [.small]#[virtual]# | Notifies listeners when the block chain tip advances. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:EnsurePeerman.adoc[`EnsurePeerman`] | Get the peer manager from a node context, asserting it is present. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#