Branch data Line data Source code
# 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 <validationinterface.h> # 11 : : # 12 : : class CAddrMan; # 13 : : class CChainParams; # 14 : : class CTxMemPool; # 15 : : class ChainstateManager; # 16 : : # 17 : : /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */ # 18 : : static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; # 19 : : /** Default number of orphan+recently-replaced txn to keep around for block reconstruction */ # 20 : : static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100; # 21 : : static const bool DEFAULT_PEERBLOOMFILTERS = false; # 22 : : static const bool DEFAULT_PEERBLOCKFILTERS = false; # 23 : : /** Threshold for marking a node to be discouraged, e.g. disconnected and added to the discouragement filter. */ # 24 : : static const int DISCOURAGEMENT_THRESHOLD{100}; # 25 : : # 26 : : struct CNodeStateStats { # 27 : : int nSyncHeight = -1; # 28 : : int nCommonHeight = -1; # 29 : : int m_starting_height = -1; # 30 : : std::chrono::microseconds m_ping_wait; # 31 : : std::vector<int> vHeightInFlight; # 32 : : }; # 33 : : # 34 : : class PeerManager : public CValidationInterface, public NetEventsInterface # 35 : : { # 36 : : public: # 37 : : static std::unique_ptr<PeerManager> make(const CChainParams& chainparams, CConnman& connman, CAddrMan& addrman, # 38 : : BanMan* banman, CScheduler& scheduler, ChainstateManager& chainman, # 39 : : CTxMemPool& pool, bool ignore_incoming_txs); # 40 : 798 : virtual ~PeerManager() { } # 41 : : # 42 : : /** Get statistics from node state */ # 43 : : virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0; # 44 : : # 45 : : /** Whether this node ignores txs received over p2p. */ # 46 : : virtual bool IgnoresIncomingTxs() = 0; # 47 : : # 48 : : /** Relay transaction to all peers. */ # 49 : : virtual void RelayTransaction(const uint256& txid, const uint256& wtxid) = 0; # 50 : : # 51 : : /** Send ping message to all peers */ # 52 : : virtual void SendPings() = 0; # 53 : : # 54 : : /** Set the best height */ # 55 : : virtual void SetBestHeight(int height) = 0; # 56 : : # 57 : : /** # 58 : : * Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node # 59 : : * to be discouraged, meaning the peer might be disconnected and added to the discouragement filter. # 60 : : * Public for unit testing. # 61 : : */ # 62 : : virtual void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) = 0; # 63 : : # 64 : : /** # 65 : : * Evict extra outbound peers. If we think our tip may be stale, connect to an extra outbound. # 66 : : * Public for unit testing. # 67 : : */ # 68 : : virtual void CheckForStaleTipAndEvictPeers() = 0; # 69 : : # 70 : : /** Process a single message from a peer. Public for fuzz testing */ # 71 : : virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv, # 72 : : const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) = 0; # 73 : : }; # 74 : : # 75 : : #endif // BITCOIN_NET_PROCESSING_H