Branch data Line data Source code
# 1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto # 2 : : // Copyright (c) 2009-2021 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 AddrMan; # 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 : : bool m_relay_txs; # 33 : : CAmount m_fee_filter_received; # 34 : : uint64_t m_addr_processed = 0; # 35 : : uint64_t m_addr_rate_limited = 0; # 36 : : bool m_addr_relay_enabled{false}; # 37 : : ServiceFlags their_services; # 38 : : int64_t presync_height{-1}; # 39 : : }; # 40 : : # 41 : : class PeerManager : public CValidationInterface, public NetEventsInterface # 42 : : { # 43 : : public: # 44 : : static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman, # 45 : : BanMan* banman, ChainstateManager& chainman, # 46 : : CTxMemPool& pool, bool ignore_incoming_txs); # 47 : 960 : virtual ~PeerManager() { } # 48 : : # 49 : : /** # 50 : : * Attempt to manually fetch block from a given peer. We must already have the header. # 51 : : * # 52 : : * @param[in] peer_id The peer id # 53 : : * @param[in] block_index The blockindex # 54 : : * @returns std::nullopt if a request was successfully made, otherwise an error message # 55 : : */ # 56 : : virtual std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) = 0; # 57 : : # 58 : : /** Begin running background tasks, should only be called once */ # 59 : : virtual void StartScheduledTasks(CScheduler& scheduler) = 0; # 60 : : # 61 : : /** Get statistics from node state */ # 62 : : virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0; # 63 : : # 64 : : /** Whether this node ignores txs received over p2p. */ # 65 : : virtual bool IgnoresIncomingTxs() = 0; # 66 : : # 67 : : /** Relay transaction to all peers. */ # 68 : : virtual void RelayTransaction(const uint256& txid, const uint256& wtxid) = 0; # 69 : : # 70 : : /** Send ping message to all peers */ # 71 : : virtual void SendPings() = 0; # 72 : : # 73 : : /** Set the best height */ # 74 : : virtual void SetBestHeight(int height) = 0; # 75 : : # 76 : : /* Public for unit testing. */ # 77 : : virtual void UnitTestMisbehaving(NodeId peer_id, int howmuch) = 0; # 78 : : # 79 : : /** # 80 : : * Evict extra outbound peers. If we think our tip may be stale, connect to an extra outbound. # 81 : : * Public for unit testing. # 82 : : */ # 83 : : virtual void CheckForStaleTipAndEvictPeers() = 0; # 84 : : # 85 : : /** Process a single message from a peer. Public for fuzz testing */ # 86 : : virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv, # 87 : : const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) = 0; # 88 : : # 89 : : /** This function is used for testing the stale tip eviction logic, see denialofservice_tests.cpp */ # 90 : : virtual void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) = 0; # 91 : : }; # 92 : : # 93 : : #endif // BITCOIN_NET_PROCESSING_H