PIVX Core  5.6.99
P2P Digital Currency
net_processing.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2015-2021 The PIVX Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef PIVX_NET_PROCESSING_H
8 #define PIVX_NET_PROCESSING_H
9 
10 #include "net.h"
11 #include "validationinterface.h"
12 
13 extern RecursiveMutex cs_main; // !TODO: change mutex to cs_orphans
14 
16 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 25;
18 static const int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
20 static const int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
22 static const bool DEFAULT_BLOCK_SPAM_FILTER = true;
24 static const unsigned int DEFAULT_BLOCK_SPAM_FILTER_MAX_SIZE = 100;
26 static const unsigned int DEFAULT_BLOCK_SPAM_FILTER_MAX_AVG = 10;
27 
30 static const unsigned int INVENTORY_BROADCAST_INTERVAL = 5;
33 static const unsigned int INVENTORY_BROADCAST_MAX = 7 * INVENTORY_BROADCAST_INTERVAL;
34 
36 private:
38 
39 public:
41  ~PeerLogicValidation() = default;
42 
43  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) override;
44  void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
45  void BlockChecked(const CBlock& block, const CValidationState& state) override;
46 
47 
48  void InitializeNode(CNode* pnode) override;
49  void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override;
51  bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
59  bool SendMessages(CNode* pto, std::atomic<bool>& interrupt) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing);
60 };
61 
66  std::vector<int> vHeightInFlight;
67  uint64_t m_addr_processed = 0;
68  uint64_t m_addr_rate_limited = 0;
69 };
70 
72 bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats);
74 void Misbehaving(NodeId nodeid, int howmuch, const std::string& message="") EXCLUSIVE_LOCKS_REQUIRED(cs_main);
75 bool IsBanned(NodeId nodeid);
76 
77 
78 using SecondsDouble = std::chrono::duration<double, std::chrono::seconds::period>;
82 inline double CountSecondsDouble(SecondsDouble t) { return t.count(); }
83 
84 #endif // PIVX_NET_PROCESSING_H
Definition: block.h:80
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
Definition: net.h:145
Information about a peer.
Definition: net.h:669
Implement this to subscribe to events generated in validation.
Capture information about block/transaction validation.
Definition: validation.h:24
Interface for message handling.
Definition: net.h:959
void BlockConnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindex) override
Notifies listeners of a block being connected.
void FinalizeNode(NodeId nodeid, bool &fUpdateConnectionTime) override
void BlockChecked(const CBlock &block, const CValidationState &state) override
bool SendMessages(CNode *pto, std::atomic< bool > &interrupt) override EXCLUSIVE_LOCKS_REQUIRED(pto -> cs_sendProcessing)
Send queued protocol messages to be sent to a give node.
PeerLogicValidation(CConnman *connman)
~PeerLogicValidation()=default
void InitializeNode(CNode *pnode) override
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Notifies listeners when the block chain tip advances.
bool ProcessMessages(CNode *pfrom, std::atomic< bool > &interrupt) override
Process protocol messages received from a given node.
clock::duration duration
Definition: bench.h:49
Definition: uint256.h:212
int NodeId
Definition: net.h:109
std::chrono::duration< double, std::chrono::seconds::period > SecondsDouble
void Misbehaving(NodeId nodeid, int howmuch, const std::string &message="") EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Increase a node's misbehavior score.
double CountSecondsDouble(SecondsDouble t)
Helper to count the seconds in any std::chrono::duration type.
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:80
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
Get statistics from node state.
bool IsBanned(NodeId nodeid)
std::vector< int > vHeightInFlight
uint64_t m_addr_rate_limited
uint64_t m_addr_processed
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:50