![]() |
Bitcoin Core
0.21.1
P2P Digital Currency
|
#include <net_processing.h>
Public Member Functions | |
| PeerManager (const CChainParams &chainparams, CConnman &connman, BanMan *banman, CScheduler &scheduler, ChainstateManager &chainman, CTxMemPool &pool) | |
| void | BlockConnected (const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected) override |
| Overridden from CValidationInterface. More... | |
| void | BlockDisconnected (const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex) override |
| Notifies listeners of a block being disconnected. More... | |
| void | UpdatedBlockTip (const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override |
| Overridden from CValidationInterface. More... | |
| void | BlockChecked (const CBlock &block, const BlockValidationState &state) override |
| Overridden from CValidationInterface. More... | |
| void | NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &pblock) override |
| Overridden from CValidationInterface. More... | |
| void | InitializeNode (CNode *pnode) override |
| Initialize a peer by adding it to mapNodeState and pushing a message requesting its version. More... | |
| void | FinalizeNode (const CNode &node, bool &fUpdateConnectionTime) override |
| Handle removal of a peer by updating various state and removing it from mapNodeState. More... | |
| bool | ProcessMessages (CNode *pfrom, std::atomic< bool > &interrupt) override |
| Process protocol messages received from a given node. More... | |
| bool | SendMessages (CNode *pto) override EXCLUSIVE_LOCKS_REQUIRED(pto-> cs_sendProcessing) |
| Send queued protocol messages to be sent to a give node. More... | |
| void | ConsiderEviction (CNode &pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
| Consider evicting an outbound peer based on the amount of time they've been behind our tip. More... | |
| void | CheckForStaleTipAndEvictPeers () |
| Evict extra outbound peers. More... | |
| void | EvictExtraOutboundPeers (int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
| If we have extra outbound peers, try to disconnect the one with the oldest block announcement. More... | |
| void | ReattemptInitialBroadcast (CScheduler &scheduler) const |
| Retrieve unbroadcast transactions from the mempool and reattempt sending to peers. More... | |
| void | ProcessMessage (CNode &pfrom, const std::string &msg_type, CDataStream &vRecv, const std::chrono::microseconds time_received, const std::atomic< bool > &interruptMsgProc) |
| Process a single message from a peer. More... | |
| void | Misbehaving (const NodeId pnode, const int howmuch, const std::string &message) |
| Increment peer's misbehavior score. More... | |
Private Member Functions | |
| bool | MaybePunishNodeForBlock (NodeId nodeid, const BlockValidationState &state, bool via_compact_block, const std::string &message="") |
| Potentially mark a node discouraged based on the contents of a BlockValidationState object. More... | |
| bool | MaybePunishNodeForTx (NodeId nodeid, const TxValidationState &state, const std::string &message="") |
| Potentially disconnect and discourage a node based on the contents of a TxValidationState object. More... | |
| bool | MaybeDiscourageAndDisconnect (CNode &pnode) |
| Maybe disconnect a peer and discourage future connections from its address. More... | |
| void | ProcessOrphanTx (std::set< uint256 > &orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main |
| void | ProcessHeadersMessage (CNode &pfrom, const std::vector< CBlockHeader > &headers, bool via_compact_block) |
| Process a single headers message from a peer. More... | |
| void | SendBlockTransactions (CNode &pfrom, const CBlock &block, const BlockTransactionsRequest &req) |
| TxRequestTracker m_txrequest | GUARDED_BY (::cs_main) |
Private Attributes | |
| void | g_cs_orphans |
| void AddTxAnnouncement(const CNode &node, const GenTxid >xid, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(const CChainParams & | m_chainparams |
| Register with TxRequestTracker that an INV has been received from a peer. More... | |
| CConnman & | m_connman |
| BanMan *const | m_banman |
| Pointer to this node's banman. More... | |
| ChainstateManager & | m_chainman |
| CTxMemPool & | m_mempool |
| int64_t | m_stale_tip_check_time |
| Next time to check for stale tip. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from CValidationInterface | |
| ~CValidationInterface ()=default | |
| Protected destructor so that instances can only be deleted by derived classes. More... | |
| virtual void | TransactionAddedToMempool (const CTransactionRef &tx, uint64_t mempool_sequence) |
| Notifies listeners of a transaction having been added to mempool. More... | |
| virtual void | TransactionRemovedFromMempool (const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) |
| Notifies listeners of a transaction leaving mempool. More... | |
| virtual void | ChainStateFlushed (const CBlockLocator &locator) |
| Notifies listeners of the new active block chain on-disk. More... | |
Protected Member Functions inherited from NetEventsInterface | |
| ~NetEventsInterface ()=default | |
| Protected destructor so that instances can only be deleted by derived classes. More... | |
Definition at line 35 of file net_processing.h.
| PeerManager::PeerManager | ( | const CChainParams & | chainparams, |
| CConnman & | connman, | ||
| BanMan * | banman, | ||
| CScheduler & | scheduler, | ||
| ChainstateManager & | chainman, | ||
| CTxMemPool & | pool | ||
| ) |
|
overridevirtual |
Overridden from CValidationInterface.
Reimplemented from CValidationInterface.
|
overridevirtual |
Overridden from CValidationInterface.
Reimplemented from CValidationInterface.
|
overridevirtual |
Notifies listeners of a block being disconnected.
Called on a background thread.
Reimplemented from CValidationInterface.
| void PeerManager::CheckForStaleTipAndEvictPeers | ( | ) |
Evict extra outbound peers.
If we think our tip may be stale, connect to an extra outbound
| void PeerManager::ConsiderEviction | ( | CNode & | pto, |
| int64_t | time_in_seconds | ||
| ) |
Consider evicting an outbound peer based on the amount of time they've been behind our tip.
| void PeerManager::EvictExtraOutboundPeers | ( | int64_t | time_in_seconds | ) |
If we have extra outbound peers, try to disconnect the one with the oldest block announcement.
|
overridevirtual |
Handle removal of a peer by updating various state and removing it from mapNodeState.
Implements NetEventsInterface.
|
private |
|
overridevirtual |
Initialize a peer by adding it to mapNodeState and pushing a message requesting its version.
Implements NetEventsInterface.
|
private |
Maybe disconnect a peer and discourage future connections from its address.
| [in] | pnode | The node to check. |
|
private |
Potentially mark a node discouraged based on the contents of a BlockValidationState object.
| [in] | via_compact_block | this bool is passed in because net_processing should punish peers differently depending on whether the data was provided in a compact block message or not. If the compact block had a valid header, but contained invalid txs, the peer should not be punished. See BIP 152. |
|
private |
Potentially disconnect and discourage a node based on the contents of a TxValidationState object.
| void PeerManager::Misbehaving | ( | const NodeId | pnode, |
| const int | howmuch, | ||
| const std::string & | message | ||
| ) |
Increment peer's misbehavior score.
If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node to be discouraged, meaning the peer might be disconnected and added to the discouragement filter. Public for unit testing.
|
overridevirtual |
Overridden from CValidationInterface.
Reimplemented from CValidationInterface.
|
private |
Process a single headers message from a peer.
| void PeerManager::ProcessMessage | ( | CNode & | pfrom, |
| const std::string & | msg_type, | ||
| CDataStream & | vRecv, | ||
| const std::chrono::microseconds | time_received, | ||
| const std::atomic< bool > & | interruptMsgProc | ||
| ) |
Process a single message from a peer.
Public for fuzz testing
|
overridevirtual |
Process protocol messages received from a given node.
| [in] | pfrom | The node which we have received messages from. |
| [in] | interrupt | Interrupt condition for processing threads |
Implements NetEventsInterface.
|
private |
| void PeerManager::ReattemptInitialBroadcast | ( | CScheduler & | scheduler | ) | const |
Retrieve unbroadcast transactions from the mempool and reattempt sending to peers.
|
private |
|
overridevirtual |
Send queued protocol messages to be sent to a give node.
| [in] | pto | The node which we are sending messages to. |
Implements NetEventsInterface.
|
overridevirtual |
Overridden from CValidationInterface.
Reimplemented from CValidationInterface.
|
private |
Definition at line 125 of file net_processing.h.
|
private |
Pointer to this node's banman.
May be nullptr - check existence before dereferencing.
Definition at line 140 of file net_processing.h.
|
private |
Definition at line 141 of file net_processing.h.
|
private |
Register with TxRequestTracker that an INV has been received from a peer.
The announcement parameters are decided in PeerManager and then passed to TxRequestTracker.
Definition at line 134 of file net_processing.h.
|
private |
Definition at line 138 of file net_processing.h.
|
private |
Definition at line 142 of file net_processing.h.
|
private |
Next time to check for stale tip.
Definition at line 145 of file net_processing.h.
1.8.8