Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show All 24 Lines | |||||
#include <validation.h> | #include <validation.h> | ||||
#include <version.h> | #include <version.h> | ||||
#include <warnings.h> | #include <warnings.h> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
static UniValue getconnectioncount(const Config &config, | static UniValue getconnectioncount(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"getconnectioncount", | "getconnectioncount", | ||||
"\nReturns the number of connections to other nodes.\n", | "\nReturns the number of connections to other nodes.\n", | ||||
{}, | {}, | ||||
RPCResult{"n (numeric) The connection count\n"}, | RPCResult{"n (numeric) The connection count\n"}, | ||||
RPCExamples{HelpExampleCli("getconnectioncount", "") + | RPCExamples{HelpExampleCli("getconnectioncount", "") + | ||||
HelpExampleRpc("getconnectioncount", "")}, | HelpExampleRpc("getconnectioncount", "")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->connman) { | if (!g_rpc_node->connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
return int(g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL)); | return int(g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL)); | ||||
} | } | ||||
static UniValue ping(const Config &config, const JSONRPCRequest &request) { | static UniValue ping(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"ping", | "ping", | ||||
"\nRequests that a ping be sent to all other nodes, to measure " | "\nRequests that a ping be sent to all other nodes, to measure ping " | ||||
"ping time.\n" | "time.\n" | ||||
"Results provided in getpeerinfo, pingtime and pingwait fields " | "Results provided in getpeerinfo, pingtime and pingwait fields are " | ||||
"are decimal seconds.\n" | "decimal seconds.\n" | ||||
"Ping command is handled in queue with all other commands, so " | "Ping command is handled in queue with all other commands, so it " | ||||
"it measures processing backlog, not just network ping.\n", | "measures processing backlog, not just network ping.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("ping", "") + | RPCExamples{HelpExampleCli("ping", "") + HelpExampleRpc("ping", "")}, | ||||
HelpExampleRpc("ping", "")}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
.Check(request); | |||||
if (!g_rpc_node->connman) { | if (!g_rpc_node->connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or 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_rpc_node->connman->ForEachNode( | g_rpc_node->connman->ForEachNode( | ||||
[](CNode *pnode) { pnode->fPingQueued = true; }); | [](CNode *pnode) { pnode->fPingQueued = true; }); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue getpeerinfo(const Config &config, | static UniValue getpeerinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"getpeerinfo", | "getpeerinfo", | ||||
"\nReturns data about each connected network node as a json array " | "\nReturns data about each connected network node as a json array of " | ||||
"of objects.\n", | "objects.\n", | ||||
{}, | {}, | ||||
RPCResult{ | RPCResult{ | ||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
" \"id\": n, (numeric) Peer index\n" | " \"id\": n, (numeric) Peer index\n" | ||||
" \"addr\":\"host:port\", (string) The IP address and " | " \"addr\":\"host:port\", (string) The IP address and port " | ||||
"port of the peer\n" | "of the peer\n" | ||||
" \"addrbind\":\"ip:port\", (string) Bind address of the " | " \"addrbind\":\"ip:port\", (string) Bind address of the " | ||||
"connection to the peer\n" | "connection to the peer\n" | ||||
" \"addrlocal\":\"ip:port\", (string) Local address as " | " \"addrlocal\":\"ip:port\", (string) Local address as " | ||||
"reported by the peer\n" | "reported by the peer\n" | ||||
" \"services\":\"xxxxxxxxxxxxxxxx\", (string) The " | " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services " | ||||
"services offered\n" | "offered\n" | ||||
" \"relaytxes\":true|false, (boolean) Whether peer has " | " \"relaytxes\":true|false, (boolean) Whether peer has asked " | ||||
"asked us to relay transactions to it\n" | "us to relay transactions to it\n" | ||||
" \"lastsend\": ttt, (numeric) The time in " | " \"lastsend\": ttt, (numeric) The time in seconds " | ||||
"seconds since epoch (Jan 1 1970 GMT) of the last send\n" | "since epoch (Jan 1 1970 GMT) of the last send\n" | ||||
" \"lastrecv\": ttt, (numeric) The time in " | " \"lastrecv\": ttt, (numeric) The time in seconds " | ||||
"seconds since epoch (Jan 1 1970 GMT) of the last receive\n" | "since epoch (Jan 1 1970 GMT) of the last receive\n" | ||||
" \"bytessent\": n, (numeric) The total bytes " | " \"bytessent\": n, (numeric) The total bytes sent\n" | ||||
"sent\n" | |||||
" \"bytesrecv\": n, (numeric) The total bytes " | " \"bytesrecv\": n, (numeric) The total bytes " | ||||
"received\n" | "received\n" | ||||
" \"conntime\": ttt, (numeric) The connection " | " \"conntime\": ttt, (numeric) The connection time in " | ||||
"time in seconds since epoch (Jan 1 1970 GMT)\n" | "seconds since epoch (Jan 1 1970 GMT)\n" | ||||
" \"timeoffset\": ttt, (numeric) The time offset in " | " \"timeoffset\": ttt, (numeric) The time offset in " | ||||
"seconds\n" | "seconds\n" | ||||
" \"pingtime\": n, (numeric) ping time (if " | " \"pingtime\": n, (numeric) ping time (if " | ||||
"available)\n" | "available)\n" | ||||
" \"minping\": n, (numeric) minimum observed " | " \"minping\": n, (numeric) minimum observed ping " | ||||
"ping time (if any at all)\n" | "time (if any at all)\n" | ||||
" \"pingwait\": n, (numeric) ping wait (if " | " \"pingwait\": n, (numeric) ping wait (if " | ||||
"non-zero)\n" | "non-zero)\n" | ||||
" \"version\": v, (numeric) The peer version, " | " \"version\": v, (numeric) The peer version, such " | ||||
"such as 70001\n" | "as 70001\n" | ||||
" \"subver\": \"/Satoshi:0.8.5/\", (string) The string " | " \"subver\": \"/Satoshi:0.8.5/\", (string) The string " | ||||
"version\n" | "version\n" | ||||
" \"inbound\": true|false, (boolean) Inbound (true) or " | " \"inbound\": true|false, (boolean) Inbound (true) or " | ||||
"Outbound (false)\n" | "Outbound (false)\n" | ||||
" \"addnode\": true|false, (boolean) Whether connection " | " \"addnode\": true|false, (boolean) Whether connection was " | ||||
"was due to addnode/-connect or if it was an automatic/inbound " | "due to addnode/-connect or if it was an automatic/inbound " | ||||
"connection\n" | "connection\n" | ||||
" \"startingheight\": n, (numeric) The starting " | " \"startingheight\": n, (numeric) The starting height " | ||||
"height (block) of the peer\n" | "(block) of the peer\n" | ||||
" \"banscore\": n, (numeric) The ban score\n" | " \"banscore\": n, (numeric) The ban score\n" | ||||
" \"synced_headers\": n, (numeric) The last header we " | " \"synced_headers\": n, (numeric) The last header we " | ||||
"have in common with this peer\n" | "have in common with this peer\n" | ||||
" \"synced_blocks\": n, (numeric) The last block we " | " \"synced_blocks\": n, (numeric) The last block we have " | ||||
"have in common with this peer\n" | "in common with this peer\n" | ||||
" \"inflight\": [\n" | " \"inflight\": [\n" | ||||
" n, (numeric) The heights of " | " n, (numeric) The heights of blocks " | ||||
"blocks we're currently asking from this peer\n" | "we're currently asking from this peer\n" | ||||
" ...\n" | " ...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"whitelisted\": true|false, (boolean) Whether the peer " | " \"whitelisted\": true|false, (boolean) Whether the peer is " | ||||
"is whitelisted\n" | "whitelisted\n" | ||||
" \"minfeefilter\": n, (numeric) The minimum fee " | " \"minfeefilter\": n, (numeric) The minimum fee rate " | ||||
"rate for transactions this peer accepts\n" | "for transactions this peer accepts\n" | ||||
" \"bytessent_per_msg\": {\n" | " \"bytessent_per_msg\": {\n" | ||||
" \"msg\": n, (numeric) The total bytes " | " \"msg\": n, (numeric) The total bytes sent " | ||||
"sent aggregated by message type\n" | "aggregated by message type\n" | ||||
" When a message type is not " | " When a message type is not listed " | ||||
"listed in this json object, the bytes sent are 0.\n" | "in this json object, the bytes sent are 0.\n" | ||||
" Only known message types can " | " Only known message types can " | ||||
"appear as keys in the object.\n" | "appear as keys in the object.\n" | ||||
" ...\n" | " ...\n" | ||||
" },\n" | " },\n" | ||||
" \"bytesrecv_per_msg\": {\n" | " \"bytesrecv_per_msg\": {\n" | ||||
" \"msg\": n, (numeric) The total bytes " | " \"msg\": n, (numeric) The total bytes " | ||||
"received aggregated by message type\n" | "received aggregated by message type\n" | ||||
" When a message type is not " | " When a message type is not listed " | ||||
"listed in this json object, the bytes received are 0.\n" | "in this json object, the bytes received are 0.\n" | ||||
" Only known message types can " | " Only known message types can " | ||||
"appear as keys in the object and all bytes received of " | "appear as keys in the object and all bytes received of unknown " | ||||
"unknown message types are listed under '" + | "message types are listed under '" + | ||||
NET_MESSAGE_COMMAND_OTHER + | NET_MESSAGE_COMMAND_OTHER + | ||||
"'.\n" | "'.\n" | ||||
" ...\n" | " ...\n" | ||||
" }\n" | " }\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{HelpExampleCli("getpeerinfo", "") + | RPCExamples{HelpExampleCli("getpeerinfo", "") + | ||||
HelpExampleRpc("getpeerinfo", "")}, | HelpExampleRpc("getpeerinfo", "")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->connman) { | if (!g_rpc_node->connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
std::vector<CNodeStats> vstats; | std::vector<CNodeStats> vstats; | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | if ((strCommand == "add") && (!g_rpc_node->connman->AddNode(strNode))) { | ||||
"Error: Node has not been added."); | "Error: Node has not been added."); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue disconnectnode(const Config &config, | static UniValue disconnectnode(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() == 0 || | RPCHelpMan{ | ||||
request.params.size() >= 3) { | |||||
throw std::runtime_error(RPCHelpMan{ | |||||
"disconnectnode", | "disconnectnode", | ||||
"\nImmediately disconnects from the specified peer node.\n" | "\nImmediately disconnects from the specified peer node.\n" | ||||
"\nStrictly one out of 'address' and 'nodeid' can be provided " | "\nStrictly one out of 'address' and 'nodeid' can be provided to " | ||||
"to identify the node.\n" | "identify the node.\n" | ||||
"\nTo disconnect by nodeid, either set 'address' to the empty " | "\nTo disconnect by nodeid, either set 'address' to the empty string, " | ||||
"string, or call using the named 'nodeid' argument only.\n", | "or call using the named 'nodeid' argument only.\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, | {"address", RPCArg::Type::STR, | ||||
/* default */ "fallback to nodeid", | /* default */ "fallback to nodeid", | ||||
"The IP address/port of the node"}, | "The IP address/port of the node"}, | ||||
{"nodeid", RPCArg::Type::NUM, | {"nodeid", RPCArg::Type::NUM, | ||||
/* default */ "fallback to address", | /* default */ "fallback to address", | ||||
"The node ID (see getpeerinfo for node IDs)"}, | "The node ID (see getpeerinfo for node IDs)"}, | ||||
}, | }, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{ | RPCExamples{HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | ||||
HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | |||||
HelpExampleCli("disconnectnode", "\"\" 1") + | HelpExampleCli("disconnectnode", "\"\" 1") + | ||||
HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") + | HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") + | ||||
HelpExampleRpc("disconnectnode", "\"\", 1")}, | HelpExampleRpc("disconnectnode", "\"\", 1")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->connman) { | if (!g_rpc_node->connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
bool success; | bool success; | ||||
Show All 20 Lines | if (!success) { | ||||
"Node not found in connected nodes"); | "Node not found in connected nodes"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue getaddednodeinfo(const Config &config, | static UniValue getaddednodeinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 1) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"getaddednodeinfo", | "getaddednodeinfo", | ||||
"\nReturns information about the given added node, or " | "\nReturns information about the given added node, or all added nodes\n" | ||||
"all added nodes\n" | |||||
"(note that onetry addnodes are not listed here)\n", | "(note that onetry addnodes are not listed here)\n", | ||||
{ | { | ||||
{"node", RPCArg::Type::STR, /* default */ "all nodes", | {"node", RPCArg::Type::STR, /* default */ "all nodes", | ||||
"If provided, return information about this specific node, " | "If provided, return information about this specific node, " | ||||
"otherwise all nodes are returned."}, | "otherwise all nodes are returned."}, | ||||
}, | }, | ||||
RPCResult{ | RPCResult{ | ||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
" \"addednode\" : \"192.168.0.201\", (string) The node IP " | " \"addednode\" : \"192.168.0.201\", (string) The node IP " | ||||
"address or name (as provided to addnode)\n" | "address or name (as provided to addnode)\n" | ||||
" \"connected\" : true|false, (boolean) If " | " \"connected\" : true|false, (boolean) If connected\n" | ||||
"connected\n" | " \"addresses\" : [ (list of objects) Only " | ||||
" \"addresses\" : [ (list of objects) " | "when connected = true\n" | ||||
"Only when connected = true\n" | |||||
" {\n" | " {\n" | ||||
" \"address\" : \"192.168.0.201:8333\", (string) The " | " \"address\" : \"192.168.0.201:8333\", (string) The " | ||||
"bitcoin server IP and port we're connected to\n" | "bitcoin server IP and port we're connected to\n" | ||||
" \"connected\" : \"outbound\" (string) " | " \"connected\" : \"outbound\" (string) " | ||||
"connection, inbound or outbound\n" | "connection, inbound or outbound\n" | ||||
" }\n" | " }\n" | ||||
" ]\n" | " ]\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{ | RPCExamples{HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + | ||||
HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + | |||||
HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")}, | HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->connman) { | if (!g_rpc_node->connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
std::vector<AddedNodeInfo> vInfo = g_rpc_node->connman->GetAddedNodeInfo(); | std::vector<AddedNodeInfo> vInfo = g_rpc_node->connman->GetAddedNodeInfo(); | ||||
Show All 30 Lines | for (const AddedNodeInfo &info : vInfo) { | ||||
ret.push_back(obj); | ret.push_back(obj); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue getnettotals(const Config &config, | static UniValue getnettotals(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 0) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"getnettotals", | "getnettotals", | ||||
"\nReturns information about network traffic, including " | "\nReturns information about network traffic, including bytes in, " | ||||
"bytes in, bytes out,\n" | "bytes out,\n" | ||||
"and current time.\n", | "and current time.\n", | ||||
{}, | {}, | ||||
RPCResult{ | RPCResult{"{\n" | ||||
"{\n" | |||||
" \"totalbytesrecv\": n, (numeric) Total bytes received\n" | " \"totalbytesrecv\": n, (numeric) Total bytes received\n" | ||||
" \"totalbytessent\": n, (numeric) Total bytes sent\n" | " \"totalbytessent\": n, (numeric) Total bytes sent\n" | ||||
" \"timemillis\": t, (numeric) Current UNIX time in " | " \"timemillis\": t, (numeric) Current UNIX time in " | ||||
"milliseconds\n" | "milliseconds\n" | ||||
" \"uploadtarget\":\n" | " \"uploadtarget\":\n" | ||||
" {\n" | " {\n" | ||||
" \"timeframe\": n, (numeric) " | " \"timeframe\": n, (numeric) " | ||||
"Length of the measuring timeframe in seconds\n" | "Length of the measuring timeframe in seconds\n" | ||||
" \"target\": n, (numeric) " | " \"target\": n, (numeric) " | ||||
"Target in bytes\n" | "Target in bytes\n" | ||||
" \"target_reached\": true|false, (boolean) True " | " \"target_reached\": true|false, (boolean) " | ||||
"if target is reached\n" | "True if target is reached\n" | ||||
" \"serve_historical_blocks\": true|false, (boolean) True " | " \"serve_historical_blocks\": true|false, (boolean) " | ||||
"if serving historical blocks\n" | "True if serving historical blocks\n" | ||||
" \"bytes_left_in_cycle\": t, (numeric) Bytes " | " \"bytes_left_in_cycle\": t, (numeric) " | ||||
"left in current time cycle\n" | "Bytes left in current time cycle\n" | ||||
" \"time_left_in_cycle\": t (numeric) " | " \"time_left_in_cycle\": t (numeric) " | ||||
"Seconds left in current time cycle\n" | "Seconds left in current time cycle\n" | ||||
" }\n" | " }\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("getnettotals", "") + | RPCExamples{HelpExampleCli("getnettotals", "") + | ||||
HelpExampleRpc("getnettotals", "")}, | HelpExampleRpc("getnettotals", "")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->connman) { | if (!g_rpc_node->connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
Show All 35 Lines | for (int n = 0; n < NET_MAX; ++n) { | ||||
obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials); | obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials); | ||||
networks.push_back(obj); | networks.push_back(obj); | ||||
} | } | ||||
return networks; | return networks; | ||||
} | } | ||||
static UniValue getnetworkinfo(const Config &config, | static UniValue getnetworkinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"getnetworkinfo", | "getnetworkinfo", | ||||
"Returns an object containing various state info " | "Returns an object containing various state info regarding P2P " | ||||
"regarding P2P networking.\n", | "networking.\n", | ||||
{}, | {}, | ||||
RPCResult{"{\n" | RPCResult{"{\n" | ||||
" \"version\": xxxxx, (numeric) " | " \"version\": xxxxx, (numeric) the " | ||||
"the server version\n" | "server version\n" | ||||
" \"subversion\": \"/Satoshi:x.x.x/\", (string) the " | " \"subversion\": \"/Satoshi:x.x.x/\", (string) the " | ||||
"server subversion string\n" | "server subversion string\n" | ||||
" \"protocolversion\": xxxxx, (numeric) " | " \"protocolversion\": xxxxx, (numeric) the " | ||||
"the protocol version\n" | "protocol version\n" | ||||
" \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the " | " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the " | ||||
"services we offer to the network\n" | "services we offer to the network\n" | ||||
" \"localrelay\": true|false, (bool) true " | " \"localrelay\": true|false, (bool) true if " | ||||
"if transaction relay is requested from peers\n" | "transaction relay is requested from peers\n" | ||||
" \"timeoffset\": xxxxx, (numeric) " | " \"timeoffset\": xxxxx, (numeric) the " | ||||
"the time offset\n" | "time offset\n" | ||||
" \"connections\": xxxxx, (numeric) " | " \"connections\": xxxxx, (numeric) the " | ||||
"the number of connections\n" | "number of connections\n" | ||||
" \"networkactive\": true|false, (bool) " | " \"networkactive\": true|false, (bool) whether " | ||||
"whether p2p networking is enabled\n" | "p2p networking is enabled\n" | ||||
" \"networks\": [ (array) " | " \"networks\": [ (array) " | ||||
"information per network\n" | "information per network\n" | ||||
" {\n" | " {\n" | ||||
" \"name\": \"xxx\", (string) " | " \"name\": \"xxx\", (string) network " | ||||
"network (ipv4, ipv6 or onion)\n" | "(ipv4, ipv6 or onion)\n" | ||||
" \"limited\": true|false, (boolean) is " | " \"limited\": true|false, (boolean) is the " | ||||
"the network limited using -onlynet?\n" | "network limited using -onlynet?\n" | ||||
" \"reachable\": true|false, (boolean) is " | " \"reachable\": true|false, (boolean) is the " | ||||
"the network reachable?\n" | "network reachable?\n" | ||||
" \"proxy\": \"host:port\" (string) the " | " \"proxy\": \"host:port\" (string) the " | ||||
"proxy that is used for this network, or empty if none\n" | "proxy that is used for this network, or empty if none\n" | ||||
" \"proxy_randomize_credentials\": true|false, " | " \"proxy_randomize_credentials\": true|false, (string) " | ||||
"(string) Whether randomized credentials are used\n" | "Whether randomized credentials are used\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"relayfee\": x.xxxxxxxx, (numeric) " | " \"relayfee\": x.xxxxxxxx, (numeric) " | ||||
"minimum relay fee for transactions in " + | "minimum relay fee for transactions in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"/kB\n" | "/kB\n" | ||||
" \"excessutxocharge\": x.xxxxxxxx, (numeric) " | " \"excessutxocharge\": x.xxxxxxxx, (numeric) " | ||||
"minimum charge for excess utxos in " + | "minimum charge for excess utxos in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"localaddresses\": [ (array) list " | " \"localaddresses\": [ (array) list of " | ||||
"of local addresses\n" | "local addresses\n" | ||||
" {\n" | " {\n" | ||||
" \"address\": \"xxxx\", (string) " | " \"address\": \"xxxx\", (string) network " | ||||
"network address\n" | "address\n" | ||||
" \"port\": xxx, (numeric) " | " \"port\": xxx, (numeric) " | ||||
"network port\n" | "network port\n" | ||||
" \"score\": xxx (numeric) " | " \"score\": xxx (numeric) " | ||||
"relative score\n" | "relative score\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
" \"warnings\": \"...\" (string) any " | " \"warnings\": \"...\" (string) any " | ||||
"network and blockchain warnings\n" | "network and blockchain warnings\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("getnetworkinfo", "") + | RPCExamples{HelpExampleCli("getnetworkinfo", "") + | ||||
HelpExampleRpc("getnetworkinfo", "")}, | HelpExampleRpc("getnetworkinfo", "")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
LOCK(cs_main); | LOCK(cs_main); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("version", CLIENT_VERSION); | obj.pushKV("version", CLIENT_VERSION); | ||||
obj.pushKV("subversion", userAgent(config)); | obj.pushKV("subversion", userAgent(config)); | ||||
obj.pushKV("protocolversion", PROTOCOL_VERSION); | obj.pushKV("protocolversion", PROTOCOL_VERSION); | ||||
if (g_rpc_node->connman) { | if (g_rpc_node->connman) { | ||||
obj.pushKV("localservices", | obj.pushKV("localservices", | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | if (strCommand == "add") { | ||||
"was not previously manually banned."); | "was not previously manually banned."); | ||||
} | } | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue listbanned(const Config &config, | static UniValue listbanned(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"listbanned", | "listbanned", | ||||
"\nList all manually banned IPs/Subnets.\n", | "\nList all manually banned IPs/Subnets.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("listbanned", "") + | RPCExamples{HelpExampleCli("listbanned", "") + | ||||
HelpExampleRpc("listbanned", "")}, | HelpExampleRpc("listbanned", "")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->banman) { | if (!g_rpc_node->banman) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, | throw JSONRPCError(RPC_DATABASE_ERROR, | ||||
"Error: Ban database not loaded"); | "Error: Ban database not loaded"); | ||||
} | } | ||||
banmap_t banMap; | banmap_t banMap; | ||||
g_rpc_node->banman->GetBanned(banMap); | g_rpc_node->banman->GetBanned(banMap); | ||||
Show All 9 Lines | for (const auto &entry : banMap) { | ||||
bannedAddresses.push_back(rec); | bannedAddresses.push_back(rec); | ||||
} | } | ||||
return bannedAddresses; | return bannedAddresses; | ||||
} | } | ||||
static UniValue clearbanned(const Config &config, | static UniValue clearbanned(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"clearbanned", | "clearbanned", | ||||
"\nClear all banned IPs.\n", | "\nClear all banned IPs.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("clearbanned", "") + | RPCExamples{HelpExampleCli("clearbanned", "") + | ||||
HelpExampleRpc("clearbanned", "")}, | HelpExampleRpc("clearbanned", "")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->banman) { | if (!g_rpc_node->banman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
g_rpc_node->banman->ClearBanned(); | g_rpc_node->banman->ClearBanned(); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue setnetworkactive(const Config &config, | static UniValue setnetworkactive(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"setnetworkactive", | "setnetworkactive", | ||||
"\nDisable/enable all p2p network activity.\n", | "\nDisable/enable all p2p network activity.\n", | ||||
{ | { | ||||
{"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, | {"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, | ||||
"true to enable networking, false to disable"}, | "true to enable networking, false to disable"}, | ||||
}, | }, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{""}, | RPCExamples{""}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->connman) { | if (!g_rpc_node->connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
g_rpc_node->connman->SetNetworkActive(request.params[0].get_bool()); | g_rpc_node->connman->SetNetworkActive(request.params[0].get_bool()); | ||||
return g_rpc_node->connman->GetNetworkActive(); | return g_rpc_node->connman->GetNetworkActive(); | ||||
} | } | ||||
static UniValue getnodeaddresses(const Config &config, | static UniValue getnodeaddresses(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 1) { | RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"getnodeaddresses", | "getnodeaddresses", | ||||
"\nReturn known addresses which can potentially be used " | "\nReturn known addresses which can potentially be used to find new " | ||||
"to find new nodes in the network\n", | "nodes in the network\n", | ||||
{ | { | ||||
{"count", RPCArg::Type::NUM, /* default */ "1", | {"count", RPCArg::Type::NUM, /* default */ "1", | ||||
"How many addresses to return. Limited to the " | "How many addresses to return. Limited to the smaller of " + | ||||
"smaller of " + | |||||
std::to_string(ADDRMAN_GETADDR_MAX) + " or " + | std::to_string(ADDRMAN_GETADDR_MAX) + " or " + | ||||
std::to_string(ADDRMAN_GETADDR_MAX_PCT) + | std::to_string(ADDRMAN_GETADDR_MAX_PCT) + | ||||
"% of all known addresses."}, | "% of all known addresses."}, | ||||
}, | }, | ||||
RPCResult{"[\n" | RPCResult{ | ||||
"[\n" | |||||
" {\n" | " {\n" | ||||
" \"time\": ttt, (numeric) Timestamp " | " \"time\": ttt, (numeric) Timestamp in seconds " | ||||
"in seconds since epoch (Jan 1 1970 GMT) keeping track " | "since epoch (Jan 1 1970 GMT) keeping track of when the node was " | ||||
"of when the node was last seen\n" | "last seen\n" | ||||
" \"services\": n, (numeric) The " | " \"services\": n, (numeric) The services offered\n" | ||||
"services offered\n" | " \"address\": \"host\", (string) The address of the " | ||||
" \"address\": \"host\", (string) The " | "node\n" | ||||
"address of the node\n" | " \"port\": n (numeric) The port of the node\n" | ||||
" \"port\": n (numeric) The port of " | |||||
"the node\n" | |||||
" }\n" | " }\n" | ||||
" ,....\n" | " ,....\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{HelpExampleCli("getnodeaddresses", "8") + | RPCExamples{HelpExampleCli("getnodeaddresses", "8") + | ||||
HelpExampleRpc("getnodeaddresses", "8")}, | HelpExampleRpc("getnodeaddresses", "8")}, | ||||
} | } | ||||
.ToString()); | .Check(request); | ||||
} | |||||
if (!g_rpc_node->connman) { | if (!g_rpc_node->connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
int count = 1; | int count = 1; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |