Skip to content

Commit e65aff6

Browse files
[RPC] setnetworkactive
1 parent 68f4c47 commit e65aff6

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* Fix Boost 1.66 Compatibility
99
* Net Overhaul and BTC Inlining
1010
* Bump Versions/Protocol
11+
* Update Tests
12+
* util: Add ParseUInt32 and ParseUInt64
13+
* [RPC] getmempoolancestors/getmempooldescendants
14+
* [RPC] setnetworkactive
1115
* Update CHANGELOG
1216

1317
**Dynamic v2.2.0.0**

src/rpcclient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
128128
{ "setban", 3 },
129129
{ "getmempoolancestors", 1 },
130130
{ "getmempooldescendants", 1 },
131+
{ "setnetworkactive", 0 },
131132
{ "spork", 1 },
132133
{ "voteraw", 1 },
133134
{ "voteraw", 5 },

src/rpcnet.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,24 @@ UniValue clearbanned(const UniValue& params, bool fHelp)
577577
return NullUniValue;
578578
}
579579

580+
UniValue setnetworkactive(const UniValue& params, bool fHelp)
581+
{
582+
if (fHelp || params.size() != 1) {
583+
throw std::runtime_error(
584+
"setnetworkactive true|false\n"
585+
"Disable/enable all p2p network activity."
586+
);
587+
}
588+
589+
if (!g_connman) {
590+
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
591+
}
592+
593+
g_connman->SetNetworkActive(params[0].get_bool());
594+
595+
return g_connman->GetNetworkActive();
596+
}
597+
580598
UniValue ntptime(const UniValue& params, bool fHelp)
581599
{
582600
if (fHelp || params.size() > 1)
@@ -618,6 +636,7 @@ static const CRPCCommand commands[] =
618636
{ "network", "setban", &setban, true },
619637
{ "network", "listbanned", &listbanned, true },
620638
{ "network", "clearbanned", &clearbanned, true },
639+
{ "network", "setnetworkactive", &setnetworkactive, true, },
621640
};
622641

623642
void RegisterNetRPCCommands(CRPCTable &tableRPC)

src/test/rpc_tests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams)
9090
BOOST_CHECK_THROW(CallRPC(std::string("sendrawtransaction ")+rawtx+" extra"), std::runtime_error);
9191
}
9292

93+
BOOST_AUTO_TEST_CASE(rpc_togglenetwork)
94+
{
95+
UniValue r;
96+
97+
r = CallRPC("getnetworkinfo");
98+
bool netState = find_value(r.get_obj(), "networkactive").get_bool();
99+
BOOST_CHECK_EQUAL(netState, true);
100+
101+
BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive false"));
102+
r = CallRPC("getnetworkinfo");
103+
int numConnection = find_value(r.get_obj(), "connections").get_int();
104+
BOOST_CHECK_EQUAL(numConnection, 0);
105+
106+
netState = find_value(r.get_obj(), "networkactive").get_bool();
107+
BOOST_CHECK_EQUAL(netState, false);
108+
109+
BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive true"));
110+
r = CallRPC("getnetworkinfo");
111+
netState = find_value(r.get_obj(), "networkactive").get_bool();
112+
BOOST_CHECK_EQUAL(netState, true);
113+
}
114+
93115
BOOST_AUTO_TEST_CASE(rpc_rawsign)
94116
{
95117
UniValue r;

0 commit comments

Comments
 (0)