mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-07 19:22:17 +01:00
Add a getaddednodeinfo RPC.
This commit is contained in:
@@ -107,3 +107,95 @@ Value addnode(const Array& params, bool fHelp)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user