Skip to content

Commit 754aae5

Browse files
committed
Merge pull request #6271
60dbe73 New RPC command disconnectnode (Alex van der Peet)
2 parents a903ad7 + 60dbe73 commit 754aae5

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/rpcnet.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ UniValue addnode(const UniValue& params, bool fHelp)
214214
return NullUniValue;
215215
}
216216

217+
UniValue disconnectnode(const UniValue& params, bool fHelp)
218+
{
219+
if (fHelp || params.size() != 1)
220+
throw runtime_error(
221+
"disconnectnode \"node\" \n"
222+
"\nImmediately disconnects from the specified node.\n"
223+
"\nArguments:\n"
224+
"1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
225+
"\nExamples:\n"
226+
+ HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"")
227+
+ HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"")
228+
);
229+
230+
CNode* pNode = FindNode(params[0].get_str());
231+
if (pNode == NULL)
232+
throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes");
233+
234+
pNode->CloseSocketDisconnect();
235+
236+
return NullUniValue;
237+
}
238+
217239
UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
218240
{
219241
if (fHelp || params.size() < 1 || params.size() > 2)

src/rpcprotocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ enum RPCErrorCode
6363
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //! Still downloading initial blocks
6464
RPC_CLIENT_NODE_ALREADY_ADDED = -23, //! Node is already added
6565
RPC_CLIENT_NODE_NOT_ADDED = -24, //! Node has not been added before
66+
RPC_CLIENT_NODE_NOT_CONNECTED = -29, //! Node to disconnect not found in connected nodes
6667

6768
//! Wallet errors
6869
RPC_WALLET_ERROR = -4, //! Unspecified problem with wallet (key not found etc.)

src/rpcserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ static const CRPCCommand vRPCCommands[] =
273273
/* P2P networking */
274274
{ "network", "getnetworkinfo", &getnetworkinfo, true },
275275
{ "network", "addnode", &addnode, true },
276+
{ "network", "disconnectnode", &disconnectnode, true },
276277
{ "network", "getaddednodeinfo", &getaddednodeinfo, true },
277278
{ "network", "getconnectioncount", &getconnectioncount, true },
278279
{ "network", "getnettotals", &getnettotals, true },

src/rpcserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ extern UniValue getconnectioncount(const UniValue& params, bool fHelp); // in rp
151151
extern UniValue getpeerinfo(const UniValue& params, bool fHelp);
152152
extern UniValue ping(const UniValue& params, bool fHelp);
153153
extern UniValue addnode(const UniValue& params, bool fHelp);
154+
extern UniValue disconnectnode(const UniValue& params, bool fHelp);
154155
extern UniValue getaddednodeinfo(const UniValue& params, bool fHelp);
155156
extern UniValue getnettotals(const UniValue& params, bool fHelp);
156157

0 commit comments

Comments
 (0)