Add a getaddednodeinfo RPC.
This commit is contained in:
parent
72a348fd9a
commit
67a11bd6c5
3 changed files with 95 additions and 0 deletions
|
@ -202,6 +202,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||||
{ "getconnectioncount", &getconnectioncount, true, false },
|
{ "getconnectioncount", &getconnectioncount, true, false },
|
||||||
{ "getpeerinfo", &getpeerinfo, true, false },
|
{ "getpeerinfo", &getpeerinfo, true, false },
|
||||||
{ "addnode", &addnode, true, true },
|
{ "addnode", &addnode, true, true },
|
||||||
|
{ "getaddednodeinfo", &getaddednodeinfo, true, true },
|
||||||
{ "getdifficulty", &getdifficulty, true, false },
|
{ "getdifficulty", &getdifficulty, true, false },
|
||||||
{ "getgenerate", &getgenerate, true, false },
|
{ "getgenerate", &getgenerate, true, false },
|
||||||
{ "setgenerate", &setgenerate, true, false },
|
{ "setgenerate", &setgenerate, true, false },
|
||||||
|
@ -1180,6 +1181,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
|
||||||
// Special case non-string parameter types
|
// Special case non-string parameter types
|
||||||
//
|
//
|
||||||
if (strMethod == "stop" && n > 0) ConvertTo<bool>(params[0]);
|
if (strMethod == "stop" && n > 0) ConvertTo<bool>(params[0]);
|
||||||
|
if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo<bool>(params[0]);
|
||||||
if (strMethod == "setgenerate" && n > 0) ConvertTo<bool>(params[0]);
|
if (strMethod == "setgenerate" && n > 0) ConvertTo<bool>(params[0]);
|
||||||
if (strMethod == "setgenerate" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
if (strMethod == "setgenerate" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
|
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
|
||||||
|
|
|
@ -133,6 +133,7 @@ extern void EnsureWalletIsUnlocked();
|
||||||
extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
|
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 getpeerinfo(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value addnode(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 dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
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);
|
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
|
||||||
|
|
||||||
|
|
|
@ -107,3 +107,95 @@ Value addnode(const Array& params, bool fHelp)
|
||||||
return Value::null;
|
return Value::null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value getaddednodeinfo(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||||
|
throw runtime_error(
|
||||||
|
"getaddednodeinfo <dns> [node]\n"
|
||||||
|
"Returns information about the given added node, or all added nodes\n"
|
||||||
|
"(note that onetry addnodes are not listed here)\n"
|
||||||
|
"If dns is false, only a list of added nodes will be provided,\n"
|
||||||
|
"otherwise connected information will also be available.");
|
||||||
|
|
||||||
|
bool fDns = params[0].get_bool();
|
||||||
|
|
||||||
|
list<string> laddedNodes(0);
|
||||||
|
if (params.size() == 1)
|
||||||
|
{
|
||||||
|
LOCK(cs_vAddedNodes);
|
||||||
|
BOOST_FOREACH(string& strAddNode, vAddedNodes)
|
||||||
|
laddedNodes.push_back(strAddNode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string strNode = params[1].get_str();
|
||||||
|
LOCK(cs_vAddedNodes);
|
||||||
|
BOOST_FOREACH(string& strAddNode, vAddedNodes)
|
||||||
|
if (strAddNode == strNode)
|
||||||
|
{
|
||||||
|
laddedNodes.push_back(strAddNode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (laddedNodes.size() == 0)
|
||||||
|
throw JSONRPCError(-24, "Error: Node has not been added.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fDns)
|
||||||
|
{
|
||||||
|
Object ret;
|
||||||
|
BOOST_FOREACH(string& strAddNode, laddedNodes)
|
||||||
|
ret.push_back(Pair("addednode", strAddNode));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array ret;
|
||||||
|
|
||||||
|
list<pair<string, vector<CService> > > laddedAddreses(0);
|
||||||
|
BOOST_FOREACH(string& strAddNode, laddedNodes)
|
||||||
|
{
|
||||||
|
vector<CService> vservNode(0);
|
||||||
|
if(Lookup(strAddNode.c_str(), vservNode, GetDefaultPort(), fNameLookup, 0))
|
||||||
|
laddedAddreses.push_back(make_pair(strAddNode, vservNode));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Object obj;
|
||||||
|
obj.push_back(Pair("addednode", strAddNode));
|
||||||
|
obj.push_back(Pair("connected", false));
|
||||||
|
Array addresses;
|
||||||
|
obj.push_back(Pair("addresses", addresses));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOCK(cs_vNodes);
|
||||||
|
for (list<pair<string, vector<CService> > >::iterator it = laddedAddreses.begin(); it != laddedAddreses.end(); it++)
|
||||||
|
{
|
||||||
|
Object obj;
|
||||||
|
obj.push_back(Pair("addednode", it->first));
|
||||||
|
|
||||||
|
Array addresses;
|
||||||
|
bool fConnected = false;
|
||||||
|
BOOST_FOREACH(CService& addrNode, it->second)
|
||||||
|
{
|
||||||
|
bool fFound = false;
|
||||||
|
Object node;
|
||||||
|
node.push_back(Pair("address", addrNode.ToString()));
|
||||||
|
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||||
|
if (pnode->addr == addrNode)
|
||||||
|
{
|
||||||
|
fFound = true;
|
||||||
|
fConnected = true;
|
||||||
|
node.push_back(Pair("connected", pnode->fInbound ? "inbound" : "outbound"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!fFound)
|
||||||
|
node.push_back(Pair("connected", "false"));
|
||||||
|
addresses.push_back(node);
|
||||||
|
}
|
||||||
|
obj.push_back(Pair("connected", fConnected));
|
||||||
|
obj.push_back(Pair("addresses", addresses));
|
||||||
|
ret.push_back(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue