Browse Source

Add addnode RPC command.

0.8
Matt Corallo 12 years ago
parent
commit
72a348fd9a
  1. 1
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 42
      src/rpcnet.cpp

1
src/bitcoinrpc.cpp

@ -201,6 +201,7 @@ static const CRPCCommand vRPCCommands[] = @@ -201,6 +201,7 @@ static const CRPCCommand vRPCCommands[] =
{ "getblockcount", &getblockcount, true, false },
{ "getconnectioncount", &getconnectioncount, true, false },
{ "getpeerinfo", &getpeerinfo, true, false },
{ "addnode", &addnode, true, true },
{ "getdifficulty", &getdifficulty, true, false },
{ "getgenerate", &getgenerate, true, false },
{ "setgenerate", &setgenerate, true, false },

1
src/bitcoinrpc.h

@ -132,6 +132,7 @@ extern void EnsureWalletIsUnlocked(); @@ -132,6 +132,7 @@ extern void EnsureWalletIsUnlocked();
extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value addnode(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);

42
src/rpcnet.cpp

@ -65,3 +65,45 @@ Value getpeerinfo(const Array& params, bool fHelp) @@ -65,3 +65,45 @@ Value getpeerinfo(const Array& params, bool fHelp)
return ret;
}
Value addnode(const Array& params, bool fHelp)
{
string strCommand;
if (params.size() == 2)
strCommand = params[1].get_str();
if (fHelp || params.size() != 2 ||
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
throw runtime_error(
"addnode <node> <add|remove|onetry>\n"
"Attempts add or remove <node> from the addnode list or try a connection to <node> once.");
string strNode = params[0].get_str();
if (strCommand == "onetry")
{
CAddress addr;
ConnectNode(addr, strNode.c_str());
return Value::null;
}
LOCK(cs_vAddedNodes);
vector<string>::iterator it = vAddedNodes.begin();
for(; it != vAddedNodes.end(); it++)
if (strNode == *it)
break;
if (strCommand == "add")
{
if (it != vAddedNodes.end())
throw JSONRPCError(-23, "Error: Node already added");
vAddedNodes.push_back(strNode);
}
else if(strCommand == "remove")
{
if (it == vAddedNodes.end())
throw JSONRPCError(-24, "Error: Node has not been added.");
vAddedNodes.erase(it);
}
return Value::null;
}

Loading…
Cancel
Save