| 382 | } |
| 383 | |
| 384 | static RPCHelpMan disconnectnode() |
| 385 | { |
| 386 | return RPCHelpMan{"disconnectnode", |
| 387 | "\nImmediately disconnects from the specified peer node.\n" |
| 388 | "\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n" |
| 389 | "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n", |
| 390 | { |
| 391 | {"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node"}, |
| 392 | {"nodeid", RPCArg::Type::NUM, RPCArg::DefaultHint{"fallback to address"}, "The node ID (see getpeerinfo for node IDs)"}, |
| 393 | }, |
| 394 | RPCResult{RPCResult::Type::NONE, "", ""}, |
| 395 | RPCExamples{ |
| 396 | HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") |
| 397 | + HelpExampleCli("disconnectnode", "\"\" 1") |
| 398 | + HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") |
| 399 | + HelpExampleRpc("disconnectnode", "\"\", 1") |
| 400 | }, |
| 401 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 402 | { |
| 403 | NodeContext& node = EnsureAnyNodeContext(request.context); |
| 404 | CConnman& connman = EnsureConnman(node); |
| 405 | |
| 406 | bool success; |
| 407 | const UniValue &address_arg = request.params[0]; |
| 408 | const UniValue &id_arg = request.params[1]; |
| 409 | |
| 410 | if (!address_arg.isNull() && id_arg.isNull()) { |
| 411 | /* handle disconnect-by-address */ |
| 412 | success = connman.DisconnectNode(address_arg.get_str()); |
| 413 | } else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) { |
| 414 | /* handle disconnect-by-id */ |
| 415 | NodeId nodeid = (NodeId) id_arg.get_int64(); |
| 416 | success = connman.DisconnectNode(nodeid); |
| 417 | } else { |
| 418 | throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided."); |
| 419 | } |
| 420 | |
| 421 | if (!success) { |
| 422 | throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes"); |
| 423 | } |
| 424 | |
| 425 | return NullUniValue; |
| 426 | }, |
| 427 | }; |
| 428 | } |
| 429 | |
| 430 | static RPCHelpMan getaddednodeinfo() |
| 431 | { |
nothing calls this directly
no test coverage detected