@@ -271,25 +271,22 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
271
271
{
272
272
if (fHelp || params.size () < 1 || params.size () > 2 )
273
273
throw runtime_error (
274
- " getaddednodeinfo dns ( \" node\" )\n "
274
+ " getaddednodeinfo dummy ( \" node\" )\n "
275
275
" \n Returns information about the given added node, or all added nodes\n "
276
276
" (note that onetry addnodes are not listed here)\n "
277
- " If dns is false, only a list of added nodes will be provided,\n "
278
- " otherwise connected information will also be available.\n "
279
277
" \n Arguments:\n "
280
- " 1. dns (boolean, required) If false, only a list of added nodes will be provided, otherwise connected information will also be available. \n "
278
+ " 1. dummy (boolean, required) Kept for historical purposes but ignored \n "
281
279
" 2. \" node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n "
282
280
" \n Result:\n "
283
281
" [\n "
284
282
" {\n "
285
- " \" addednode\" : \" 192.168.0.201\" , (string) The node ip address\n "
283
+ " \" addednode\" : \" 192.168.0.201\" , (string) The node ip address or name (as provided to addnode) \n "
286
284
" \" connected\" : true|false, (boolean) If connected\n "
287
- " \" addresses\" : [\n "
285
+ " \" addresses\" : [ (list of objects) Only when connected = true \n "
288
286
" {\n "
289
- " \" address\" : \" 192.168.0.201:8333\" , (string) The bitcoin server host and port\n "
287
+ " \" address\" : \" 192.168.0.201:8333\" , (string) The bitcoin server IP and port we're connected to \n "
290
288
" \" connected\" : \" outbound\" (string) connection, inbound or outbound\n "
291
289
" }\n "
292
- " ,...\n "
293
290
" ]\n "
294
291
" }\n "
295
292
" ,...\n "
@@ -300,83 +297,35 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
300
297
+ HelpExampleRpc (" getaddednodeinfo" , " true, \" 192.168.0.201\" " )
301
298
);
302
299
303
- bool fDns = params[ 0 ]. get_bool ();
300
+ std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo ();
304
301
305
- list<string> laddedNodes (0 );
306
- if (params.size () == 1 )
307
- {
308
- LOCK (cs_vAddedNodes);
309
- BOOST_FOREACH (const std::string& strAddNode, vAddedNodes)
310
- laddedNodes.push_back (strAddNode);
311
- }
312
- else
313
- {
314
- string strNode = params[1 ].get_str ();
315
- LOCK (cs_vAddedNodes);
316
- BOOST_FOREACH (const std::string& strAddNode, vAddedNodes) {
317
- if (strAddNode == strNode)
318
- {
319
- laddedNodes.push_back (strAddNode);
302
+ if (params.size () == 2 ) {
303
+ bool found = false ;
304
+ for (const AddedNodeInfo& info : vInfo) {
305
+ if (info.strAddedNode == params[1 ].get_str ()) {
306
+ vInfo.assign (1 , info);
307
+ found = true ;
320
308
break ;
321
309
}
322
310
}
323
- if (laddedNodes. size () == 0 )
311
+ if (!found) {
324
312
throw JSONRPCError (RPC_CLIENT_NODE_NOT_ADDED, " Error: Node has not been added." );
325
- }
326
-
327
- UniValue ret (UniValue::VARR);
328
- if (!fDns )
329
- {
330
- BOOST_FOREACH (const std::string& strAddNode, laddedNodes) {
331
- UniValue obj (UniValue::VOBJ);
332
- obj.push_back (Pair (" addednode" , strAddNode));
333
- ret.push_back (obj);
334
313
}
335
- return ret;
336
314
}
337
315
338
- list<pair<string, vector<CService> > > laddedAddreses (0 );
339
- BOOST_FOREACH (const std::string& strAddNode, laddedNodes) {
340
- vector<CService> vservNode (0 );
341
- if (Lookup (strAddNode.c_str (), vservNode, Params ().GetDefaultPort (), fNameLookup , 0 ))
342
- laddedAddreses.push_back (make_pair (strAddNode, vservNode));
343
- else
344
- {
345
- UniValue obj (UniValue::VOBJ);
346
- obj.push_back (Pair (" addednode" , strAddNode));
347
- obj.push_back (Pair (" connected" , false ));
348
- UniValue addresses (UniValue::VARR);
349
- obj.push_back (Pair (" addresses" , addresses));
350
- ret.push_back (obj);
351
- }
352
- }
316
+ UniValue ret (UniValue::VARR);
353
317
354
- LOCK (cs_vNodes);
355
- for (list<pair<string, vector<CService> > >::iterator it = laddedAddreses.begin (); it != laddedAddreses.end (); it++)
356
- {
318
+ for (const AddedNodeInfo& info : vInfo) {
357
319
UniValue obj (UniValue::VOBJ);
358
- obj.push_back (Pair (" addednode" , it-> first ));
359
-
320
+ obj.push_back (Pair (" addednode" , info. strAddedNode ));
321
+ obj. push_back ( Pair ( " connected " , info. fConnected ));
360
322
UniValue addresses (UniValue::VARR);
361
- bool fConnected = false ;
362
- BOOST_FOREACH (const CService& addrNode, it->second ) {
363
- bool fFound = false ;
364
- UniValue node (UniValue::VOBJ);
365
- node.push_back (Pair (" address" , addrNode.ToString ()));
366
- BOOST_FOREACH (CNode* pnode, vNodes) {
367
- if (pnode->addr == addrNode)
368
- {
369
- fFound = true ;
370
- fConnected = true ;
371
- node.push_back (Pair (" connected" , pnode->fInbound ? " inbound" : " outbound" ));
372
- break ;
373
- }
374
- }
375
- if (!fFound )
376
- node.push_back (Pair (" connected" , " false" ));
377
- addresses.push_back (node);
323
+ if (info.fConnected ) {
324
+ UniValue address (UniValue::VOBJ);
325
+ address.push_back (Pair (" address" , info.resolvedAddress .ToString ()));
326
+ address.push_back (Pair (" connected" , info.fInbound ? " inbound" : " outbound" ));
327
+ addresses.push_back (address);
378
328
}
379
- obj.push_back (Pair (" connected" , fConnected ));
380
329
obj.push_back (Pair (" addresses" , addresses));
381
330
ret.push_back (obj);
382
331
}
0 commit comments