From b2e3edc61cf891c3e707a86e90fe37fca92cb05a Mon Sep 17 00:00:00 2001 From: brunoerg Date: Thu, 24 Nov 2022 10:52:11 -0300 Subject: [PATCH] rpc, p2p: allow `disconnectnode` with subnet --- src/rpc/net.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 8d7f4e7f5b..94760c2a07 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -394,7 +394,7 @@ static RPCHelpMan disconnectnode() "\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", { - {"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node"}, + {"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node or subnet"}, {"nodeid", RPCArg::Type::NUM, RPCArg::DefaultHint{"fallback to address"}, "The node ID (see getpeerinfo for node IDs)"}, }, RPCResult{RPCResult::Type::NONE, "", ""}, @@ -415,7 +415,16 @@ static RPCHelpMan disconnectnode() if (!address_arg.isNull() && id_arg.isNull()) { /* handle disconnect-by-address */ - success = connman.DisconnectNode(address_arg.get_str()); + if (address_arg.get_str().find('/') != std::string::npos) { + CSubNet subnet; + if (LookupSubNet(address_arg.get_str(), subnet)) { + success = connman.DisconnectNode(subnet); + } else { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid subnet"); + } + } else { + success = 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.getInt();