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.
6 #ifndef BITCOIN_NET_PROCESSING_H
7 #define BITCOIN_NET_PROCESSING_H
10 #include "validationinterface.h"
12 /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
13 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS
= 100;
14 /** Expiration time for orphan transactions in seconds */
15 static const int64_t ORPHAN_TX_EXPIRE_TIME
= 20 * 60;
16 /** Minimum time between orphan transactions expire time checks in seconds */
17 static const int64_t ORPHAN_TX_EXPIRE_INTERVAL
= 5 * 60;
18 /** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
19 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
= 100;
20 /** Headers download timeout expressed in microseconds
21 * Timeout = base + per_header * (expected number of headers) */
22 static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE
= 15 * 60 * 1000000; // 15 minutes
23 static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER
= 1000; // 1ms/header
25 /** Register with a network node to receive its signals */
26 void RegisterNodeSignals(CNodeSignals
& nodeSignals
);
27 /** Unregister a network node */
28 void UnregisterNodeSignals(CNodeSignals
& nodeSignals
);
30 class PeerLogicValidation
: public CValidationInterface
{
35 explicit PeerLogicValidation(CConnman
* connmanIn
);
37 void BlockConnected(const std::shared_ptr
<const CBlock
>& pblock
, const CBlockIndex
* pindexConnected
, const std::vector
<CTransactionRef
>& vtxConflicted
) override
;
38 void UpdatedBlockTip(const CBlockIndex
*pindexNew
, const CBlockIndex
*pindexFork
, bool fInitialDownload
) override
;
39 void BlockChecked(const CBlock
& block
, const CValidationState
& state
) override
;
40 void NewPoWValidBlock(const CBlockIndex
*pindex
, const std::shared_ptr
<const CBlock
>& pblock
) override
;
43 struct CNodeStateStats
{
47 std::vector
<int> vHeightInFlight
;
50 /** Get statistics from node state */
51 bool GetNodeStateStats(NodeId nodeid
, CNodeStateStats
&stats
);
52 /** Increase a node's misbehavior score. */
53 void Misbehaving(NodeId nodeid
, int howmuch
);
55 /** Process protocol messages received from a given node */
56 bool ProcessMessages(CNode
* pfrom
, CConnman
& connman
, const std::atomic
<bool>& interrupt
);
58 * Send queued protocol messages to be sent to a give node.
60 * @param[in] pto The node which we are sending messages to.
61 * @param[in] connman The connection manager for that node.
62 * @param[in] interrupt Interrupt condition for processing threads
63 * @return True if there is more work to be done
65 bool SendMessages(CNode
* pto
, CConnman
& connman
, const std::atomic
<bool>& interrupt
);
67 #endif // BITCOIN_NET_PROCESSING_H