@@ -320,6 +320,22 @@ class NetinfoRequestHandler : public BaseRequestHandler
320
320
ipv6,
321
321
onion,
322
322
};
323
+ struct Peer {
324
+ int id;
325
+ int mapped_as;
326
+ int version;
327
+ int64_t conn_time;
328
+ int64_t last_recv;
329
+ int64_t last_send;
330
+ double min_ping;
331
+ double ping;
332
+ std::string addr;
333
+ std::string sub_version;
334
+ NetType net_type;
335
+ bool is_block_relay;
336
+ bool is_outbound;
337
+ bool operator <(const Peer& rhs) const { return std::tie (is_outbound, min_ping) < std::tie (rhs.is_outbound , rhs.min_ping ); }
338
+ };
323
339
std::string NetTypeEnumToString (NetType t)
324
340
{
325
341
switch (t) {
@@ -357,9 +373,10 @@ class NetinfoRequestHandler : public BaseRequestHandler
357
373
if (!batch[ID_PEERINFO][" error" ].isNull ()) return batch[ID_PEERINFO];
358
374
if (!batch[ID_NETWORKINFO][" error" ].isNull ()) return batch[ID_NETWORKINFO];
359
375
360
- // Count peer connection totals.
376
+ // Count peer connection totals, and if m_verbose is true, store peer data in a vector of structs .
361
377
int ipv4_i{0 }, ipv6_i{0 }, onion_i{0 }, block_relay_i{0 }, total_i{0 }; // inbound conn counters
362
378
int ipv4_o{0 }, ipv6_o{0 }, onion_o{0 }, block_relay_o{0 }, total_o{0 }; // outbound conn counters
379
+ std::vector<Peer> peers;
363
380
const UniValue& getpeerinfo{batch[ID_PEERINFO][" result" ]};
364
381
365
382
for (const UniValue& peer : getpeerinfo.getValues ()) {
@@ -392,6 +409,18 @@ class NetinfoRequestHandler : public BaseRequestHandler
392
409
}
393
410
if (is_block_relay) ++block_relay_o;
394
411
}
412
+ if (m_verbose) {
413
+ // Push data for this peer to the peers vector.
414
+ const int peer_id{peer[" id" ].get_int ()};
415
+ const int version{peer[" version" ].get_int ()};
416
+ const std::string sub_version{peer[" subver" ].get_str ()};
417
+ const int64_t conn_time{peer[" conntime" ].get_int64 ()};
418
+ const int64_t last_recv{peer[" lastrecv" ].get_int64 ()};
419
+ const int64_t last_send{peer[" lastsend" ].get_int64 ()};
420
+ const double min_ping{peer[" minping" ].isNull () ? -1 : peer[" minping" ].get_real ()};
421
+ const double ping{peer[" pingtime" ].isNull () ? -1 : peer[" pingtime" ].get_real ()};
422
+ peers.push_back ({peer_id, mapped_as, version, conn_time, last_recv, last_send, min_ping, ping, addr, sub_version, net_type, is_block_relay, !is_inbound});
423
+ }
395
424
}
396
425
397
426
// Generate report header.
0 commit comments