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 : : };
# 38 : :
# 39 : : class PeerManager : public CValidationInterface, public NetEventsInterface
# 40 : : {
# 41 : : public:
# 42 : : static std::unique_ptr<PeerManager> make(const CChainParams& chainparams, CConnman& connman, AddrMan& addrman,
# 43 : : BanMan* banman, ChainstateManager& chainman,
# 44 : : CTxMemPool& pool, bool ignore_incoming_txs);
# 45 : 968 : virtual ~PeerManager() { }
# 46 : :
# 47 : : /**
# 48 : : * Attempt to manually fetch block from a given peer. We must already have the header.
# 49 : : *
# 50 : : * @param[in] peer_id The peer id
# 51 : : * @param[in] block_index The blockindex
# 52 : : * @returns std::nullopt if a request was successfully made, otherwise an error message
# 53 : : */
# 54 : : virtual std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) = 0;
# 55 : :
# 56 : : /** Begin running background tasks, should only be called once */
# 57 : : virtual void StartScheduledTasks(CScheduler& scheduler) = 0;
# 58 : :
# 59 : : /** Get statistics from node state */
# 60 : : virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
# 61 : :
# 62 : : /** Whether this node ignores txs received over p2p. */
# 63 : : virtual bool IgnoresIncomingTxs() = 0;
# 64 : :
# 65 : : /** Relay transaction to all peers. */
# 66 : : virtual void RelayTransaction(const uint256& txid, const uint256& wtxid) = 0;
# 67 : :
# 68 : : /** Send ping message to all peers */
# 69 : : virtual void SendPings() = 0;
# 70 : :
# 71 : : /** Set the best height */
# 72 : : virtual void SetBestHeight(int height) = 0;
# 73 : :
# 74 : : /**
# 75 : : * Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
# 76 : : * to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
# 77 : : * Public for unit testing.
# 78 : : */
# 79 : : virtual void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) = 0;
# 80 : :
# 81 : : /**
# 82 : : * Evict extra outbound peers. If we think our tip may be stale, connect to an extra outbound.
# 83 : : * Public for unit testing.
# 84 : : */
# 85 : : virtual void CheckForStaleTipAndEvictPeers() = 0;
# 86 : :
# 87 : : /** Process a single message from a peer. Public for fuzz testing */
# 88 : : virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
# 89 : : const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) = 0;
# 90 : : };
# 91 : :
# 92 : : #endif // BITCOIN_NET_PROCESSING_H
|