Browse Source

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

0.14
Matt Corallo 8 years ago
parent
commit
e736772c56
  1. 2
      src/Makefile.am
  2. 1
      src/bench/checkblock.cpp
  3. 1
      src/init.cpp
  4. 3005
      src/main.cpp
  5. 48
      src/main.h
  6. 3026
      src/net_processing.cpp
  7. 51
      src/net_processing.h
  8. 1
      src/qt/clientmodel.cpp
  9. 1
      src/qt/peertablemodel.cpp
  10. 2
      src/qt/peertablemodel.h
  11. 2
      src/qt/walletmodel.cpp
  12. 1
      src/rpc/net.cpp
  13. 2
      src/test/DoS_tests.cpp
  14. 1
      src/test/main_tests.cpp
  15. 1
      src/test/test_bitcoin.cpp
  16. 1
      src/zmq/zmqpublishnotifier.cpp

2
src/Makefile.am

@ -109,6 +109,7 @@ BITCOIN_CORE_H = \ @@ -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 = \ @@ -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 \

1
src/bench/checkblock.cpp

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

1
src/init.cpp

@ -23,6 +23,7 @@ @@ -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"

3005
src/main.cpp

File diff suppressed because it is too large Load Diff

48
src/main.h

@ -13,10 +13,9 @@ @@ -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 @@ @@ -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(); @@ -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

File diff suppressed because it is too large Load Diff

51
src/net_processing.h

@ -0,0 +1,51 @@ @@ -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

1
src/qt/clientmodel.cpp

@ -12,6 +12,7 @@ @@ -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"

1
src/qt/peertablemodel.cpp

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

2
src/qt/peertablemodel.h

@ -5,7 +5,7 @@ @@ -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>

2
src/qt/walletmodel.cpp

@ -15,8 +15,10 @@ @@ -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

1
src/rpc/net.cpp

@ -8,6 +8,7 @@ @@ -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"

2
src/test/DoS_tests.cpp

@ -6,8 +6,8 @@ @@ -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"

1
src/test/main_tests.cpp

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

1
src/test/test_bitcoin.cpp

@ -12,6 +12,7 @@ @@ -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"

1
src/zmq/zmqpublishnotifier.cpp

@ -3,6 +3,7 @@ @@ -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"

Loading…
Cancel
Save