// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_NET_PROCESSING_H #define BITCOIN_NET_PROCESSING_H #include #include #include /** Default for -maxorphantxsize, maximum size in megabytes the orphan map can grow before entries are removed */ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS_SIZE = 10; // this allows around 100 TXs of max size (and many more of normal size) /** Default number of orphan+recently-replaced txn to keep around for block reconstruction */ static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100; /** Default for BIP61 (sending reject messages) */ static constexpr bool DEFAULT_ENABLE_BIP61 = true; class PeerLogicValidation : public CValidationInterface, public NetEventsInterface { private: CConnman* const connman; public: explicit PeerLogicValidation(CConnman* connmanIn, CScheduler &scheduler, bool enable_bip61); void BlockConnected(const std::shared_ptr& pblock, const CBlockIndex* pindexConnected, const std::vector& vtxConflicted) override; void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override; void BlockChecked(const CBlock& block, const CValidationState& state) override; void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr& pblock) override; void InitializeNode(CNode* pnode) override; void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override; /** Process protocol messages received from a given node */ bool ProcessMessages(CNode* pfrom, std::atomic& interrupt, bool &fRetDidWork) override; /** * Send queued protocol messages to be sent to a give node. * * @param[in] pto The node which we are sending messages to. * @param[in] interrupt Interrupt condition for processing threads * @return True if there is more work to be done */ bool SendMessages(CNode* pto, std::atomic& interrupt) override; void ConsiderEviction(CNode *pto, int64_t time_in_seconds); void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams); void EvictExtraOutboundPeers(int64_t time_in_seconds); private: int64_t m_stale_tip_check_time; //! Next time to check for stale tip /** Enable BIP61 (sending reject messages) */ const bool m_enable_bip61; }; struct CNodeStateStats { int nMisbehavior; int nSyncHeight; int nCommonHeight; std::vector vHeightInFlight; }; /** Get statistics from node state */ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats); bool IsBanned(NodeId nodeid); // Upstream moved this into net_processing.cpp (13417), however since we use Misbehaving in a number of dash specific // files such as mnauth.cpp and governance.cpp it makes sense to keep it in the header /** Increase a node's misbehavior score. */ void Misbehaving(NodeId nodeid, int howmuch, const std::string& message=""); void EraseObjectRequest(NodeId nodeId, const CInv& inv); void RequestObject(NodeId nodeId, const CInv& inv, std::chrono::microseconds current_time, bool fForce=false); size_t GetRequestedObjectCount(NodeId nodeId); #endif // BITCOIN_NET_PROCESSING_H