From 3851960576a8553696cacc6ad236ec4a85b7135e Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 16 Feb 2025 11:25:43 -0600 Subject: [PATCH 1/2] netinfo: return local services in the default report --- src/bitcoin-cli.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 75911d00874..4e3a748aff8 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -481,6 +481,16 @@ private: } return str; } + std::string ServicesList(const UniValue& services) + { + std::vector v; + for (size_t i = 0; i < services.size(); ++i) { + std::string s{ToLower((services[i].get_str()))}; + std::ranges::replace(s, '_', ' '); + v.push_back(s); + } + return Join(v, ", "); + } public: static constexpr int ID_PEERINFO = 0; @@ -654,6 +664,7 @@ public: } // Report local addresses, ports, and scores. + result += strprintf("\n\nLocal services: %s", ServicesList(networkinfo["localservicesnames"])); result += "\n\nLocal addresses"; const std::vector& local_addrs{networkinfo["localaddresses"].getValues()}; if (local_addrs.empty()) { From 724546e28a5778e1c3f5100406ed7237f76aab55 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 16 Feb 2025 09:22:46 -0600 Subject: [PATCH 2/2] netinfo: return shortened services, if peers list requested When the detailed peers list is requested, return the shortened services in the -netinfo header in the same format as the "serv" column, instead of the full names list in the report. --- src/bitcoin-cli.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 4e3a748aff8..e51d4a3c65f 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -582,7 +582,8 @@ public: } // Generate report header. - std::string result{strprintf("%s client %s%s - server %i%s\n\n", CLIENT_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].getInt(), networkinfo["subversion"].get_str())}; + const std::string_view services{DetailsRequested() ? strprintf(" - services %s", FormatServices(networkinfo["localservicesnames"])) : ""}; + std::string result{strprintf("%s client %s%s - server %i%s%s\n\n", CLIENT_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].getInt(), networkinfo["subversion"].get_str(), services)}; // Report detailed peer connections list sorted by direction and minimum ping time. if (DetailsRequested() && !m_peers.empty()) { @@ -664,7 +665,9 @@ public: } // Report local addresses, ports, and scores. - result += strprintf("\n\nLocal services: %s", ServicesList(networkinfo["localservicesnames"])); + if (!DetailsRequested()) { + result += strprintf("\n\nLocal services: %s", ServicesList(networkinfo["localservicesnames"])); + } result += "\n\nLocal addresses"; const std::vector& local_addrs{networkinfo["localaddresses"].getValues()}; if (local_addrs.empty()) {