@@ -314,8 +314,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
314
314
}
315
315
return UNKNOWN_NETWORK;
316
316
}
317
- uint8_t m_details_level{0 }; // !< Optional user-supplied arg to set dashboard details level
318
- bool m_is_help_requested{false }; // !< Optional user-supplied arg to print help documentation
317
+ uint8_t m_details_level{0 }; // !< Optional user-supplied arg to set dashboard details level
319
318
bool DetailsRequested () const { return m_details_level > 0 && m_details_level < 5 ; }
320
319
bool IsAddressSelected () const { return m_details_level == 2 || m_details_level == 4 ; }
321
320
bool IsVersionSelected () const { return m_details_level == 3 || m_details_level == 4 ; }
@@ -367,68 +366,6 @@ class NetinfoRequestHandler : public BaseRequestHandler
367
366
if (conn_type == " addr-fetch" ) return " addr" ;
368
367
return " " ;
369
368
}
370
- const UniValue NetinfoHelp ()
371
- {
372
- return std::string{
373
- " -netinfo level|\" help\" \n\n "
374
- " Returns a network peer connections dashboard with information from the remote server.\n "
375
- " Under the hood, -netinfo fetches the data by calling getpeerinfo and getnetworkinfo.\n "
376
- " An optional integer argument from 0 to 4 can be passed for different peers listings.\n "
377
- " Pass \" help\" to see this detailed help documentation.\n "
378
- " If more than one argument is passed, only the first one is read and parsed.\n "
379
- " Suggestion: use with the Linux watch(1) command for a live dashboard; see example below.\n\n "
380
- " Arguments:\n "
381
- " 1. level (integer 0-4, optional) Specify the info level of the peers dashboard (default 0):\n "
382
- " 0 - Connection counts and local addresses\n "
383
- " 1 - Like 0 but with a peers listing (without address or version columns)\n "
384
- " 2 - Like 1 but with an address column\n "
385
- " 3 - Like 1 but with a version column\n "
386
- " 4 - Like 1 but with both address and version columns\n "
387
- " 2. help (string \" help\" , optional) Print this help documentation instead of the dashboard.\n\n "
388
- " Result:\n\n "
389
- " * The peers listing in levels 1-4 displays all of the peers sorted by direction and minimum ping time:\n\n "
390
- " Column Description\n "
391
- " ------ -----------\n "
392
- " <-> Direction\n "
393
- " \" in\" - inbound connections are those initiated by the peer\n "
394
- " \" out\" - outbound connections are those initiated by us\n "
395
- " type Type of peer connection\n "
396
- " \" full\" - full relay, the default\n "
397
- " \" block\" - block relay; like full relay but does not relay transactions or addresses\n "
398
- " \" manual\" - peer we manually added using RPC addnode or the -addnode/-connect config options\n "
399
- " \" feeler\" - short-lived connection for testing addresses\n "
400
- " \" addr\" - address fetch; short-lived connection for requesting addresses\n "
401
- " net Network the peer connected through (\" ipv4\" , \" ipv6\" , \" onion\" , \" i2p\" , or \" cjdns\" )\n "
402
- " mping Minimum observed ping time, in milliseconds (ms)\n "
403
- " ping Last observed ping time, in milliseconds (ms)\n "
404
- " send Time since last message sent to the peer, in seconds\n "
405
- " recv Time since last message received from the peer, in seconds\n "
406
- " txn Time since last novel transaction received from the peer and accepted into our mempool, in minutes\n "
407
- " blk Time since last novel block passing initial validity checks received from the peer, in minutes\n "
408
- " hb High-bandwidth BIP152 compact block relay\n "
409
- " \" .\" (to) - we selected the peer as a high-bandwidth peer\n "
410
- " \" *\" (from) - the peer selected us as a high-bandwidth peer\n "
411
- " age Duration of connection to the peer, in minutes\n "
412
- " asmap Mapped AS (Autonomous System) number in the BGP route to the peer, used for diversifying\n "
413
- " peer selection (only displayed if the -asmap config option is set)\n "
414
- " id Peer index, in increasing order of peer connections since node startup\n "
415
- " address IP address and port of the peer\n "
416
- " version Peer version and subversion concatenated, e.g. \" 70016/Satoshi:21.0.0/\"\n\n "
417
- " * The connection counts table displays the number of peers by direction, network, and the totals\n "
418
- " for each, as well as two special outbound columns for block relay peers and manual peers.\n\n "
419
- " * The local addresses table lists each local address broadcast by the node, the port, and the score.\n\n "
420
- " Examples:\n\n "
421
- " Connection counts and local addresses only\n "
422
- " > bitcoin-cli -netinfo\n\n "
423
- " Compact peers listing\n "
424
- " > bitcoin-cli -netinfo 1\n\n "
425
- " Full dashboard\n "
426
- " > bitcoin-cli -netinfo 4\n\n "
427
- " Full live dashboard, adjust --interval or --no-title as needed (Linux)\n "
428
- " > watch --interval 1 --no-title bitcoin-cli -netinfo 4\n\n "
429
- " See this help\n "
430
- " > bitcoin-cli -netinfo help\n " };
431
- }
432
369
const int64_t m_time_now{GetSystemTimeInSeconds ()};
433
370
434
371
public:
@@ -441,8 +378,6 @@ class NetinfoRequestHandler : public BaseRequestHandler
441
378
uint8_t n{0 };
442
379
if (ParseUInt8 (args.at (0 ), &n)) {
443
380
m_details_level = std::min (n, MAX_DETAIL_LEVEL);
444
- } else if (args.at (0 ) == " help" ) {
445
- m_is_help_requested = true ;
446
381
} else {
447
382
throw std::runtime_error (strprintf (" invalid -netinfo argument: %s" , args.at (0 )));
448
383
}
@@ -455,9 +390,6 @@ class NetinfoRequestHandler : public BaseRequestHandler
455
390
456
391
UniValue ProcessReply (const UniValue& batch_in) override
457
392
{
458
- if (m_is_help_requested) {
459
- return JSONRPCReplyObj (NetinfoHelp (), NullUniValue, 1 );
460
- }
461
393
const std::vector<UniValue> batch{JSONRPCProcessBatchReply (batch_in)};
462
394
if (!batch[ID_PEERINFO][" error" ].isNull ()) return batch[ID_PEERINFO];
463
395
if (!batch[ID_NETWORKINFO][" error" ].isNull ()) return batch[ID_NETWORKINFO];
@@ -576,6 +508,66 @@ class NetinfoRequestHandler : public BaseRequestHandler
576
508
577
509
return JSONRPCReplyObj (UniValue{result}, NullUniValue, 1 );
578
510
}
511
+
512
+ const std::string m_help_doc{
513
+ " -netinfo level|\" help\" \n\n "
514
+ " Returns a network peer connections dashboard with information from the remote server.\n "
515
+ " Under the hood, -netinfo fetches the data by calling getpeerinfo and getnetworkinfo.\n "
516
+ " An optional integer argument from 0 to 4 can be passed for different peers listings.\n "
517
+ " Pass \" help\" to see this detailed help documentation.\n "
518
+ " If more than one argument is passed, only the first one is read and parsed.\n "
519
+ " Suggestion: use with the Linux watch(1) command for a live dashboard; see example below.\n\n "
520
+ " Arguments:\n "
521
+ " 1. level (integer 0-4, optional) Specify the info level of the peers dashboard (default 0):\n "
522
+ " 0 - Connection counts and local addresses\n "
523
+ " 1 - Like 0 but with a peers listing (without address or version columns)\n "
524
+ " 2 - Like 1 but with an address column\n "
525
+ " 3 - Like 1 but with a version column\n "
526
+ " 4 - Like 1 but with both address and version columns\n "
527
+ " 2. help (string \" help\" , optional) Print this help documentation instead of the dashboard.\n\n "
528
+ " Result:\n\n "
529
+ " * The peers listing in levels 1-4 displays all of the peers sorted by direction and minimum ping time:\n\n "
530
+ " Column Description\n "
531
+ " ------ -----------\n "
532
+ " <-> Direction\n "
533
+ " \" in\" - inbound connections are those initiated by the peer\n "
534
+ " \" out\" - outbound connections are those initiated by us\n "
535
+ " type Type of peer connection\n "
536
+ " \" full\" - full relay, the default\n "
537
+ " \" block\" - block relay; like full relay but does not relay transactions or addresses\n "
538
+ " \" manual\" - peer we manually added using RPC addnode or the -addnode/-connect config options\n "
539
+ " \" feeler\" - short-lived connection for testing addresses\n "
540
+ " \" addr\" - address fetch; short-lived connection for requesting addresses\n "
541
+ " net Network the peer connected through (\" ipv4\" , \" ipv6\" , \" onion\" , \" i2p\" , or \" cjdns\" )\n "
542
+ " mping Minimum observed ping time, in milliseconds (ms)\n "
543
+ " ping Last observed ping time, in milliseconds (ms)\n "
544
+ " send Time since last message sent to the peer, in seconds\n "
545
+ " recv Time since last message received from the peer, in seconds\n "
546
+ " txn Time since last novel transaction received from the peer and accepted into our mempool, in minutes\n "
547
+ " blk Time since last novel block passing initial validity checks received from the peer, in minutes\n "
548
+ " hb High-bandwidth BIP152 compact block relay\n "
549
+ " \" .\" (to) - we selected the peer as a high-bandwidth peer\n "
550
+ " \" *\" (from) - the peer selected us as a high-bandwidth peer\n "
551
+ " age Duration of connection to the peer, in minutes\n "
552
+ " asmap Mapped AS (Autonomous System) number in the BGP route to the peer, used for diversifying\n "
553
+ " peer selection (only displayed if the -asmap config option is set)\n "
554
+ " id Peer index, in increasing order of peer connections since node startup\n "
555
+ " address IP address and port of the peer\n "
556
+ " version Peer version and subversion concatenated, e.g. \" 70016/Satoshi:21.0.0/\"\n\n "
557
+ " * The connection counts table displays the number of peers by direction, network, and the totals\n "
558
+ " for each, as well as two special outbound columns for block relay peers and manual peers.\n\n "
559
+ " * The local addresses table lists each local address broadcast by the node, the port, and the score.\n\n "
560
+ " Examples:\n\n "
561
+ " Connection counts and local addresses only\n "
562
+ " > bitcoin-cli -netinfo\n\n "
563
+ " Compact peers listing\n "
564
+ " > bitcoin-cli -netinfo 1\n\n "
565
+ " Full dashboard\n "
566
+ " > bitcoin-cli -netinfo 4\n\n "
567
+ " Full live dashboard, adjust --interval or --no-title as needed (Linux)\n "
568
+ " > watch --interval 1 --no-title bitcoin-cli -netinfo 4\n\n "
569
+ " See this help\n "
570
+ " > bitcoin-cli -netinfo help\n " };
579
571
};
580
572
581
573
/* * Process RPC generatetoaddress request. */
@@ -907,6 +899,10 @@ static int CommandLineRPC(int argc, char *argv[])
907
899
if (gArgs .IsArgSet (" -getinfo" )) {
908
900
rh.reset (new GetinfoRequestHandler ());
909
901
} else if (gArgs .GetBoolArg (" -netinfo" , false )) {
902
+ if (!args.empty () && args.at (0 ) == " help" ) {
903
+ tfm::format (std::cout, " %s\n " , NetinfoRequestHandler ().m_help_doc );
904
+ return 0 ;
905
+ }
910
906
rh.reset (new NetinfoRequestHandler ());
911
907
} else if (gArgs .GetBoolArg (" -generate" , false )) {
912
908
const UniValue getnewaddress{GetNewAddress ()};
0 commit comments