mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-08 14:34:53 -05:00
scripted-diff: Remove g_connman, g_banman globals
-BEGIN VERIFY SCRIPT- sed -i 's:#include <interfaces/chain.h>:#include <banman.h>\n#include <interfaces/chain.h>\n#include <net.h>\n#include <net_processing.h>:' src/node/context.cpp sed -i 's/namespace interfaces {/class BanMan;\nclass CConnman;\nclass PeerLogicValidation;\n&/' src/node/context.h sed -i 's/std::unique_ptr<interfaces::Chain> chain/std::unique_ptr<CConnman> connman;\n std::unique_ptr<PeerLogicValidation> peer_logic;\n std::unique_ptr<BanMan> banman;\n &/' src/node/context.h sed -i '/std::unique_ptr<[^>]\+> \(g_connman\|g_banman\|peerLogic\);/d' src/banman.h src/net.h src/init.cpp sed -i 's/g_connman/m_context.connman/g' src/interfaces/node.cpp sed -i 's/g_banman/m_context.banman/g' src/interfaces/node.cpp sed -i 's/g_connman/m_node.connman/g' src/interfaces/chain.cpp src/test/setup_common.cpp sed -i 's/g_banman/m_node.banman/g' src/test/setup_common.cpp sed -i 's/g_connman/node.connman/g' src/init.cpp src/node/transaction.cpp sed -i 's/g_banman/node.banman/g' src/init.cpp sed -i 's/peerLogic/node.peer_logic/g' src/init.cpp sed -i 's/g_connman/g_rpc_node->connman/g' src/rpc/mining.cpp src/rpc/net.cpp src/rpc/rawtransaction.cpp sed -i 's/g_banman/g_rpc_node->banman/g' src/rpc/net.cpp sed -i 's/std::shared_ptr<CWallet> wallet =/node.context()->connman = std::move(test.m_node.connman);\n &/' src/qt/test/wallettests.cpp -END VERIFY SCRIPT-
This commit is contained in:
parent
e6f4f895d5
commit
8922d7f6b7
11 changed files with 102 additions and 98 deletions
|
@ -66,5 +66,4 @@ private:
|
||||||
const int64_t m_default_ban_time;
|
const int64_t m_default_ban_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::unique_ptr<BanMan> g_banman;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
37
src/init.cpp
37
src/init.cpp
|
@ -85,9 +85,6 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
|
||||||
// Dump addresses to banlist.dat every 15 minutes (900s)
|
// Dump addresses to banlist.dat every 15 minutes (900s)
|
||||||
static constexpr int DUMP_BANS_INTERVAL = 60 * 15;
|
static constexpr int DUMP_BANS_INTERVAL = 60 * 15;
|
||||||
|
|
||||||
std::unique_ptr<CConnman> g_connman;
|
|
||||||
std::unique_ptr<PeerLogicValidation> peerLogic;
|
|
||||||
std::unique_ptr<BanMan> g_banman;
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
|
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
|
||||||
|
@ -163,8 +160,8 @@ void Interrupt(NodeContext& node)
|
||||||
InterruptREST();
|
InterruptREST();
|
||||||
InterruptTorControl();
|
InterruptTorControl();
|
||||||
InterruptMapPort();
|
InterruptMapPort();
|
||||||
if (g_connman)
|
if (node.connman)
|
||||||
g_connman->Interrupt();
|
node.connman->Interrupt();
|
||||||
if (g_txindex) {
|
if (g_txindex) {
|
||||||
g_txindex->Interrupt();
|
g_txindex->Interrupt();
|
||||||
}
|
}
|
||||||
|
@ -197,8 +194,8 @@ void Shutdown(NodeContext& node)
|
||||||
|
|
||||||
// Because these depend on each-other, we make sure that neither can be
|
// Because these depend on each-other, we make sure that neither can be
|
||||||
// using the other before destroying them.
|
// using the other before destroying them.
|
||||||
if (peerLogic) UnregisterValidationInterface(peerLogic.get());
|
if (node.peer_logic) UnregisterValidationInterface(node.peer_logic.get());
|
||||||
if (g_connman) g_connman->Stop();
|
if (node.connman) node.connman->Stop();
|
||||||
if (g_txindex) g_txindex->Stop();
|
if (g_txindex) g_txindex->Stop();
|
||||||
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
|
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
|
||||||
|
|
||||||
|
@ -211,9 +208,9 @@ void Shutdown(NodeContext& node)
|
||||||
|
|
||||||
// After the threads that potentially access these pointers have been stopped,
|
// After the threads that potentially access these pointers have been stopped,
|
||||||
// destruct and reset all to nullptr.
|
// destruct and reset all to nullptr.
|
||||||
peerLogic.reset();
|
node.peer_logic.reset();
|
||||||
g_connman.reset();
|
node.connman.reset();
|
||||||
g_banman.reset();
|
node.banman.reset();
|
||||||
g_txindex.reset();
|
g_txindex.reset();
|
||||||
DestroyAllBlockFilterIndexes();
|
DestroyAllBlockFilterIndexes();
|
||||||
|
|
||||||
|
@ -1315,13 +1312,13 @@ bool AppInitMain(NodeContext& node)
|
||||||
// is not yet setup and may end up being set up twice if we
|
// is not yet setup and may end up being set up twice if we
|
||||||
// need to reindex later.
|
// need to reindex later.
|
||||||
|
|
||||||
assert(!g_banman);
|
assert(!node.banman);
|
||||||
g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
|
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
|
||||||
assert(!g_connman);
|
assert(!node.connman);
|
||||||
g_connman = std::unique_ptr<CConnman>(new CConnman(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max())));
|
node.connman = std::unique_ptr<CConnman>(new CConnman(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max())));
|
||||||
|
|
||||||
peerLogic.reset(new PeerLogicValidation(g_connman.get(), g_banman.get(), scheduler));
|
node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), scheduler));
|
||||||
RegisterValidationInterface(peerLogic.get());
|
RegisterValidationInterface(node.peer_logic.get());
|
||||||
|
|
||||||
// sanitize comments per BIP-0014, format user agent and check total size
|
// sanitize comments per BIP-0014, format user agent and check total size
|
||||||
std::vector<std::string> uacomments;
|
std::vector<std::string> uacomments;
|
||||||
|
@ -1766,8 +1763,8 @@ bool AppInitMain(NodeContext& node)
|
||||||
connOptions.nMaxFeeler = 1;
|
connOptions.nMaxFeeler = 1;
|
||||||
connOptions.nBestHeight = chain_active_height;
|
connOptions.nBestHeight = chain_active_height;
|
||||||
connOptions.uiInterface = &uiInterface;
|
connOptions.uiInterface = &uiInterface;
|
||||||
connOptions.m_banman = g_banman.get();
|
connOptions.m_banman = node.banman.get();
|
||||||
connOptions.m_msgproc = peerLogic.get();
|
connOptions.m_msgproc = node.peer_logic.get();
|
||||||
connOptions.nSendBufferMaxSize = 1000*gArgs.GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
|
connOptions.nSendBufferMaxSize = 1000*gArgs.GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
|
||||||
connOptions.nReceiveFloodSize = 1000*gArgs.GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
|
connOptions.nReceiveFloodSize = 1000*gArgs.GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
|
||||||
connOptions.m_added_nodes = gArgs.GetArgs("-addnode");
|
connOptions.m_added_nodes = gArgs.GetArgs("-addnode");
|
||||||
|
@ -1807,7 +1804,7 @@ bool AppInitMain(NodeContext& node)
|
||||||
connOptions.m_specified_outgoing = connect;
|
connOptions.m_specified_outgoing = connect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!g_connman->Start(scheduler, connOptions)) {
|
if (!node.connman->Start(scheduler, connOptions)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1820,7 +1817,7 @@ bool AppInitMain(NodeContext& node)
|
||||||
client->start(scheduler);
|
client->start(scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
BanMan* banman = g_banman.get();
|
BanMan* banman = node.banman.get();
|
||||||
scheduler.scheduleEvery([banman]{
|
scheduler.scheduleEvery([banman]{
|
||||||
banman->DumpBanlist();
|
banman->DumpBanlist();
|
||||||
}, DUMP_BANS_INTERVAL * 1000);
|
}, DUMP_BANS_INTERVAL * 1000);
|
||||||
|
|
|
@ -100,15 +100,15 @@ public:
|
||||||
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
|
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
|
||||||
size_t getNodeCount(CConnman::NumConnections flags) override
|
size_t getNodeCount(CConnman::NumConnections flags) override
|
||||||
{
|
{
|
||||||
return g_connman ? g_connman->GetNodeCount(flags) : 0;
|
return m_context.connman ? m_context.connman->GetNodeCount(flags) : 0;
|
||||||
}
|
}
|
||||||
bool getNodesStats(NodesStats& stats) override
|
bool getNodesStats(NodesStats& stats) override
|
||||||
{
|
{
|
||||||
stats.clear();
|
stats.clear();
|
||||||
|
|
||||||
if (g_connman) {
|
if (m_context.connman) {
|
||||||
std::vector<CNodeStats> stats_temp;
|
std::vector<CNodeStats> stats_temp;
|
||||||
g_connman->GetNodeStats(stats_temp);
|
m_context.connman->GetNodeStats(stats_temp);
|
||||||
|
|
||||||
stats.reserve(stats_temp.size());
|
stats.reserve(stats_temp.size());
|
||||||
for (auto& node_stats_temp : stats_temp) {
|
for (auto& node_stats_temp : stats_temp) {
|
||||||
|
@ -129,44 +129,44 @@ public:
|
||||||
}
|
}
|
||||||
bool getBanned(banmap_t& banmap) override
|
bool getBanned(banmap_t& banmap) override
|
||||||
{
|
{
|
||||||
if (g_banman) {
|
if (m_context.banman) {
|
||||||
g_banman->GetBanned(banmap);
|
m_context.banman->GetBanned(banmap);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool ban(const CNetAddr& net_addr, BanReason reason, int64_t ban_time_offset) override
|
bool ban(const CNetAddr& net_addr, BanReason reason, int64_t ban_time_offset) override
|
||||||
{
|
{
|
||||||
if (g_banman) {
|
if (m_context.banman) {
|
||||||
g_banman->Ban(net_addr, reason, ban_time_offset);
|
m_context.banman->Ban(net_addr, reason, ban_time_offset);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool unban(const CSubNet& ip) override
|
bool unban(const CSubNet& ip) override
|
||||||
{
|
{
|
||||||
if (g_banman) {
|
if (m_context.banman) {
|
||||||
g_banman->Unban(ip);
|
m_context.banman->Unban(ip);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool disconnect(const CNetAddr& net_addr) override
|
bool disconnect(const CNetAddr& net_addr) override
|
||||||
{
|
{
|
||||||
if (g_connman) {
|
if (m_context.connman) {
|
||||||
return g_connman->DisconnectNode(net_addr);
|
return m_context.connman->DisconnectNode(net_addr);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool disconnect(NodeId id) override
|
bool disconnect(NodeId id) override
|
||||||
{
|
{
|
||||||
if (g_connman) {
|
if (m_context.connman) {
|
||||||
return g_connman->DisconnectNode(id);
|
return m_context.connman->DisconnectNode(id);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int64_t getTotalBytesRecv() override { return g_connman ? g_connman->GetTotalBytesRecv() : 0; }
|
int64_t getTotalBytesRecv() override { return m_context.connman ? m_context.connman->GetTotalBytesRecv() : 0; }
|
||||||
int64_t getTotalBytesSent() override { return g_connman ? g_connman->GetTotalBytesSent() : 0; }
|
int64_t getTotalBytesSent() override { return m_context.connman ? m_context.connman->GetTotalBytesSent() : 0; }
|
||||||
size_t getMempoolSize() override { return ::mempool.size(); }
|
size_t getMempoolSize() override { return ::mempool.size(); }
|
||||||
size_t getMempoolDynamicUsage() override { return ::mempool.DynamicMemoryUsage(); }
|
size_t getMempoolDynamicUsage() override { return ::mempool.DynamicMemoryUsage(); }
|
||||||
bool getHeaderTip(int& height, int64_t& block_time) override
|
bool getHeaderTip(int& height, int64_t& block_time) override
|
||||||
|
@ -206,11 +206,11 @@ public:
|
||||||
bool getImporting() override { return ::fImporting; }
|
bool getImporting() override { return ::fImporting; }
|
||||||
void setNetworkActive(bool active) override
|
void setNetworkActive(bool active) override
|
||||||
{
|
{
|
||||||
if (g_connman) {
|
if (m_context.connman) {
|
||||||
g_connman->SetNetworkActive(active);
|
m_context.connman->SetNetworkActive(active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); }
|
bool getNetworkActive() override { return m_context.connman && m_context.connman->GetNetworkActive(); }
|
||||||
CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) override
|
CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) override
|
||||||
{
|
{
|
||||||
FeeCalculation fee_calc;
|
FeeCalculation fee_calc;
|
||||||
|
|
|
@ -480,8 +480,6 @@ private:
|
||||||
|
|
||||||
friend struct CConnmanTest;
|
friend struct CConnmanTest;
|
||||||
};
|
};
|
||||||
extern std::unique_ptr<CConnman> g_connman;
|
|
||||||
extern std::unique_ptr<BanMan> g_banman;
|
|
||||||
void Discover();
|
void Discover();
|
||||||
void StartMapPort();
|
void StartMapPort();
|
||||||
void InterruptMapPort();
|
void InterruptMapPort();
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
|
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
|
|
||||||
|
#include <banman.h>
|
||||||
#include <interfaces/chain.h>
|
#include <interfaces/chain.h>
|
||||||
|
#include <net.h>
|
||||||
|
#include <net_processing.h>
|
||||||
|
|
||||||
NodeContext::NodeContext() {}
|
NodeContext::NodeContext() {}
|
||||||
NodeContext::~NodeContext() {}
|
NodeContext::~NodeContext() {}
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class BanMan;
|
||||||
|
class CConnman;
|
||||||
|
class PeerLogicValidation;
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
class Chain;
|
class Chain;
|
||||||
class ChainClient;
|
class ChainClient;
|
||||||
|
@ -25,6 +28,9 @@ class ChainClient;
|
||||||
//! be used without pulling in unwanted dependencies or functionality.
|
//! be used without pulling in unwanted dependencies or functionality.
|
||||||
struct NodeContext
|
struct NodeContext
|
||||||
{
|
{
|
||||||
|
std::unique_ptr<CConnman> connman;
|
||||||
|
std::unique_ptr<PeerLogicValidation> peer_logic;
|
||||||
|
std::unique_ptr<BanMan> banman;
|
||||||
std::unique_ptr<interfaces::Chain> chain;
|
std::unique_ptr<interfaces::Chain> chain;
|
||||||
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
|
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
|
||||||
{
|
{
|
||||||
// BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
|
// BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
|
||||||
// g_connman is assigned both before chain clients and before RPC server is accepting calls,
|
// node.connman is assigned both before chain clients and before RPC server is accepting calls,
|
||||||
// and reset after chain clients and RPC sever are stopped. g_connman should never be null here.
|
// and reset after chain clients and RPC sever are stopped. node.connman should never be null here.
|
||||||
assert(g_connman);
|
assert(node.connman);
|
||||||
std::promise<void> promise;
|
std::promise<void> promise;
|
||||||
uint256 hashTx = tx->GetHash();
|
uint256 hashTx = tx->GetHash();
|
||||||
bool callback_set = false;
|
bool callback_set = false;
|
||||||
|
@ -80,7 +80,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relay) {
|
if (relay) {
|
||||||
RelayTransaction(hashTx, *g_connman);
|
RelayTransaction(hashTx, *node.connman);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TransactionError::OK;
|
return TransactionError::OK;
|
||||||
|
|
|
@ -133,6 +133,7 @@ void TestGUI(interfaces::Node& node)
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
|
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
|
||||||
}
|
}
|
||||||
|
node.context()->connman = std::move(test.m_node.connman);
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
||||||
bool firstRun;
|
bool firstRun;
|
||||||
wallet->LoadWallet(firstRun);
|
wallet->LoadWallet(firstRun);
|
||||||
|
|
|
@ -425,10 +425,10 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||||
if (strMode != "template")
|
if (strMode != "template")
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
|
||||||
|
|
||||||
if(!g_connman)
|
if(!g_rpc_node->connman)
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
|
||||||
if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
|
if (g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
|
||||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, PACKAGE_NAME " is not connected!");
|
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, PACKAGE_NAME " is not connected!");
|
||||||
|
|
||||||
if (::ChainstateActive().IsInitialBlockDownload())
|
if (::ChainstateActive().IsInitialBlockDownload())
|
||||||
|
|
|
@ -39,10 +39,10 @@ static UniValue getconnectioncount(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if(!g_connman)
|
if(!g_rpc_node->connman)
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
|
||||||
return (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL);
|
return (int)g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue ping(const JSONRPCRequest& request)
|
static UniValue ping(const JSONRPCRequest& request)
|
||||||
|
@ -59,11 +59,11 @@ static UniValue ping(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if(!g_connman)
|
if(!g_rpc_node->connman)
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
|
||||||
// Request that each node send a ping during next message processing pass
|
// Request that each node send a ping during next message processing pass
|
||||||
g_connman->ForEachNode([](CNode* pnode) {
|
g_rpc_node->connman->ForEachNode([](CNode* pnode) {
|
||||||
pnode->fPingQueued = true;
|
pnode->fPingQueued = true;
|
||||||
});
|
});
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
|
@ -132,11 +132,11 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if(!g_connman)
|
if(!g_rpc_node->connman)
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
|
||||||
std::vector<CNodeStats> vstats;
|
std::vector<CNodeStats> vstats;
|
||||||
g_connman->GetNodeStats(vstats);
|
g_rpc_node->connman->GetNodeStats(vstats);
|
||||||
|
|
||||||
UniValue ret(UniValue::VARR);
|
UniValue ret(UniValue::VARR);
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ static UniValue addnode(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.ToString());
|
}.ToString());
|
||||||
|
|
||||||
if(!g_connman)
|
if(!g_rpc_node->connman)
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
|
||||||
std::string strNode = request.params[0].get_str();
|
std::string strNode = request.params[0].get_str();
|
||||||
|
@ -243,18 +243,18 @@ static UniValue addnode(const JSONRPCRequest& request)
|
||||||
if (strCommand == "onetry")
|
if (strCommand == "onetry")
|
||||||
{
|
{
|
||||||
CAddress addr;
|
CAddress addr;
|
||||||
g_connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, true);
|
g_rpc_node->connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, true);
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strCommand == "add")
|
if (strCommand == "add")
|
||||||
{
|
{
|
||||||
if(!g_connman->AddNode(strNode))
|
if(!g_rpc_node->connman->AddNode(strNode))
|
||||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
|
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
|
||||||
}
|
}
|
||||||
else if(strCommand == "remove")
|
else if(strCommand == "remove")
|
||||||
{
|
{
|
||||||
if(!g_connman->RemoveAddedNode(strNode))
|
if(!g_rpc_node->connman->RemoveAddedNode(strNode))
|
||||||
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
|
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ static UniValue disconnectnode(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if(!g_connman)
|
if(!g_rpc_node->connman)
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
|
||||||
bool success;
|
bool success;
|
||||||
|
@ -289,11 +289,11 @@ static UniValue disconnectnode(const JSONRPCRequest& request)
|
||||||
|
|
||||||
if (!address_arg.isNull() && id_arg.isNull()) {
|
if (!address_arg.isNull() && id_arg.isNull()) {
|
||||||
/* handle disconnect-by-address */
|
/* handle disconnect-by-address */
|
||||||
success = g_connman->DisconnectNode(address_arg.get_str());
|
success = g_rpc_node->connman->DisconnectNode(address_arg.get_str());
|
||||||
} else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) {
|
} else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) {
|
||||||
/* handle disconnect-by-id */
|
/* handle disconnect-by-id */
|
||||||
NodeId nodeid = (NodeId) id_arg.get_int64();
|
NodeId nodeid = (NodeId) id_arg.get_int64();
|
||||||
success = g_connman->DisconnectNode(nodeid);
|
success = g_rpc_node->connman->DisconnectNode(nodeid);
|
||||||
} else {
|
} else {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided.");
|
throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided.");
|
||||||
}
|
}
|
||||||
|
@ -334,10 +334,10 @@ static UniValue getaddednodeinfo(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if(!g_connman)
|
if(!g_rpc_node->connman)
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
|
||||||
std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo();
|
std::vector<AddedNodeInfo> vInfo = g_rpc_node->connman->GetAddedNodeInfo();
|
||||||
|
|
||||||
if (!request.params[0].isNull()) {
|
if (!request.params[0].isNull()) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
@ -400,21 +400,21 @@ static UniValue getnettotals(const JSONRPCRequest& request)
|
||||||
+ HelpExampleRpc("getnettotals", "")
|
+ HelpExampleRpc("getnettotals", "")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
if(!g_connman)
|
if(!g_rpc_node->connman)
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.pushKV("totalbytesrecv", g_connman->GetTotalBytesRecv());
|
obj.pushKV("totalbytesrecv", g_rpc_node->connman->GetTotalBytesRecv());
|
||||||
obj.pushKV("totalbytessent", g_connman->GetTotalBytesSent());
|
obj.pushKV("totalbytessent", g_rpc_node->connman->GetTotalBytesSent());
|
||||||
obj.pushKV("timemillis", GetTimeMillis());
|
obj.pushKV("timemillis", GetTimeMillis());
|
||||||
|
|
||||||
UniValue outboundLimit(UniValue::VOBJ);
|
UniValue outboundLimit(UniValue::VOBJ);
|
||||||
outboundLimit.pushKV("timeframe", g_connman->GetMaxOutboundTimeframe());
|
outboundLimit.pushKV("timeframe", g_rpc_node->connman->GetMaxOutboundTimeframe());
|
||||||
outboundLimit.pushKV("target", g_connman->GetMaxOutboundTarget());
|
outboundLimit.pushKV("target", g_rpc_node->connman->GetMaxOutboundTarget());
|
||||||
outboundLimit.pushKV("target_reached", g_connman->OutboundTargetReached(false));
|
outboundLimit.pushKV("target_reached", g_rpc_node->connman->OutboundTargetReached(false));
|
||||||
outboundLimit.pushKV("serve_historical_blocks", !g_connman->OutboundTargetReached(true));
|
outboundLimit.pushKV("serve_historical_blocks", !g_rpc_node->connman->OutboundTargetReached(true));
|
||||||
outboundLimit.pushKV("bytes_left_in_cycle", g_connman->GetOutboundTargetBytesLeft());
|
outboundLimit.pushKV("bytes_left_in_cycle", g_rpc_node->connman->GetOutboundTargetBytesLeft());
|
||||||
outboundLimit.pushKV("time_left_in_cycle", g_connman->GetMaxOutboundTimeLeftInCycle());
|
outboundLimit.pushKV("time_left_in_cycle", g_rpc_node->connman->GetMaxOutboundTimeLeftInCycle());
|
||||||
obj.pushKV("uploadtarget", outboundLimit);
|
obj.pushKV("uploadtarget", outboundLimit);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -493,16 +493,16 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
|
||||||
obj.pushKV("version", CLIENT_VERSION);
|
obj.pushKV("version", CLIENT_VERSION);
|
||||||
obj.pushKV("subversion", strSubVersion);
|
obj.pushKV("subversion", strSubVersion);
|
||||||
obj.pushKV("protocolversion",PROTOCOL_VERSION);
|
obj.pushKV("protocolversion",PROTOCOL_VERSION);
|
||||||
if (g_connman) {
|
if (g_rpc_node->connman) {
|
||||||
ServiceFlags services = g_connman->GetLocalServices();
|
ServiceFlags services = g_rpc_node->connman->GetLocalServices();
|
||||||
obj.pushKV("localservices", strprintf("%016x", services));
|
obj.pushKV("localservices", strprintf("%016x", services));
|
||||||
obj.pushKV("localservicesnames", GetServicesNames(services));
|
obj.pushKV("localservicesnames", GetServicesNames(services));
|
||||||
}
|
}
|
||||||
obj.pushKV("localrelay", g_relay_txes);
|
obj.pushKV("localrelay", g_relay_txes);
|
||||||
obj.pushKV("timeoffset", GetTimeOffset());
|
obj.pushKV("timeoffset", GetTimeOffset());
|
||||||
if (g_connman) {
|
if (g_rpc_node->connman) {
|
||||||
obj.pushKV("networkactive", g_connman->GetNetworkActive());
|
obj.pushKV("networkactive", g_rpc_node->connman->GetNetworkActive());
|
||||||
obj.pushKV("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL));
|
obj.pushKV("connections", (int)g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL));
|
||||||
}
|
}
|
||||||
obj.pushKV("networks", GetNetworksInfo());
|
obj.pushKV("networks", GetNetworksInfo());
|
||||||
obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()));
|
obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()));
|
||||||
|
@ -547,7 +547,7 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||||
if (request.fHelp || !help.IsValidNumArgs(request.params.size()) || (strCommand != "add" && strCommand != "remove")) {
|
if (request.fHelp || !help.IsValidNumArgs(request.params.size()) || (strCommand != "add" && strCommand != "remove")) {
|
||||||
throw std::runtime_error(help.ToString());
|
throw std::runtime_error(help.ToString());
|
||||||
}
|
}
|
||||||
if (!g_banman) {
|
if (!g_rpc_node->banman) {
|
||||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,7 +571,7 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||||
|
|
||||||
if (strCommand == "add")
|
if (strCommand == "add")
|
||||||
{
|
{
|
||||||
if (isSubnet ? g_banman->IsBanned(subNet) : g_banman->IsBanned(netAddr)) {
|
if (isSubnet ? g_rpc_node->banman->IsBanned(subNet) : g_rpc_node->banman->IsBanned(netAddr)) {
|
||||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
|
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,20 +584,20 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||||
absolute = true;
|
absolute = true;
|
||||||
|
|
||||||
if (isSubnet) {
|
if (isSubnet) {
|
||||||
g_banman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute);
|
g_rpc_node->banman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute);
|
||||||
if (g_connman) {
|
if (g_rpc_node->connman) {
|
||||||
g_connman->DisconnectNode(subNet);
|
g_rpc_node->connman->DisconnectNode(subNet);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g_banman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
|
g_rpc_node->banman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
|
||||||
if (g_connman) {
|
if (g_rpc_node->connman) {
|
||||||
g_connman->DisconnectNode(netAddr);
|
g_rpc_node->connman->DisconnectNode(netAddr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(strCommand == "remove")
|
else if(strCommand == "remove")
|
||||||
{
|
{
|
||||||
if (!( isSubnet ? g_banman->Unban(subNet) : g_banman->Unban(netAddr) )) {
|
if (!( isSubnet ? g_rpc_node->banman->Unban(subNet) : g_rpc_node->banman->Unban(netAddr) )) {
|
||||||
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously banned.");
|
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously banned.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -616,12 +616,12 @@ static UniValue listbanned(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if(!g_banman) {
|
if(!g_rpc_node->banman) {
|
||||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
banmap_t banMap;
|
banmap_t banMap;
|
||||||
g_banman->GetBanned(banMap);
|
g_rpc_node->banman->GetBanned(banMap);
|
||||||
|
|
||||||
UniValue bannedAddresses(UniValue::VARR);
|
UniValue bannedAddresses(UniValue::VARR);
|
||||||
for (const auto& entry : banMap)
|
for (const auto& entry : banMap)
|
||||||
|
@ -650,11 +650,11 @@ static UniValue clearbanned(const JSONRPCRequest& request)
|
||||||
+ HelpExampleRpc("clearbanned", "")
|
+ HelpExampleRpc("clearbanned", "")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
if (!g_banman) {
|
if (!g_rpc_node->banman) {
|
||||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_banman->ClearBanned();
|
g_rpc_node->banman->ClearBanned();
|
||||||
|
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
|
@ -670,13 +670,13 @@ static UniValue setnetworkactive(const JSONRPCRequest& request)
|
||||||
RPCExamples{""},
|
RPCExamples{""},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if (!g_connman) {
|
if (!g_rpc_node->connman) {
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_connman->SetNetworkActive(request.params[0].get_bool());
|
g_rpc_node->connman->SetNetworkActive(request.params[0].get_bool());
|
||||||
|
|
||||||
return g_connman->GetNetworkActive();
|
return g_rpc_node->connman->GetNetworkActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue getnodeaddresses(const JSONRPCRequest& request)
|
static UniValue getnodeaddresses(const JSONRPCRequest& request)
|
||||||
|
@ -702,7 +702,7 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request)
|
||||||
+ HelpExampleRpc("getnodeaddresses", "8")
|
+ HelpExampleRpc("getnodeaddresses", "8")
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
if (!g_connman) {
|
if (!g_rpc_node->connman) {
|
||||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,7 +714,7 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// returns a shuffled list of CAddress
|
// returns a shuffled list of CAddress
|
||||||
std::vector<CAddress> vAddr = g_connman->GetAddresses();
|
std::vector<CAddress> vAddr = g_rpc_node->connman->GetAddresses();
|
||||||
UniValue ret(UniValue::VARR);
|
UniValue ret(UniValue::VARR);
|
||||||
|
|
||||||
int address_return_count = std::min<int>(count, vAddr.size());
|
int address_return_count = std::min<int>(count, vAddr.size());
|
||||||
|
|
|
@ -104,8 +104,8 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
|
||||||
for (int i = 0; i < nScriptCheckThreads - 1; i++)
|
for (int i = 0; i < nScriptCheckThreads - 1; i++)
|
||||||
threadGroup.create_thread([i]() { return ThreadScriptCheck(i); });
|
threadGroup.create_thread([i]() { return ThreadScriptCheck(i); });
|
||||||
|
|
||||||
g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
m_node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
g_connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
|
m_node.connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
|
||||||
}
|
}
|
||||||
|
|
||||||
TestingSetup::~TestingSetup()
|
TestingSetup::~TestingSetup()
|
||||||
|
@ -114,8 +114,8 @@ TestingSetup::~TestingSetup()
|
||||||
threadGroup.join_all();
|
threadGroup.join_all();
|
||||||
GetMainSignals().FlushBackgroundCallbacks();
|
GetMainSignals().FlushBackgroundCallbacks();
|
||||||
GetMainSignals().UnregisterBackgroundSignalScheduler();
|
GetMainSignals().UnregisterBackgroundSignalScheduler();
|
||||||
g_connman.reset();
|
m_node.connman.reset();
|
||||||
g_banman.reset();
|
m_node.banman.reset();
|
||||||
UnloadBlockIndex();
|
UnloadBlockIndex();
|
||||||
g_chainstate.reset();
|
g_chainstate.reset();
|
||||||
pblocktree.reset();
|
pblocktree.reset();
|
||||||
|
|
Loading…
Add table
Reference in a new issue