RPC: Add "togglenetwork" method to toggle network activity temporarily
RPC command "togglenetwork" toggles network and returns new state after command. RPC command "getinfo" returns "networkactive" field in output.
This commit is contained in:
parent
7c9a98aac8
commit
e38993bb36
3 changed files with 23 additions and 1 deletions
|
@ -131,6 +131,7 @@ public:
|
||||||
bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, std::string& strNodeError, Options options);
|
bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, std::string& strNodeError, Options options);
|
||||||
void Stop();
|
void Stop();
|
||||||
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
|
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
|
||||||
|
bool GetNetworkActive() const { return fNetworkActive; };
|
||||||
void SetNetworkActive(bool active);
|
void SetNetworkActive(bool active);
|
||||||
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
|
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
|
||||||
bool CheckIncomingNonce(uint64_t nonce);
|
bool CheckIncomingNonce(uint64_t nonce);
|
||||||
|
|
|
@ -89,8 +89,10 @@ UniValue getinfo(const UniValue& params, bool fHelp)
|
||||||
#endif
|
#endif
|
||||||
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
||||||
obj.push_back(Pair("timeoffset", GetTimeOffset()));
|
obj.push_back(Pair("timeoffset", GetTimeOffset()));
|
||||||
if(g_connman)
|
if (g_connman) {
|
||||||
|
obj.push_back(Pair("networkactive", g_connman->GetNetworkActive()));
|
||||||
obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
|
obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
|
||||||
|
}
|
||||||
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string())));
|
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string())));
|
||||||
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
|
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
|
||||||
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));
|
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));
|
||||||
|
|
|
@ -571,6 +571,24 @@ UniValue clearbanned(const UniValue& params, bool fHelp)
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue togglenetwork(const JSONRPCRequest& request)
|
||||||
|
{
|
||||||
|
if (request.fHelp || request.params.size() != 0) {
|
||||||
|
throw runtime_error(
|
||||||
|
"togglenetwork\n"
|
||||||
|
"Toggle all network activity temporarily."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_connman) {
|
||||||
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
g_connman->SetNetworkActive(!g_connman->GetNetworkActive());
|
||||||
|
|
||||||
|
return g_connman->GetNetworkActive();
|
||||||
|
}
|
||||||
|
|
||||||
static const CRPCCommand commands[] =
|
static const CRPCCommand commands[] =
|
||||||
{ // category name actor (function) okSafeMode
|
{ // category name actor (function) okSafeMode
|
||||||
// --------------------- ------------------------ ----------------------- ----------
|
// --------------------- ------------------------ ----------------------- ----------
|
||||||
|
@ -585,6 +603,7 @@ static const CRPCCommand commands[] =
|
||||||
{ "network", "setban", &setban, true },
|
{ "network", "setban", &setban, true },
|
||||||
{ "network", "listbanned", &listbanned, true },
|
{ "network", "listbanned", &listbanned, true },
|
||||||
{ "network", "clearbanned", &clearbanned, true },
|
{ "network", "clearbanned", &clearbanned, true },
|
||||||
|
{ "network", "togglenetwork", &togglenetwork, true, },
|
||||||
};
|
};
|
||||||
|
|
||||||
void RegisterNetRPCCommands(CRPCTable &t)
|
void RegisterNetRPCCommands(CRPCTable &t)
|
||||||
|
|
Loading…
Reference in a new issue