Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show All 27 Lines | |||||
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{"getconnectioncount", | RPCHelpMan{"getconnectioncount", | ||||
"\nReturns the number of connections to other nodes.\n", | "\nReturns the number of connections to other nodes.\n", | ||||
{}} | {}} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"n (numeric) The connection count\n" | "n (numeric) The connection count\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getconnectioncount", "") + | HelpExampleCli("getconnectioncount", "") + | ||||
HelpExampleRpc("getconnectioncount", "")); | HelpExampleRpc("getconnectioncount", "")); | ||||
} | } | ||||
if (!g_connman) { | if (!g_connman) { | ||||
Show All 12 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
"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", | ||||
{}} | {}} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nExamples:\n" + HelpExampleCli("ping", "") + | "\nExamples:\n" + HelpExampleCli("ping", "") + | ||||
HelpExampleRpc("ping", "")); | HelpExampleRpc("ping", "")); | ||||
} | } | ||||
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{"getpeerinfo", | RPCHelpMan{"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", | ||||
{}} | {}} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nResult:\n" | "\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" | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 2 || | ||||
/* 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"}, | ||||
}} | }} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
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\"")); | ||||
} | } | ||||
if (!g_connman) { | if (!g_connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
Show All 35 Lines | if (request.fHelp || request.params.size() == 0 || | ||||
"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)"}, | ||||
}} | }} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
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")); | ||||
} | } | ||||
if (!g_connman) { | if (!g_connman) { | ||||
Show All 38 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
"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."}, | ||||
}} | }} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nResult:\n" | "\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 connected\n" | ||||
" \"addresses\" : [ (list of objects) Only " | " \"addresses\" : [ (list of objects) Only " | ||||
"when connected = true\n" | "when connected = true\n" | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | 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{"getnettotals", | RPCHelpMan{"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", | ||||
{}} | {}} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nResult:\n" | "\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" | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
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{"getnetworkinfo", | RPCHelpMan{"getnetworkinfo", | ||||
"Returns an object containing various state info " | "Returns an object containing various state info " | ||||
"regarding P2P networking.\n", | "regarding P2P networking.\n", | ||||
{}} | {}} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nResult:\n" | "\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" | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
"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)"}, | ||||
}} | }} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
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")); | ||||
} | } | ||||
if (!g_banman) { | if (!g_banman) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, | throw JSONRPCError(RPC_DATABASE_ERROR, | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | static UniValue setban(const Config &config, const JSONRPCRequest &request) { | ||||
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{"listbanned", "\nList all banned IPs/Subnets.\n", {}} | RPCHelpMan{"listbanned", "\nList all banned IPs/Subnets.\n", {}} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nExamples:\n" + HelpExampleCli("listbanned", "") + | "\nExamples:\n" + HelpExampleCli("listbanned", "") + | ||||
HelpExampleRpc("listbanned", "")); | HelpExampleRpc("listbanned", "")); | ||||
} | } | ||||
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"); | ||||
} | } | ||||
Show All 16 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{"clearbanned", "\nClear all banned IPs.\n", {}} | RPCHelpMan{"clearbanned", "\nClear all banned IPs.\n", {}} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nExamples:\n" + HelpExampleCli("clearbanned", "") + | "\nExamples:\n" + HelpExampleCli("clearbanned", "") + | ||||
HelpExampleRpc("clearbanned", "")); | HelpExampleRpc("clearbanned", "")); | ||||
} | } | ||||
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"}, | ||||
}}.ToStringWithArgs()); | }}.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 13 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
{"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."}, | ||||
}} | }} | ||||
.ToStringWithArgs() + | .ToString() + | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
" \"time\": ttt, (numeric) Timestamp in seconds " | " \"time\": ttt, (numeric) Timestamp in seconds " | ||||
"since epoch (Jan 1 1970 GMT) keeping track of when the node was " | "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 services offered\n" | ||||
" \"address\": \"host\", (string) The address of the " | " \"address\": \"host\", (string) The address of the " | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |