Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show All 24 Lines | |||||
#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( | ||||
"getconnectioncount\n" | RPCHelpMan{"getconnectioncount", | ||||
"\nReturns the number of connections to other nodes.\n" | "\nReturns the number of connections to other nodes.\n", | ||||
{}} | |||||
.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) { | ||||
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( | ||||
"ping\n" | RPCHelpMan{ | ||||
"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 are " | "Results provided in getpeerinfo, pingtime and pingwait fields " | ||||
"decimal seconds.\n" | "are decimal seconds.\n" | ||||
"Ping command is handled in queue with all other commands, so it " | "Ping command is handled in queue with all other commands, so " | ||||
"measures processing backlog, not just network ping.\n" | "it measures processing backlog, not just network ping.\n", | ||||
"\nExamples:\n" + | {}} | ||||
HelpExampleCli("ping", "") + HelpExampleRpc("ping", "")); | .ToString() + | ||||
"\nExamples:\n" + HelpExampleCli("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( | ||||
"getpeerinfo\n" | RPCHelpMan{"getpeerinfo", | ||||
"\nReturns data about each connected network node as a json array " | "\nReturns data about each connected network node as a " | ||||
"of objects.\n" | "json array of objects.\n", | ||||
{}} | |||||
.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 152 Lines • ▼ Show 20 Lines | static UniValue addnode(const Config &config, const JSONRPCRequest &request) { | ||||
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( | ||||
"addnode \"node\" \"command\"\n" | RPCHelpMan{ | ||||
"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 DoS " | "Nodes added using addnode (or -connect) are protected from " | ||||
"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 " | "full nodes as other outbound peers are (though such peers " | ||||
"such peers will not be synced from).\n" | "will not be synced from).\n", | ||||
{ | |||||
{"node", RPCArg::Type::STR, false}, | |||||
{"command", RPCArg::Type::STR, false}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"node\" (string, required) The node (see getpeerinfo for " | "1. \"node\" (string, required) The node (see getpeerinfo for " | ||||
"nodes)\n" | "nodes)\n" | ||||
"2. \"command\" (string, required) 'add' to add a node to the " | "2. \"command\" (string, required) 'add' to add a node to the " | ||||
"list, 'remove' to remove a node from the list, 'onetry' to try a " | "list, 'remove' to remove a node from the list, 'onetry' to try a " | ||||
"connection to the node once\n" | "connection to the node once\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + | HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + | ||||
Show All 27 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( | ||||
"disconnectnode ( \"address\" nodeid )\n" | RPCHelpMan{ | ||||
"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 to " | "\nStrictly one out of 'address' and 'nodeid' can be provided " | ||||
"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, true}, | |||||
{"nodeid", RPCArg::Type::NUM, true}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"address\" (string, optional) The IP address/port of the " | "1. \"address\" (string, optional) The IP address/port of the " | ||||
"node\n" | "node\n" | ||||
"2. \"nodeid\" (number, optional) The node ID (see " | "2. \"nodeid\" (number, optional) The node ID (see " | ||||
"getpeerinfo for node IDs)\n" | "getpeerinfo for node IDs)\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | ||||
HelpExampleCli("disconnectnode", "\"\" 1") + | HelpExampleCli("disconnectnode", "\"\" 1") + | ||||
Show All 33 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( | ||||
"getaddednodeinfo ( \"node\" )\n" | RPCHelpMan{"getaddednodeinfo", | ||||
"\nReturns information about the given added node, or all added " | "\nReturns information about the given added node, or " | ||||
"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, true}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"node\" (string, optional) If provided, return information " | "1. \"node\" (string, optional) If provided, return information " | ||||
"about this specific node, otherwise all nodes are returned.\n" | "about this specific node, otherwise all nodes are returned.\n" | ||||
"\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" | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 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( | ||||
"getnettotals\n" | RPCHelpMan{"getnettotals", | ||||
"\nReturns information about network traffic, including bytes in, " | "\nReturns information about network traffic, including " | ||||
"bytes out,\n" | "bytes in, bytes out,\n" | ||||
"and current time.\n" | "and current time.\n", | ||||
{}} | |||||
.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 62 Lines • ▼ Show 20 Lines | static UniValue GetNetworksInfo() { | ||||
} | } | ||||
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( | ||||
"getnetworkinfo\n" | RPCHelpMan{"getnetworkinfo", | ||||
"Returns an object containing various state info regarding P2P " | "Returns an object containing various state info " | ||||
"networking.\n" | "regarding P2P networking.\n", | ||||
{}} | |||||
.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 92 Lines • ▼ Show 20 Lines | 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( | ||||
"setban \"subnet\" \"command\" ( bantime absolute )\n" | RPCHelpMan{"setban", | ||||
"\nAttempts to add or remove a IP/Subnet from the banned list.\n" | "\nAttempts to add or remove an IP/Subnet from the " | ||||
"banned list.\n", | |||||
{ | |||||
{"subnet", RPCArg::Type::STR, false}, | |||||
{"command", RPCArg::Type::STR, false}, | |||||
{"bantime", RPCArg::Type::NUM, true}, | |||||
{"absolute", RPCArg::Type::BOOL, true}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"subnet\" (string, required) The IP/Subnet (see " | "1. \"subnet\" (string, required) The IP/Subnet (see " | ||||
"getpeerinfo for nodes IP) with an optional netmask (default is " | "getpeerinfo for nodes IP) with an optional netmask (default is " | ||||
"/32 " | "/32 " | ||||
"= single IP)\n" | "= single IP)\n" | ||||
"2. \"command\" (string, required) 'add' to add an IP/Subnet " | "2. \"command\" (string, required) 'add' to add an IP/Subnet " | ||||
"to the list, 'remove' to remove an IP/Subnet from the list\n" | "to the list, 'remove' to remove an IP/Subnet from the list\n" | ||||
"3. \"bantime\" (numeric, optional) time in seconds how long " | "3. \"bantime\" (numeric, optional) time in seconds how long " | ||||
▲ Show 20 Lines • Show All 71 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("listbanned\n" | throw std::runtime_error( | ||||
"\nList all banned IPs/Subnets.\n" | RPCHelpMan{"listbanned", "\nList all banned IPs/Subnets.\n", {}} | ||||
"\nExamples:\n" + | .ToString() + | ||||
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"); | ||||
} | } | ||||
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("clearbanned\n" | throw std::runtime_error( | ||||
"\nClear all banned IPs.\n" | RPCHelpMan{"clearbanned", "\nClear all banned IPs.\n", {}} | ||||
"\nExamples:\n" + | .ToString() + | ||||
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( | throw std::runtime_error( | ||||
"setnetworkactive state\n" | RPCHelpMan{"setnetworkactive", | ||||
"\nDisable/enable all p2p network activity.\n" | "\nDisable/enable all p2p network activity.\n", | ||||
{ | |||||
{"state", RPCArg::Type::BOOL, false}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"state\" (boolean, required) true to " | "1. \"state\" (boolean, required) true to " | ||||
"enable networking, false to disable\n"); | "enable networking, false to disable\n"); | ||||
} | } | ||||
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( | ||||
"getnodeaddresses ( count )\n" | RPCHelpMan{"getnodeaddresses", | ||||
"\nReturn known addresses which can potentially be used to find " | "\nReturn known addresses which can potentially be used " | ||||
"new nodes in the network\n" | "to find new nodes in the network\n", | ||||
{ | |||||
{"count", RPCArg::Type::NUM, true}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"count\" (numeric, optional) How many addresses to return. " | "1. \"count\" (numeric, optional) How many addresses to return. " | ||||
"Limited to the smaller of " + | "Limited to the 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. (default = 1)\n" | "% of all known addresses. (default = 1)\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |