Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show First 20 Lines • Show All 258 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 2 || | ||||
"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, false}, | {"node", RPCArg::Type::STR, /* opt */ false, | ||||
{"command", RPCArg::Type::STR, false}, | /* default_val */ "", | ||||
"The node (see getpeerinfo for nodes)"}, | |||||
{"command", RPCArg::Type::STR, /* opt */ false, | |||||
/* default_val */ "", | |||||
"'add' to add a node to the list, 'remove' to remove a " | |||||
"node from the list, 'onetry' to try a connection to the " | |||||
"node once"}, | |||||
}} | }} | ||||
.ToString() + | .ToString() + | ||||
"\nArguments:\n" | |||||
"1. \"node\" (string, required) The node (see getpeerinfo for " | |||||
"nodes)\n" | |||||
"2. \"command\" (string, required) 'add' to add a node to the " | |||||
"list, 'remove' to remove a node from the list, 'onetry' to try a " | |||||
"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\"") + | ||||
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 29 Lines | if (request.fHelp || request.params.size() == 0 || | ||||
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, true}, | {"address", RPCArg::Type::STR, /* opt */ true, | ||||
{"nodeid", RPCArg::Type::NUM, true}, | /* default_val */ "", "The IP address/port of the node"}, | ||||
{"nodeid", RPCArg::Type::NUM, /* opt */ true, | |||||
/* default_val */ "", | |||||
"The node ID (see getpeerinfo for node IDs)"}, | |||||
}} | }} | ||||
.ToString() + | .ToString() + | ||||
"\nArguments:\n" | |||||
"1. \"address\" (string, optional) The IP address/port of the " | |||||
"node\n" | |||||
"2. \"nodeid\" (number, optional) The node ID (see " | |||||
"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") + | ||||
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 33 Lines | 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{"getaddednodeinfo", | RPCHelpMan{"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, true}, | {"node", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | |||||
"If provided, return information about this " | |||||
"specific node, otherwise all nodes are returned."}, | |||||
}} | }} | ||||
.ToString() + | .ToString() + | ||||
"\nArguments:\n" | |||||
"1. \"node\" (string, optional) If provided, return information " | |||||
"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" | ||||
" \"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 251 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( | ||||
RPCHelpMan{"setban", | RPCHelpMan{ | ||||
"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, false}, | {"subnet", RPCArg::Type::STR, /* opt */ false, | ||||
{"command", RPCArg::Type::STR, false}, | /* default_val */ "", | ||||
{"bantime", RPCArg::Type::NUM, true}, | "The IP/Subnet (see getpeerinfo for nodes IP) with an " | ||||
{"absolute", RPCArg::Type::BOOL, true}, | "optional netmask (default is /32 = single IP)"}, | ||||
{"command", RPCArg::Type::STR, /* opt */ false, | |||||
/* default_val */ "", | |||||
"'add' to add an IP/Subnet to the list, 'remove' to " | |||||
"remove an IP/Subnet from the list"}, | |||||
{"bantime", RPCArg::Type::NUM, /* opt */ true, | |||||
/* default_val */ "", | |||||
"time in seconds how long (or until when if [absolute] is " | |||||
"set) the IP is banned (0 or empty means using the " | |||||
"default time of 24h which can also be overwritten by the " | |||||
"-bantime startup argument)"}, | |||||
{"absolute", RPCArg::Type::BOOL, /* opt */ true, | |||||
/* default_val */ "", | |||||
"If set, the bantime must be an absolute timestamp in " | |||||
"seconds since epoch (Jan 1 1970 GMT)"}, | |||||
}} | }} | ||||
.ToString() + | .ToString() + | ||||
"\nArguments:\n" | |||||
"1. \"subnet\" (string, required) The IP/Subnet (see " | |||||
"getpeerinfo for nodes IP) with an optional netmask (default is " | |||||
"/32 " | |||||
"= single IP)\n" | |||||
"2. \"command\" (string, required) 'add' to add an IP/Subnet " | |||||
"to the list, 'remove' to remove an IP/Subnet from the list\n" | |||||
"3. \"bantime\" (numeric, optional) time in seconds how long " | |||||
"(or until when if [absolute] is set) the IP is banned (0 or empty " | |||||
"means using the default time of 24h which can also be overwritten " | |||||
"by the -bantime startup argument)\n" | |||||
"4. \"absolute\" (boolean, optional) If set, the bantime must " | |||||
"be an absolute timestamp in seconds since epoch (Jan 1 1970 GMT)\n" | |||||
"\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 111 Lines • ▼ Show 20 Lines | static UniValue clearbanned(const Config &config, | ||||
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(RPCHelpMan{ | ||||
RPCHelpMan{"setnetworkactive", | "setnetworkactive", | ||||
"\nDisable/enable all p2p network activity.\n", | "\nDisable/enable all p2p network activity.\n", | ||||
{ | { | ||||
{"state", RPCArg::Type::BOOL, false}, | {"state", RPCArg::Type::BOOL, /* opt */ false, | ||||
}} | /* default_val */ "", | ||||
.ToString() + | "true to enable networking, false to disable"}, | ||||
"\nArguments:\n" | }}.ToString()); | ||||
"1. \"state\" (boolean, required) true to " | |||||
"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( | ||||
RPCHelpMan{"getnodeaddresses", | RPCHelpMan{"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, true}, | {"count", RPCArg::Type::NUM, /* opt */ true, | ||||
}} | /* default_val */ "1", | ||||
.ToString() + | "How many addresses to return. Limited to the " | ||||
"\nArguments:\n" | "smaller of " + | ||||
"1. \"count\" (numeric, optional) How many addresses to return. " | |||||
"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."}, | ||||
}} | |||||
.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 |