| 450 | } |
| 451 | |
| 452 | static RPCMethod disconnectnode() |
| 453 | { |
| 454 | return RPCMethod{ |
| 455 | "disconnectnode", |
| 456 | "Immediately disconnects from the specified peer node.\n" |
| 457 | "\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n" |
| 458 | "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n", |
| 459 | { |
| 460 | {"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node"}, |
| 461 | {"nodeid", RPCArg::Type::NUM, RPCArg::DefaultHint{"fallback to address"}, "The node ID (see getpeerinfo for node IDs)"}, |
| 462 | }, |
| 463 | RPCResult{RPCResult::Type::NONE, "", ""}, |
| 464 | RPCExamples{ |
| 465 | HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") |
| 466 | + HelpExampleCli("disconnectnode", "\"\" 1") |
| 467 | + HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") |
| 468 | + HelpExampleRpc("disconnectnode", "\"\", 1") |
| 469 | }, |
| 470 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 471 | { |
| 472 | NodeContext& node = EnsureAnyNodeContext(request.context); |
| 473 | CConnman& connman = EnsureConnman(node); |
| 474 | |
| 475 | bool success; |
| 476 | auto address{self.MaybeArg<std::string_view>("address")}; |
| 477 | auto node_id{self.MaybeArg<int64_t>("nodeid")}; |
| 478 | |
| 479 | if (address && !node_id) { |
| 480 | /* handle disconnect-by-address */ |
| 481 | success = connman.DisconnectNode(*address); |
| 482 | } else if (node_id && (!address || address->empty())) { |
| 483 | /* handle disconnect-by-id */ |
| 484 | success = connman.DisconnectNode(*node_id); |
| 485 | } else { |
| 486 | throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided."); |
| 487 | } |
| 488 | |
| 489 | if (!success) { |
| 490 | throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes"); |
| 491 | } |
| 492 | |
| 493 | return UniValue::VNULL; |
| 494 | }, |
| 495 | }; |
| 496 | } |
| 497 | |
| 498 | static RPCMethod getaddednodeinfo() |
| 499 | { |
nothing calls this directly
no test coverage detected