Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
disconnectpeer RPC
  • Loading branch information
gavinandresen committed Sep 10, 2014
1 parent def2fdb commit 499ae0b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rpcclient.cpp
Expand Up @@ -87,6 +87,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "estimatepriority", 0 },
{ "prioritisetransaction", 1 },
{ "prioritisetransaction", 2 },
{ "disconnectpeer", 0 },
};

class CRPCConvertTable
Expand Down
29 changes: 29 additions & 0 deletions src/rpcnet.cpp
Expand Up @@ -12,6 +12,7 @@
#include "timedata.h"
#include "util.h"

#include <boost/assign/list_of.hpp>
#include <boost/foreach.hpp>
#include "json/json_spirit_value.h"

Expand Down Expand Up @@ -413,3 +414,31 @@ Value getnetworkinfo(const Array& params, bool fHelp)
obj.push_back(Pair("localaddresses", localAddresses));
return obj;
}

Value disconnectpeer(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"disconnectpeer id\n"
"Disconnect peer with given id\n"
"(id as reported by getpeerinfo).\n"
"\nExamples:\n"
+ HelpExampleCli("disconnectpeer", "11")
+ HelpExampleRpc("disconnectpeer", "11")
);

RPCTypeCheck(params, boost::assign::list_of(int_type));

int node_id = params[0].get_int();

LOCK(cs_vNodes);
BOOST_FOREACH(CNode* node, vNodes)
{
if (node->GetId() == node_id)
{
node->CloseSocketDisconnect();
return Value::null;
}
}
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid peer id");
}
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Expand Up @@ -253,6 +253,7 @@ static const CRPCCommand vRPCCommands[] =
{ "network", "getnettotals", &getnettotals, true, true, false },
{ "network", "getpeerinfo", &getpeerinfo, true, false, false },
{ "network", "ping", &ping, true, false, false },
{ "network", "disconnectpeer", &disconnectpeer, true, false, false },

/* Block chain and UTXO */
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true, false, false },
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Expand Up @@ -131,6 +131,7 @@ extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value disconnectpeer(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
Expand Down

0 comments on commit 499ae0b

Please sign in to comment.