@@ -400,12 +400,14 @@ class NetinfoRequestHandler : public BaseRequestHandler
400400 size_t m_max_addr_rate_limited_length{6 };
401401 size_t m_max_age_length{5 };
402402 size_t m_max_id_length{2 };
403+ size_t m_max_services_length{6 };
403404 struct Peer {
404405 std::string addr;
405406 std::string sub_version;
406407 std::string conn_type;
407408 std::string network;
408409 std::string age;
410+ std::string services;
409411 std::string transport_protocol_type;
410412 double min_ping;
411413 double ping;
@@ -456,6 +458,15 @@ class NetinfoRequestHandler : public BaseRequestHandler
456458 if (conn_type == " addr-fetch" ) return " addr" ;
457459 return " " ;
458460 }
461+ std::string FormatServices (const UniValue& services)
462+ {
463+ std::string str;
464+ for (size_t i = 0 ; i < services.size (); ++i) {
465+ const std::string s{services[i].get_str ()};
466+ str += s == " NETWORK_LIMITED" ? ' l' : s == " P2P_V2" ? ' 2' : ToLower (s[0 ]);
467+ }
468+ return str;
469+ }
459470
460471public:
461472 static constexpr int ID_PEERINFO = 0 ;
@@ -519,17 +530,19 @@ class NetinfoRequestHandler : public BaseRequestHandler
519530 const double ping{peer[" pingtime" ].isNull () ? -1 : peer[" pingtime" ].get_real ()};
520531 const std::string addr{peer[" addr" ].get_str ()};
521532 const std::string age{conn_time == 0 ? " " : ToString ((time_now - conn_time) / 60 )};
533+ const std::string services{FormatServices (peer[" servicesnames" ])};
522534 const std::string sub_version{peer[" subver" ].get_str ()};
523535 const std::string transport{peer[" transport_protocol_type" ].isNull () ? " v1" : peer[" transport_protocol_type" ].get_str ()};
524536 const bool is_addr_relay_enabled{peer[" addr_relay_enabled" ].isNull () ? false : peer[" addr_relay_enabled" ].get_bool ()};
525537 const bool is_bip152_hb_from{peer[" bip152_hb_from" ].get_bool ()};
526538 const bool is_bip152_hb_to{peer[" bip152_hb_to" ].get_bool ()};
527- m_peers.push_back ({addr, sub_version, conn_type, NETWORK_SHORT_NAMES[network_id], age, transport, min_ping, ping, addr_processed, addr_rate_limited, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_addr_relay_enabled, is_bip152_hb_from, is_bip152_hb_to, is_outbound, is_tx_relay});
539+ m_peers.push_back ({addr, sub_version, conn_type, NETWORK_SHORT_NAMES[network_id], age, services, transport, min_ping, ping, addr_processed, addr_rate_limited, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_addr_relay_enabled, is_bip152_hb_from, is_bip152_hb_to, is_outbound, is_tx_relay});
528540 m_max_addr_length = std::max (addr.length () + 1 , m_max_addr_length);
529541 m_max_addr_processed_length = std::max (ToString (addr_processed).length (), m_max_addr_processed_length);
530542 m_max_addr_rate_limited_length = std::max (ToString (addr_rate_limited).length (), m_max_addr_rate_limited_length);
531543 m_max_age_length = std::max (age.length (), m_max_age_length);
532544 m_max_id_length = std::max (ToString (peer_id).length (), m_max_id_length);
545+ m_max_services_length = std::max (services.length (), m_max_services_length);
533546 m_is_asmap_on |= (mapped_as != 0 );
534547 }
535548 }
@@ -540,7 +553,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
540553 // Report detailed peer connections list sorted by direction and minimum ping time.
541554 if (DetailsRequested () && !m_peers.empty ()) {
542555 std::sort (m_peers.begin (), m_peers.end ());
543- result += strprintf (" <-> type net v mping ping send recv txn blk hb %*s%*s%*s " ,
556+ result += strprintf (" <-> type net %*s v mping ping send recv txn blk hb %*s%*s%*s " ,
557+ m_max_services_length, " serv" ,
544558 m_max_addr_processed_length, " addrp" ,
545559 m_max_addr_rate_limited_length, " addrl" ,
546560 m_max_age_length, " age" );
@@ -549,10 +563,12 @@ class NetinfoRequestHandler : public BaseRequestHandler
549563 for (const Peer& peer : m_peers) {
550564 std::string version{ToString (peer.version ) + peer.sub_version };
551565 result += strprintf (
552- " %3s %6s %5s %2s%7s%7s%5s%5s%5s%5s %2s %*s%*s%*s%*i %*s %-*s%s\n " ,
566+ " %3s %6s %5s %*s % 2s%7s%7s%5s%5s%5s%5s %2s %*s%*s%*s%*i %*s %-*s%s\n " ,
553567 peer.is_outbound ? " out" : " in" ,
554568 ConnectionTypeForNetinfo (peer.conn_type ),
555569 peer.network ,
570+ m_max_services_length, // variable spacing
571+ peer.services ,
556572 (peer.transport_protocol_type .size () == 2 && peer.transport_protocol_type [0 ] == ' v' ) ? peer.transport_protocol_type [1 ] : ' ' ,
557573 PingTimeToString (peer.min_ping ),
558574 PingTimeToString (peer.ping ),
@@ -575,7 +591,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
575591 IsAddressSelected () ? peer.addr : " " ,
576592 IsVersionSelected () && version != " 0" ? version : " " );
577593 }
578- result += strprintf (" ms ms sec sec min min %*s\n\n " , m_max_age_length, " min" );
594+ result += strprintf (" %*s ms ms sec sec min min %*s\n\n " , m_max_services_length, " " , m_max_age_length, " min" );
579595 }
580596
581597 // Report peer connection totals by type.
@@ -663,6 +679,14 @@ class NetinfoRequestHandler : public BaseRequestHandler
663679 " \" feeler\" - short-lived connection for testing addresses\n "
664680 " \" addr\" - address fetch; short-lived connection for requesting addresses\n "
665681 " net Network the peer connected through (\" ipv4\" , \" ipv6\" , \" onion\" , \" i2p\" , \" cjdns\" , or \" npr\" (not publicly routable))\n "
682+ " serv Services offered by the peer\n "
683+ " \" n\" - NETWORK: peer can serve the full block chain\n "
684+ " \" b\" - BLOOM: peer can handle bloom-filtered connections (see BIP 111)\n "
685+ " \" w\" - WITNESS: peer can be asked for blocks and transactions with witness data (SegWit)\n "
686+ " \" c\" - COMPACT_FILTERS: peer can handle basic block filter requests (see BIPs 157 and 158)\n "
687+ " \" l\" - NETWORK_LIMITED: peer limited to serving only the last 288 blocks (~2 days)\n "
688+ " \" 2\" - P2P_V2: peer supports version 2 P2P transport protocol, as defined in BIP 324\n "
689+ " \" u\" - UNKNOWN: unrecognized bit flag\n "
666690 " v Version of transport protocol used for the connection\n "
667691 " mping Minimum observed ping time, in milliseconds (ms)\n "
668692 " ping Last observed ping time, in milliseconds (ms)\n "
0 commit comments