aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex van der Peet <alex.van.der.peet@gmail.com>2015-06-11 20:20:54 -0700
committerWladimir J. van der Laan <laanwj@gmail.com>2015-06-16 14:19:41 +0200
commit60dbe730164552128d9b79b5120b4b5e9d456bbb (patch)
tree7f1e33dfa8e8b2c06318a9c110e3342b5f2b4f4b
parenta903ad7e9cafb73f65dc78601dbef1c3c7b4fe0f (diff)
downloadbitcoin-60dbe730164552128d9b79b5120b4b5e9d456bbb.tar.xz
New RPC command disconnectnode
-rw-r--r--src/rpcnet.cpp22
-rw-r--r--src/rpcprotocol.h1
-rw-r--r--src/rpcserver.cpp1
-rw-r--r--src/rpcserver.h1
4 files changed, 25 insertions, 0 deletions
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp
index c4e038eebb..aeaf54814f 100644
--- a/src/rpcnet.cpp
+++ b/src/rpcnet.cpp
@@ -214,6 +214,28 @@ UniValue addnode(const UniValue& params, bool fHelp)
return NullUniValue;
}
+UniValue disconnectnode(const UniValue& params, bool fHelp)
+{
+ if (fHelp || params.size() != 1)
+ throw runtime_error(
+ "disconnectnode \"node\" \n"
+ "\nImmediately disconnects from the specified node.\n"
+ "\nArguments:\n"
+ "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
+ "\nExamples:\n"
+ + HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"")
+ + HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"")
+ );
+
+ CNode* pNode = FindNode(params[0].get_str());
+ if (pNode == NULL)
+ throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes");
+
+ pNode->CloseSocketDisconnect();
+
+ return NullUniValue;
+}
+
UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h
index b9fa091955..ecd7c1f7df 100644
--- a/src/rpcprotocol.h
+++ b/src/rpcprotocol.h
@@ -63,6 +63,7 @@ enum RPCErrorCode
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //! Still downloading initial blocks
RPC_CLIENT_NODE_ALREADY_ADDED = -23, //! Node is already added
RPC_CLIENT_NODE_NOT_ADDED = -24, //! Node has not been added before
+ RPC_CLIENT_NODE_NOT_CONNECTED = -29, //! Node to disconnect not found in connected nodes
//! Wallet errors
RPC_WALLET_ERROR = -4, //! Unspecified problem with wallet (key not found etc.)
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index 3894dd08bb..c27bba519a 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -273,6 +273,7 @@ static const CRPCCommand vRPCCommands[] =
/* P2P networking */
{ "network", "getnetworkinfo", &getnetworkinfo, true },
{ "network", "addnode", &addnode, true },
+ { "network", "disconnectnode", &disconnectnode, true },
{ "network", "getaddednodeinfo", &getaddednodeinfo, true },
{ "network", "getconnectioncount", &getconnectioncount, true },
{ "network", "getnettotals", &getnettotals, true },
diff --git a/src/rpcserver.h b/src/rpcserver.h
index 7b462a8b79..fdd871d0b0 100644
--- a/src/rpcserver.h
+++ b/src/rpcserver.h
@@ -151,6 +151,7 @@ extern UniValue getconnectioncount(const UniValue& params, bool fHelp); // in rp
extern UniValue getpeerinfo(const UniValue& params, bool fHelp);
extern UniValue ping(const UniValue& params, bool fHelp);
extern UniValue addnode(const UniValue& params, bool fHelp);
+extern UniValue disconnectnode(const UniValue& params, bool fHelp);
extern UniValue getaddednodeinfo(const UniValue& params, bool fHelp);
extern UniValue getnettotals(const UniValue& params, bool fHelp);