Bitcoin Core  21.99.0
P2P Digital Currency
net_processing.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_NET_PROCESSING_H
7 #define BITCOIN_NET_PROCESSING_H
8 
9 #include <net.h>
10 #include <sync.h>
11 #include <validationinterface.h>
12 
13 class CAddrMan;
14 class CChainParams;
15 class CTxMemPool;
16 class ChainstateManager;
17 
18 extern RecursiveMutex cs_main;
19 
21 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
23 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
24 static const bool DEFAULT_PEERBLOOMFILTERS = false;
25 static const bool DEFAULT_PEERBLOCKFILTERS = false;
27 static const int DISCOURAGEMENT_THRESHOLD{100};
28 
30  int nSyncHeight = -1;
31  int nCommonHeight = -1;
33  std::chrono::microseconds m_ping_wait;
34  std::vector<int> vHeightInFlight;
35 };
36 
38 {
39 public:
40  static std::unique_ptr<PeerManager> make(const CChainParams& chainparams, CConnman& connman, CAddrMan& addrman,
41  BanMan* banman, CScheduler& scheduler, ChainstateManager& chainman,
42  CTxMemPool& pool, bool ignore_incoming_txs);
43  virtual ~PeerManager() { }
44 
46  virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) = 0;
47 
49  virtual bool IgnoresIncomingTxs() = 0;
50 
52  virtual void RelayTransaction(const uint256& txid, const uint256& wtxid)
54 
56  virtual void SendPings() = 0;
57 
59  virtual void SetBestHeight(int height) = 0;
60 
66  virtual void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) = 0;
67 
72  virtual void CheckForStaleTipAndEvictPeers() = 0;
73 
75  virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
76  const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) = 0;
77 };
78 
79 #endif // BITCOIN_NET_PROCESSING_H
CValidationInterface
Implement this to subscribe to events generated in validation.
Definition: validationinterface.h:78
NodeId
int64_t NodeId
Definition: net.h:90
PeerManager::SendPings
virtual void SendPings()=0
Send ping message to all peers.
CNodeStateStats::vHeightInFlight
std::vector< int > vHeightInFlight
Definition: net_processing.h:34
CScheduler
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:33
CNodeStateStats::nCommonHeight
int nCommonHeight
Definition: net_processing.h:31
PeerManager::IgnoresIncomingTxs
virtual bool IgnoresIncomingTxs()=0
Whether this node ignores txs received over p2p.
NetEventsInterface
Interface for message handling.
Definition: net.h:768
PeerManager::Misbehaving
virtual void Misbehaving(const NodeId pnode, const int howmuch, const std::string &message)=0
Increment peer's misbehavior score.
sync.h
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:477
CNode
Information about a peer.
Definition: net.h:396
validationinterface.h
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:64
CNodeStateStats::nSyncHeight
int nSyncHeight
Definition: net_processing.h:30
AnnotatedMixin< std::recursive_mutex >
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:131
PeerManager::SetBestHeight
virtual void SetBestHeight(int height)=0
Set the best height.
DEFAULT_MAX_ORPHAN_TRANSACTIONS
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS
Default for -maxorphantx, maximum number of orphan transactions kept in memory.
Definition: net_processing.h:21
DEFAULT_PEERBLOCKFILTERS
static const bool DEFAULT_PEERBLOCKFILTERS
Definition: net_processing.h:25
DEFAULT_PEERBLOOMFILTERS
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: net_processing.h:24
PeerManager::RelayTransaction
virtual void RelayTransaction(const uint256 &txid, const uint256 &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main)=0
Relay transaction to all peers.
PeerManager::ProcessMessage
virtual void ProcessMessage(CNode &pfrom, const std::string &msg_type, CDataStream &vRecv, const std::chrono::microseconds time_received, const std::atomic< bool > &interruptMsgProc)=0
Process a single message from a peer.
DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
Default number of orphan+recently-replaced txn to keep around for block reconstruction.
Definition: net_processing.h:23
PeerManager
Definition: net_processing.h:37
uint256
256-bit opaque blob.
Definition: uint256.h:124
PeerManager::CheckForStaleTipAndEvictPeers
virtual void CheckForStaleTipAndEvictPeers()=0
Evict extra outbound peers.
CNodeStateStats::m_starting_height
int m_starting_height
Definition: net_processing.h:32
BanMan
Definition: banman.h:57
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:807
CConnman
Definition: net.h:803
CAddrMan
Stochastical (IP) address manager.
Definition: addrman.h:172
PeerManager::~PeerManager
virtual ~PeerManager()
Definition: net_processing.h:43
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
PeerManager::GetNodeStateStats
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)=0
Get statistics from node state.
DISCOURAGEMENT_THRESHOLD
static const int DISCOURAGEMENT_THRESHOLD
Threshold for marking a node to be discouraged, e.g.
Definition: net_processing.h:27
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:204
CNodeStateStats::m_ping_wait
std::chrono::microseconds m_ping_wait
Definition: net_processing.h:33
CNodeStateStats
Definition: net_processing.h:29
net.h
PeerManager::make
static std::unique_ptr< PeerManager > make(const CChainParams &chainparams, CConnman &connman, CAddrMan &addrman, BanMan *banman, CScheduler &scheduler, ChainstateManager &chainman, CTxMemPool &pool, bool ignore_incoming_txs)
Definition: net_processing.cpp:1255