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

Function disconnectnode

src/rpc/net.cpp:240–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240static 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
283static UniValue getaddednodeinfo(const JSONRPCRequest& request)
284{

Callers

nothing calls this directly

Calls 9

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
isNullMethod · 0.80
DisconnectNodeMethod · 0.80
isStrMethod · 0.80
get_int64Method · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected