Skip to content

Commit d3f77b7

Browse files
committed
cli: create inbound/outbound peer connections report
1 parent 19377b2 commit d3f77b7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/bitcoin-cli.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
344344
if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO];
345345

346346
// Count peer connection totals.
347-
int ipv4_i{0}, ipv6_i{0}, onion_i{0}, block_relay_i{0}; // inbound conn counters
348-
int ipv4_o{0}, ipv6_o{0}, onion_o{0}, block_relay_o{0}; // outbound conn counters
347+
int ipv4_i{0}, ipv6_i{0}, onion_i{0}, block_relay_i{0}, total_i{0}; // inbound conn counters
348+
int ipv4_o{0}, ipv6_o{0}, onion_o{0}, block_relay_o{0}, total_o{0}; // outbound conn counters
349349
const UniValue& getpeerinfo{batch[ID_PEERINFO]["result"]};
350350

351351
for (const UniValue& peer : getpeerinfo.getValues()) {
@@ -379,6 +379,14 @@ class NetinfoRequestHandler : public BaseRequestHandler
379379
const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]};
380380
std::string result{strprintf("%s %s%s - %i%s\n\n", PACKAGE_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].get_int(), networkinfo["subversion"].get_str())};
381381

382+
// Report peer connection totals by type.
383+
total_i = ipv4_i + ipv6_i + onion_i;
384+
total_o = ipv4_o + ipv6_o + onion_o;
385+
result += " ipv4 ipv6 onion total block-relay\n";
386+
result += strprintf("in %5i %5i %5i %5i %5i\n", ipv4_i, ipv6_i, onion_i, total_i, block_relay_i);
387+
result += strprintf("out %5i %5i %5i %5i %5i\n", ipv4_o, ipv6_o, onion_o, total_o, block_relay_o);
388+
result += strprintf("total %5i %5i %5i %5i %5i\n", ipv4_i + ipv4_o, ipv6_i + ipv6_o, onion_i + onion_o, total_i + total_o, block_relay_i + block_relay_o);
389+
382390
return JSONRPCReplyObj(UniValue{result}, NullUniValue, 1);
383391
}
384392
};

0 commit comments

Comments
 (0)