Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show All 23 Lines | |||||
#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) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getconnectioncount", | "getconnectioncount", | ||||
"\nReturns the number of connections to other nodes.\n", | "\nReturns the number of connections to other nodes.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"n (numeric) The connection count\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("getconnectioncount", "") + | ||||
"n (numeric) The connection count\n" | HelpExampleRpc("getconnectioncount", "")}, | ||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("getconnectioncount", "") + | .ToString()); | ||||
HelpExampleRpc("getconnectioncount", "")); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)); | return int(g_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) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
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 time.\n" | "ping time.\n" | ||||
"Results provided in getpeerinfo, pingtime and pingwait fields " | "Results provided in getpeerinfo, pingtime and pingwait fields " | ||||
"are decimal seconds.\n" | "are 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 measures processing backlog, not just network ping.\n", | "it measures processing backlog, not just network ping.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + HelpExampleCli("ping", "") + | RPCExamples{HelpExampleCli("ping", "") + | ||||
HelpExampleRpc("ping", "")); | HelpExampleRpc("ping", "")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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_connman->ForEachNode([](CNode *pnode) { pnode->fPingQueued = true; }); | g_connman->ForEachNode([](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) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getpeerinfo", | "getpeerinfo", | ||||
"\nReturns data about each connected network node as a " | "\nReturns data about each connected network node as a " | ||||
"json array of objects.\n", | "json array of objects.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
" \"id\": n, (numeric) Peer index\n" | " \"id\": n, (numeric) Peer index\n" | ||||
" \"addr\":\"host:port\", (string) The IP address and port " | " \"addr\":\"host:port\", (string) The IP address and " | ||||
"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 " | " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The " | ||||
"services " | |||||
"offered\n" | "offered\n" | ||||
" \"relaytxes\":true|false, (boolean) Whether peer has asked " | " \"relaytxes\":true|false, (boolean) Whether peer has " | ||||
"asked " | |||||
"us to relay transactions to it\n" | "us to relay transactions to it\n" | ||||
" \"lastsend\": ttt, (numeric) The time in seconds " | " \"lastsend\": ttt, (numeric) The time in " | ||||
"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 seconds " | " \"lastrecv\": ttt, (numeric) The time in " | ||||
"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 sent\n" | " \"bytessent\": n, (numeric) The total bytes " | ||||
"sent\n" | |||||
" \"bytesrecv\": n, (numeric) The total bytes " | " \"bytesrecv\": n, (numeric) The total bytes " | ||||
"received\n" | "received\n" | ||||
" \"conntime\": ttt, (numeric) The connection time in " | " \"conntime\": ttt, (numeric) The connection " | ||||
"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 ping " | " \"minping\": n, (numeric) minimum observed " | ||||
"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, such " | " \"version\": v, (numeric) The peer version, " | ||||
"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 was " | " \"addnode\": true|false, (boolean) Whether connection " | ||||
"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 height " | " \"startingheight\": n, (numeric) The starting " | ||||
"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 have " | " \"synced_blocks\": n, (numeric) The last block we " | ||||
"have " | |||||
"in common with this peer\n" | "in common with this peer\n" | ||||
" \"inflight\": [\n" | " \"inflight\": [\n" | ||||
" n, (numeric) The heights of blocks " | " n, (numeric) The heights of " | ||||
"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 is " | " \"whitelisted\": true|false, (boolean) Whether the peer " | ||||
"is " | |||||
"whitelisted\n" | "whitelisted\n" | ||||
" \"minfeefilter\": n, (numeric) The minimum fee rate " | " \"minfeefilter\": n, (numeric) The minimum fee " | ||||
"rate " | |||||
"for transactions this peer accepts\n" | "for transactions this peer accepts\n" | ||||
" \"bytessent_per_msg\": {\n" | " \"bytessent_per_msg\": {\n" | ||||
" \"addr\": n, (numeric) The total bytes sent " | " \"addr\": n, (numeric) The total bytes " | ||||
"sent " | |||||
"aggregated by message type\n" | "aggregated by message type\n" | ||||
" ...\n" | " ...\n" | ||||
" },\n" | " },\n" | ||||
" \"bytesrecv_per_msg\": {\n" | " \"bytesrecv_per_msg\": {\n" | ||||
" \"addr\": n, (numeric) The total bytes " | " \"addr\": n, (numeric) The total bytes " | ||||
"received aggregated by message type\n" | "received aggregated by message type\n" | ||||
" ...\n" | " ...\n" | ||||
" }\n" | " }\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("getpeerinfo", "") + | ||||
HelpExampleCli("getpeerinfo", "") + | HelpExampleRpc("getpeerinfo", "")}, | ||||
HelpExampleRpc("getpeerinfo", "")); | } | ||||
.ToString()); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | static UniValue addnode(const Config &config, const JSONRPCRequest &request) { | ||||
std::string strCommand; | std::string strCommand; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
strCommand = request.params[1].get_str(); | strCommand = request.params[1].get_str(); | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 2 || | if (request.fHelp || request.params.size() != 2 || | ||||
(strCommand != "onetry" && strCommand != "add" && | (strCommand != "onetry" && strCommand != "add" && | ||||
strCommand != "remove")) { | strCommand != "remove")) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"addnode", | "addnode", | ||||
"\nAttempts to add or remove a node from the addnode list.\n" | "\nAttempts to add or remove a node from the addnode list.\n" | ||||
"Or try a connection to a node once.\n" | "Or try a connection to a node once.\n" | ||||
"Nodes added using addnode (or -connect) are protected from " | "Nodes added using addnode (or -connect) are protected from " | ||||
"DoS disconnection and are not required to be\n" | "DoS disconnection and are not required to be\n" | ||||
"full nodes as other outbound peers are (though such peers " | "full nodes as other outbound peers are (though such peers " | ||||
"will not be synced from).\n", | "will not be synced from).\n", | ||||
{ | { | ||||
{"node", RPCArg::Type::STR, /* opt */ false, | {"node", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", "The node (see getpeerinfo for nodes)"}, | ||||
"The node (see getpeerinfo for nodes)"}, | |||||
{"command", RPCArg::Type::STR, /* opt */ false, | {"command", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"'add' to add a node to the list, 'remove' to remove a " | "'add' to add a node to the list, 'remove' to remove a " | ||||
"node from the list, 'onetry' to try a connection to the " | "node from the list, 'onetry' to try a connection to the " | ||||
"node once"}, | "node once"}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + | RPCExamples{ | ||||
HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + | HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + | ||||
HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")); | HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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"); | ||||
} | } | ||||
Show All 17 Lines | static UniValue addnode(const Config &config, const JSONRPCRequest &request) { | ||||
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 || | if (request.fHelp || request.params.size() == 0 || | ||||
request.params.size() >= 3) { | request.params.size() >= 3) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
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 identify the node.\n" | "to 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, or call using the named 'nodeid' argument only.\n", | "string, or call using the named 'nodeid' argument only.\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, /* opt */ true, | {"address", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", "The IP address/port of the node"}, | /* default_val */ "", "The IP address/port of the node"}, | ||||
{"nodeid", RPCArg::Type::NUM, /* opt */ true, | {"nodeid", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The node ID (see getpeerinfo for node IDs)"}, | "The node ID (see getpeerinfo for node IDs)"}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + | 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()); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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"); | ||||
} | } | ||||
Show All 22 Lines | static UniValue disconnectnode(const Config &config, | ||||
} | } | ||||
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) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
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, /* opt */ true, | {"node", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"If provided, return information about this " | "If provided, return information about this " | ||||
"specific node, otherwise all nodes are returned."}, | "specific node, otherwise all nodes are returned."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"[\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\n" | " \"connected\" : true|false, (boolean) If " | ||||
" \"addresses\" : [ (list of objects) Only " | "connected\n" | ||||
" \"addresses\" : [ (list of objects) " | |||||
"Only " | |||||
"when connected = true\n" | "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"}, | ||||
"\nExamples:\n" + | 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()); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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"); | ||||
} | } | ||||
Show All 32 Lines | static UniValue getaddednodeinfo(const Config &config, | ||||
} | } | ||||
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) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getnettotals", | "getnettotals", | ||||
"\nReturns information about network traffic, including " | "\nReturns information about network traffic, including " | ||||
"bytes in, bytes out,\n" | "bytes in, bytes out,\n" | ||||
"and current time.\n", | "and current time.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\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) Length of " | " \"timeframe\": n, (numeric) " | ||||
"Length of " | |||||
"the measuring timeframe in seconds\n" | "the measuring timeframe in seconds\n" | ||||
" \"target\": n, (numeric) Target in " | " \"target\": n, (numeric) " | ||||
"Target in " | |||||
"bytes\n" | "bytes\n" | ||||
" \"target_reached\": true|false, (boolean) True if " | " \"target_reached\": true|false, (boolean) True " | ||||
"if " | |||||
"target is reached\n" | "target is reached\n" | ||||
" \"serve_historical_blocks\": true|false, (boolean) True if " | " \"serve_historical_blocks\": true|false, (boolean) True " | ||||
"if " | |||||
"serving historical blocks\n" | "serving historical blocks\n" | ||||
" \"bytes_left_in_cycle\": t, (numeric) Bytes " | " \"bytes_left_in_cycle\": t, (numeric) Bytes " | ||||
"left in current time cycle\n" | "left in current time cycle\n" | ||||
" \"time_left_in_cycle\": t (numeric) Seconds " | " \"time_left_in_cycle\": t (numeric) " | ||||
"Seconds " | |||||
"left in current time cycle\n" | "left in current time cycle\n" | ||||
" }\n" | " }\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("getnettotals", "") + | ||||
HelpExampleCli("getnettotals", "") + | HelpExampleRpc("getnettotals", "")}, | ||||
HelpExampleRpc("getnettotals", "")); | } | ||||
.ToString()); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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"); | ||||
} | } | ||||
Show All 36 Lines | for (int n = 0; n < NET_MAX; ++n) { | ||||
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) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getnetworkinfo", | "getnetworkinfo", | ||||
"Returns an object containing various state info " | "Returns an object containing various state info " | ||||
"regarding P2P networking.\n", | "regarding P2P networking.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"version\": xxxxx, (numeric) the server " | " \"version\": xxxxx, (numeric) the " | ||||
"server " | |||||
"version\n" | "version\n" | ||||
" \"subversion\": \"/Satoshi:x.x.x/\", (string) the server " | " \"subversion\": \"/Satoshi:x.x.x/\", (string) the " | ||||
"server " | |||||
"subversion string\n" | "subversion string\n" | ||||
" \"protocolversion\": xxxxx, (numeric) the protocol " | " \"protocolversion\": xxxxx, (numeric) the " | ||||
"protocol " | |||||
"version\n" | "version\n" | ||||
" \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services " | " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the " | ||||
"services " | |||||
"we offer to the network\n" | "we offer to the network\n" | ||||
" \"localrelay\": true|false, (bool) true if " | " \"localrelay\": true|false, (bool) true if " | ||||
"transaction relay is requested from peers\n" | "transaction relay is requested from peers\n" | ||||
" \"timeoffset\": xxxxx, (numeric) the time " | " \"timeoffset\": xxxxx, (numeric) the time " | ||||
"offset\n" | "offset\n" | ||||
" \"connections\": xxxxx, (numeric) the number " | " \"connections\": xxxxx, (numeric) the " | ||||
"number " | |||||
"of connections\n" | "of connections\n" | ||||
" \"networkactive\": true|false, (bool) whether p2p " | " \"networkactive\": true|false, (bool) whether p2p " | ||||
"networking is enabled\n" | "networking is enabled\n" | ||||
" \"networks\": [ (array) information " | " \"networks\": [ (array) " | ||||
"information " | |||||
"per network\n" | "per network\n" | ||||
" {\n" | " {\n" | ||||
" \"name\": \"xxx\", (string) network " | " \"name\": \"xxx\", (string) network " | ||||
"(ipv4, ipv6 or onion)\n" | "(ipv4, ipv6 or onion)\n" | ||||
" \"limited\": true|false, (boolean) is the " | " \"limited\": true|false, (boolean) is the " | ||||
"network limited using -onlynet?\n" | "network limited using -onlynet?\n" | ||||
" \"reachable\": true|false, (boolean) is the " | " \"reachable\": true|false, (boolean) is the " | ||||
"network reachable?\n" | "network reachable?\n" | ||||
" \"proxy\": \"host:port\" (string) the proxy " | " \"proxy\": \"host:port\" (string) the proxy " | ||||
"that is used for this network, or empty if none\n" | "that is used for this network, or empty if none\n" | ||||
" \"proxy_randomize_credentials\": true|false, (string) " | " \"proxy_randomize_credentials\": true|false, (string) " | ||||
"Whether randomized credentials are used\n" | "Whether randomized credentials are used\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"relayfee\": x.xxxxxxxx, (numeric) minimum " | " \"relayfee\": x.xxxxxxxx, (numeric) minimum " | ||||
"relay fee for transactions in " + | "relay fee for transactions in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"/kB\n" | "/kB\n" | ||||
" \"excessutxocharge\": x.xxxxxxxx, (numeric) minimum " | " \"excessutxocharge\": x.xxxxxxxx, (numeric) minimum " | ||||
"charge for excess utxos in " + | "charge for excess utxos in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"localaddresses\": [ " | " \"localaddresses\": [ " | ||||
"(array) list of local addresses\n" | "(array) list of local addresses\n" | ||||
" {\n" | " {\n" | ||||
" \"address\": \"xxxx\", " | " \"address\": \"xxxx\", " | ||||
"(string) network address\n" | "(string) network address\n" | ||||
" \"port\": xxx, " | " \"port\": xxx, " | ||||
"(numeric) network port\n" | "(numeric) network port\n" | ||||
" \"score\": xxx " | " \"score\": xxx " | ||||
"(numeric) relative score\n" | "(numeric) relative score\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
" \"warnings\": \"...\" (string) any network " | " \"warnings\": \"...\" (string) any " | ||||
"network " | |||||
"and blockchain warnings\n" | "and blockchain warnings\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("getnetworkinfo", "") + | ||||
HelpExampleCli("getnetworkinfo", "") + | HelpExampleRpc("getnetworkinfo", "")}, | ||||
HelpExampleRpc("getnetworkinfo", "")); | } | ||||
.ToString()); | |||||
} | } | ||||
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_connman) { | if (g_connman) { | ||||
Show All 31 Lines | |||||
static UniValue setban(const Config &config, const JSONRPCRequest &request) { | static UniValue setban(const Config &config, const JSONRPCRequest &request) { | ||||
std::string strCommand; | std::string strCommand; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
strCommand = request.params[1].get_str(); | strCommand = request.params[1].get_str(); | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
(strCommand != "add" && strCommand != "remove")) { | (strCommand != "add" && strCommand != "remove")) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"setban", | "setban", | ||||
"\nAttempts to add or remove an IP/Subnet from the " | "\nAttempts to add or remove an IP/Subnet from the " | ||||
"banned list.\n", | "banned list.\n", | ||||
{ | { | ||||
{"subnet", RPCArg::Type::STR, /* opt */ false, | {"subnet", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The IP/Subnet (see getpeerinfo for nodes IP) with an " | "The IP/Subnet (see getpeerinfo for nodes IP) with an " | ||||
"optional netmask (default is /32 = single IP)"}, | "optional netmask (default is /32 = single IP)"}, | ||||
{"command", RPCArg::Type::STR, /* opt */ false, | {"command", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"'add' to add an IP/Subnet to the list, 'remove' to " | "'add' to add an IP/Subnet to the list, 'remove' to " | ||||
"remove an IP/Subnet from the list"}, | "remove an IP/Subnet from the list"}, | ||||
{"bantime", RPCArg::Type::NUM, /* opt */ true, | {"bantime", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"time in seconds how long (or until when if [absolute] is " | "time in seconds how long (or until when if [absolute] is " | ||||
"set) the IP is banned (0 or empty means using the " | "set) the IP is banned (0 or empty means using the " | ||||
"default time of 24h which can also be overwritten by the " | "default time of 24h which can also be overwritten by the " | ||||
"-bantime startup argument)"}, | "-bantime startup argument)"}, | ||||
{"absolute", RPCArg::Type::BOOL, /* opt */ true, | {"absolute", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"If set, the bantime must be an absolute timestamp in " | "If set, the bantime must be an absolute timestamp in " | ||||
"seconds since epoch (Jan 1 1970 GMT)"}, | "seconds since epoch (Jan 1 1970 GMT)"}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + | RPCExamples{ | ||||
HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") + | HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") + | ||||
HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") + | HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") + | ||||
HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")); | HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (!g_banman) { | if (!g_banman) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, | throw JSONRPCError(RPC_DATABASE_ERROR, | ||||
"Error: Ban database not loaded"); | "Error: Ban database not loaded"); | ||||
} | } | ||||
CSubNet subNet; | CSubNet subNet; | ||||
CNetAddr netAddr; | CNetAddr netAddr; | ||||
bool isSubnet = false; | bool isSubnet = false; | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | if (strCommand == "add") { | ||||
} | } | ||||
} | } | ||||
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) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"listbanned", "\nList all banned IPs/Subnets.\n", {}} | "listbanned", | ||||
.ToString() + | "\nList all banned IPs/Subnets.\n", | ||||
"\nExamples:\n" + HelpExampleCli("listbanned", "") + | {}, | ||||
HelpExampleRpc("listbanned", "")); | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("listbanned", "") + | |||||
HelpExampleRpc("listbanned", "")}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (!g_banman) { | if (!g_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; | ||||
Show All 12 Lines | static UniValue listbanned(const Config &config, | ||||
} | } | ||||
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) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"clearbanned", "\nClear all banned IPs.\n", {}} | "clearbanned", | ||||
.ToString() + | "\nClear all banned IPs.\n", | ||||
"\nExamples:\n" + HelpExampleCli("clearbanned", "") + | {}, | ||||
HelpExampleRpc("clearbanned", "")); | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("clearbanned", "") + | |||||
HelpExampleRpc("clearbanned", "")}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (!g_banman) { | if (!g_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_banman->ClearBanned(); | g_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) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error(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, /* opt */ false, | {"state", RPCArg::Type::BOOL, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"true to enable networking, false to disable"}, | "true to enable networking, false to disable"}, | ||||
}}.ToString()); | }, | ||||
RPCResults{}, | |||||
RPCExamples{""}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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_connman->SetNetworkActive(request.params[0].get_bool()); | g_connman->SetNetworkActive(request.params[0].get_bool()); | ||||
return g_connman->GetNetworkActive(); | return g_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) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getnodeaddresses", | "getnodeaddresses", | ||||
"\nReturn known addresses which can potentially be used " | "\nReturn known addresses which can potentially be used " | ||||
"to find new nodes in the network\n", | "to find new nodes in the network\n", | ||||
{ | { | ||||
{"count", RPCArg::Type::NUM, /* opt */ true, | {"count", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "1", | /* default_val */ "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."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"[\n" | ||||
"\nResult:\n" | |||||
"[\n" | |||||
" {\n" | " {\n" | ||||
" \"time\": ttt, (numeric) Timestamp in seconds " | " \"time\": ttt, (numeric) Timestamp " | ||||
"since epoch (Jan 1 1970 GMT) keeping track of when the node was " | "in seconds " | ||||
"since epoch (Jan 1 1970 GMT) keeping track of when the " | |||||
"node was " | |||||
"last seen\n" | "last seen\n" | ||||
" \"services\": n, (numeric) The services offered\n" | " \"services\": n, (numeric) The " | ||||
" \"address\": \"host\", (string) The address of the " | "services offered\n" | ||||
" \"address\": \"host\", (string) The " | |||||
"address of the " | |||||
"node\n" | "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"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("getnodeaddresses", "8") + | ||||
HelpExampleCli("getnodeaddresses", "8") + | HelpExampleRpc("getnodeaddresses", "8")}, | ||||
HelpExampleRpc("getnodeaddresses", "8")); | } | ||||
.ToString()); | |||||
} | } | ||||
if (!g_connman) { | if (!g_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; | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |