Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | if (strCommand == "add") { | ||||
"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() != 1) | if (request.fHelp || request.params.size() == 0 || | ||||
request.params.size() >= 3) { | |||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"disconnectnode \"address\" \n" | "disconnectnode \"[address]\" [nodeid]\n" | ||||
"\nImmediately disconnects from the specified node.\n" | "\nImmediately disconnects from the specified peer node.\n" | ||||
"\nStrictly one out of 'address' and 'nodeid' can be provided to " | |||||
"identify the node.\n" | |||||
"\nTo disconnect by nodeid, either set 'address' to the empty " | |||||
"string, or call using the named 'nodeid' argument only.\n" | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"address\" (string, required) 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 " | |||||
"getpeerinfo for node IDs)\n" | |||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | ||||
HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"")); | HelpExampleCli("disconnectnode", "\"\" 1") + | ||||
HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") + | |||||
HelpExampleRpc("disconnectnode", "\"\", 1")); | |||||
} | |||||
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"); | ||||
} | |||||
bool ret = g_connman->DisconnectNode(request.params[0].get_str()); | bool success; | ||||
if (!ret) | const UniValue &address_arg = request.params[0]; | ||||
const UniValue &id_arg = | |||||
request.params.size() < 2 ? NullUniValue : request.params[1]; | |||||
if (!address_arg.isNull() && id_arg.isNull()) { | |||||
/* handle disconnect-by-address */ | |||||
success = g_connman->DisconnectNode(address_arg.get_str()); | |||||
} else if (!id_arg.isNull() && | |||||
(address_arg.isNull() || | |||||
(address_arg.isStr() && address_arg.get_str().empty()))) { | |||||
/* handle disconnect-by-id */ | |||||
NodeId nodeid = (NodeId)id_arg.get_int64(); | |||||
success = g_connman->DisconnectNode(nodeid); | |||||
} else { | |||||
throw JSONRPCError( | |||||
RPC_INVALID_PARAMS, | |||||
"Only one of address and nodeid should be provided."); | |||||
} | |||||
if (!success) { | |||||
throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, | throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, | ||||
"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) | if (request.fHelp || request.params.size() > 1) | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Lines | |||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category name actor (function) okSafeMode | // category name actor (function) okSafeMode | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "network", "getconnectioncount", getconnectioncount, true, {} }, | { "network", "getconnectioncount", getconnectioncount, true, {} }, | ||||
{ "network", "ping", ping, true, {} }, | { "network", "ping", ping, true, {} }, | ||||
{ "network", "getpeerinfo", getpeerinfo, true, {} }, | { "network", "getpeerinfo", getpeerinfo, true, {} }, | ||||
{ "network", "addnode", addnode, true, {"node","command"} }, | { "network", "addnode", addnode, true, {"node","command"} }, | ||||
{ "network", "disconnectnode", disconnectnode, true, {"address"} }, | { "network", "disconnectnode", disconnectnode, true, {"address", "nodeid"} }, | ||||
{ "network", "getaddednodeinfo", getaddednodeinfo, true, {"node"} }, | { "network", "getaddednodeinfo", getaddednodeinfo, true, {"node"} }, | ||||
{ "network", "getnettotals", getnettotals, true, {} }, | { "network", "getnettotals", getnettotals, true, {} }, | ||||
{ "network", "getnetworkinfo", getnetworkinfo, true, {} }, | { "network", "getnetworkinfo", getnetworkinfo, true, {} }, | ||||
{ "network", "setban", setban, true, {"subnet", "command", "bantime", "absolute"} }, | { "network", "setban", setban, true, {"subnet", "command", "bantime", "absolute"} }, | ||||
{ "network", "listbanned", listbanned, true, {} }, | { "network", "listbanned", listbanned, true, {} }, | ||||
{ "network", "clearbanned", clearbanned, true, {} }, | { "network", "clearbanned", clearbanned, true, {} }, | ||||
{ "network", "setnetworkactive", setnetworkactive, true, {"state"} }, | { "network", "setnetworkactive", setnetworkactive, true, {"state"} }, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterNetRPCCommands(CRPCTable &t) { | void RegisterNetRPCCommands(CRPCTable &t) { | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } |