You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

net_processing.h 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 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. #ifndef BITCOIN_NET_PROCESSING_H
  6. #define BITCOIN_NET_PROCESSING_H
  7. #include "net.h"
  8. #include "validationinterface.h"
  9. /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
  10. static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
  11. /** Expiration time for orphan transactions in seconds */
  12. static const int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
  13. /** Minimum time between orphan transactions expire time checks in seconds */
  14. static const int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
  15. /** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
  16. static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
  17. /** Headers download timeout expressed in microseconds
  18. * Timeout = base + per_header * (expected number of headers) */
  19. static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000; // 15 minutes
  20. static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 1000; // 1ms/header
  21. class PeerLogicValidation : public CValidationInterface, public NetEventsInterface {
  22. private:
  23. CConnman* connman;
  24. public:
  25. explicit PeerLogicValidation(CConnman* connman);
  26. void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected, const std::vector<CTransactionRef>& vtxConflicted) override;
  27. void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
  28. void BlockChecked(const CBlock& block, const CValidationState& state) override;
  29. void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
  30. void InitializeNode(CNode* pnode) override;
  31. void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override;
  32. /** Process protocol messages received from a given node */
  33. bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
  34. /**
  35. * Send queued protocol messages to be sent to a give node.
  36. *
  37. * @param[in] pto The node which we are sending messages to.
  38. * @param[in] interrupt Interrupt condition for processing threads
  39. * @return True if there is more work to be done
  40. */
  41. bool SendMessages(CNode* pto, std::atomic<bool>& interrupt) override;
  42. };
  43. struct CNodeStateStats {
  44. int nMisbehavior;
  45. int nSyncHeight;
  46. int nCommonHeight;
  47. std::vector<int> vHeightInFlight;
  48. };
  49. /** Get statistics from node state */
  50. bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
  51. /** Increase a node's misbehavior score. */
  52. void Misbehaving(NodeId nodeid, int howmuch);
  53. #endif // BITCOIN_NET_PROCESSING_H