MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / disconnectnode

Function disconnectnode

src/rpc/net.cpp:452–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

450}
451
452static 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
498static RPCMethod getaddednodeinfo()
499{

Callers

nothing calls this directly

Calls 5

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
DisconnectNodeMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected