| 238 | } |
| 239 | |
| 240 | static UniValue disconnectnode(const JSONRPCRequest& request) |
| 241 | { |
| 242 | if (request.fHelp || request.params.size() == 0 || request.params.size() >= 3) |
| 243 | throw std::runtime_error( |
| 244 | "disconnectnode \"[address]\" [nodeid]\n" |
| 245 | "\nImmediately disconnects from the specified peer node.\n" |
| 246 | "\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n" |
| 247 | "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n" |
| 248 | "\nArguments:\n" |
| 249 | "1. \"address\" (string, optional) The IP address/port of the node\n" |
| 250 | "2. \"nodeid\" (number, optional) The node ID (see getpeerinfo for node IDs)\n" |
| 251 | "\nExamples:\n" |
| 252 | + HelpExampleCli("disconnectnode", "\"192.168.0.6:8338\"") |
| 253 | + HelpExampleCli("disconnectnode", "\"\" 1") |
| 254 | + HelpExampleRpc("disconnectnode", "\"192.168.0.6:8338\"") |
| 255 | + HelpExampleRpc("disconnectnode", "\"\", 1") |
| 256 | ); |
| 257 | |
| 258 | if(!g_connman) |
| 259 | throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); |
| 260 | |
| 261 | bool success; |
| 262 | const UniValue &address_arg = request.params[0]; |
| 263 | const UniValue &id_arg = request.params[1]; |
| 264 | |
| 265 | if (!address_arg.isNull() && id_arg.isNull()) { |
| 266 | /* handle disconnect-by-address */ |
| 267 | success = g_connman->DisconnectNode(address_arg.get_str()); |
| 268 | } else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) { |
| 269 | /* handle disconnect-by-id */ |
| 270 | NodeId nodeid = (NodeId) id_arg.get_int64(); |
| 271 | success = g_connman->DisconnectNode(nodeid); |
| 272 | } else { |
| 273 | throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided."); |
| 274 | } |
| 275 | |
| 276 | if (!success) { |
| 277 | throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes"); |
| 278 | } |
| 279 | |
| 280 | return NullUniValue; |
| 281 | } |
| 282 | |
| 283 | static UniValue getaddednodeinfo(const JSONRPCRequest& request) |
| 284 | { |
nothing calls this directly
no test coverage detected