Move network-msg-processing code out of main to its own file

This commit is contained in:
Matt Corallo 2016-12-01 15:45:50 -08:00
parent 87c35f5843
commit e736772c56
16 changed files with 3096 additions and 3028 deletions

View file

@ -109,6 +109,7 @@ BITCOIN_CORE_H = \
merkleblock.h \
miner.h \
net.h \
net_processing.h \
netaddress.h \
netbase.h \
netmessagemaker.h \
@ -183,6 +184,7 @@ libbitcoin_server_a_SOURCES = \
merkleblock.cpp \
miner.cpp \
net.cpp \
net_processing.cpp \
noui.cpp \
policy/fees.cpp \
policy/policy.cpp \

View file

@ -6,6 +6,7 @@
#include "chainparams.h"
#include "main.h"
#include "streams.h"
#include "consensus/validation.h"
namespace block_bench {

View file

@ -23,6 +23,7 @@
#include "miner.h"
#include "netbase.h"
#include "net.h"
#include "net_processing.h"
#include "policy/policy.h"
#include "rpc/server.h"
#include "rpc/register.h"

File diff suppressed because it is too large Load diff

View file

@ -13,10 +13,9 @@
#include "amount.h"
#include "chain.h"
#include "coins.h"
#include "net.h"
#include "protocol.h" // For CMessageHeader::MessageStartChars
#include "script/script_error.h"
#include "sync.h"
#include "validationinterface.h"
#include "versionbits.h"
#include <algorithm>
@ -28,7 +27,10 @@
#include <utility>
#include <vector>
#include <atomic>
#include <boost/unordered_map.hpp>
#include <boost/filesystem/path.hpp>
class CBlockIndex;
class CBlockTreeDB;
@ -560,46 +562,4 @@ void DumpMempool();
/** Load the mempool from disk. */
bool LoadMempool();
// The following things handle network-processing logic
// (and should be moved to a separate file)
/** Register with a network node to receive its signals */
void RegisterNodeSignals(CNodeSignals& nodeSignals);
/** Unregister a network node */
void UnregisterNodeSignals(CNodeSignals& nodeSignals);
class PeerLogicValidation : public CValidationInterface {
private:
CConnman* connman;
public:
PeerLogicValidation(CConnman* connmanIn);
virtual void SyncTransaction(const CTransaction& tx, const CBlockIndex* pindex, int nPosInBlock);
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload);
virtual void BlockChecked(const CBlock& block, const CValidationState& state);
};
struct CNodeStateStats {
int nMisbehavior;
int nSyncHeight;
int nCommonHeight;
std::vector<int> vHeightInFlight;
};
/** Get statistics from node state */
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
/** Increase a node's misbehavior score. */
void Misbehaving(NodeId nodeid, int howmuch);
/** Process protocol messages received from a given node */
bool ProcessMessages(CNode* pfrom, CConnman& connman);
/**
* Send queued protocol messages to be sent to a give node.
*
* @param[in] pto The node which we are sending messages to.
* @param[in] connman The connection manager for that node.
*/
bool SendMessages(CNode* pto, CConnman& connman);
#endif // BITCOIN_MAIN_H

3026
src/net_processing.cpp Normal file

File diff suppressed because it is too large Load diff

51
src/net_processing.h Normal file
View file

@ -0,0 +1,51 @@
// 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 "net.h"
#include "validationinterface.h"
/** Register with a network node to receive its signals */
void RegisterNodeSignals(CNodeSignals& nodeSignals);
/** Unregister a network node */
void UnregisterNodeSignals(CNodeSignals& nodeSignals);
class PeerLogicValidation : public CValidationInterface {
private:
CConnman* connman;
public:
PeerLogicValidation(CConnman* connmanIn);
virtual void SyncTransaction(const CTransaction& tx, const CBlockIndex* pindex, int nPosInBlock);
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload);
virtual void BlockChecked(const CBlock& block, const CValidationState& state);
};
struct CNodeStateStats {
int nMisbehavior;
int nSyncHeight;
int nCommonHeight;
std::vector<int> vHeightInFlight;
};
/** Get statistics from node state */
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
/** Increase a node's misbehavior score. */
void Misbehaving(NodeId nodeid, int howmuch);
/** Process protocol messages received from a given node */
bool ProcessMessages(CNode* pfrom, CConnman& connman);
/**
* Send queued protocol messages to be sent to a give node.
*
* @param[in] pto The node which we are sending messages to.
* @param[in] connman The connection manager for that node.
*/
bool SendMessages(CNode* pto, CConnman& connman);
#endif // BITCOIN_NET_PROCESSING_H

View file

@ -12,6 +12,7 @@
#include "chainparams.h"
#include "checkpoints.h"
#include "clientversion.h"
#include "main.h"
#include "net.h"
#include "txmempool.h"
#include "ui_interface.h"

View file

@ -8,6 +8,7 @@
#include "guiconstants.h"
#include "guiutil.h"
#include "main.h" // for cs_main
#include "sync.h"
#include <QDebug>

View file

@ -5,7 +5,7 @@
#ifndef BITCOIN_QT_PEERTABLEMODEL_H
#define BITCOIN_QT_PEERTABLEMODEL_H
#include "main.h" // For CNodeStateStats
#include "net_processing.h" // For CNodeStateStats
#include "net.h"
#include <QAbstractTableModel>

View file

@ -15,8 +15,10 @@
#include "base58.h"
#include "keystore.h"
#include "main.h"
#include "net.h" // for g_connman
#include "sync.h"
#include "ui_interface.h"
#include "util.h" // for GetBoolArg
#include "wallet/wallet.h"
#include "wallet/walletdb.h" // for BackupWallet

View file

@ -8,6 +8,7 @@
#include "clientversion.h"
#include "main.h"
#include "net.h"
#include "net_processing.h"
#include "netbase.h"
#include "protocol.h"
#include "sync.h"

View file

@ -6,8 +6,8 @@
#include "chainparams.h"
#include "keystore.h"
#include "main.h"
#include "net.h"
#include "net_processing.h"
#include "pow.h"
#include "script/sign.h"
#include "serialize.h"

View file

@ -4,6 +4,7 @@
#include "chainparams.h"
#include "main.h"
#include "net.h"
#include "test/test_bitcoin.h"

View file

@ -12,6 +12,7 @@
#include "key.h"
#include "main.h"
#include "miner.h"
#include "net_processing.h"
#include "pubkey.h"
#include "random.h"
#include "txdb.h"

View file

@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chainparams.h"
#include "streams.h"
#include "zmqpublishnotifier.h"
#include "main.h"
#include "util.h"