| 460 | } |
| 461 | |
| 462 | UniValue ProcessReply(const UniValue& batch_in) override |
| 463 | { |
| 464 | const std::vector<UniValue> batch{JSONRPCProcessBatchReply(batch_in)}; |
| 465 | if (!batch[ID_PEERINFO]["error"].isNull()) return batch[ID_PEERINFO]; |
| 466 | if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO]; |
| 467 | |
| 468 | const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]}; |
| 469 | if (networkinfo["version"].get_int() < 209900) { |
| 470 | throw std::runtime_error("-netinfo requires bitcoind server to be running v0.21.0 and up"); |
| 471 | } |
| 472 | |
| 473 | // Count peer connection totals, and if DetailsRequested(), store peer data in a vector of structs. |
| 474 | for (const UniValue& peer : batch[ID_PEERINFO]["result"].getValues()) { |
| 475 | const std::string network{peer["network"].get_str()}; |
| 476 | const int8_t network_id{NetworkStringToId(network)}; |
| 477 | if (network_id == UNKNOWN_NETWORK) continue; |
| 478 | const bool is_outbound{!peer["inbound"].get_bool()}; |
| 479 | const bool is_block_relay{!peer["relaytxes"].get_bool()}; |
| 480 | const std::string conn_type{peer["connection_type"].get_str()}; |
| 481 | ++m_counts.at(is_outbound).at(network_id); // in/out by network |
| 482 | ++m_counts.at(is_outbound).at(NETWORKS.size()); // in/out overall |
| 483 | ++m_counts.at(2).at(network_id); // total by network |
| 484 | ++m_counts.at(2).at(NETWORKS.size()); // total overall |
| 485 | if (conn_type == "block-relay-only") ++m_block_relay_peers_count; |
| 486 | if (conn_type == "manual") ++m_manual_peers_count; |
| 487 | if (DetailsRequested()) { |
| 488 | // Push data for this peer to the peers vector. |
| 489 | const int peer_id{peer["id"].get_int()}; |
| 490 | const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].get_int()}; |
| 491 | const int version{peer["version"].get_int()}; |
| 492 | const int64_t addr_processed{peer["addr_processed"].isNull() ? 0 : peer["addr_processed"].get_int64()}; |
| 493 | const int64_t addr_rate_limited{peer["addr_rate_limited"].isNull() ? 0 : peer["addr_rate_limited"].get_int64()}; |
| 494 | const int64_t conn_time{peer["conntime"].get_int64()}; |
| 495 | const int64_t last_blck{peer["last_block"].get_int64()}; |
| 496 | const int64_t last_recv{peer["lastrecv"].get_int64()}; |
| 497 | const int64_t last_send{peer["lastsend"].get_int64()}; |
| 498 | const int64_t last_trxn{peer["last_transaction"].get_int64()}; |
| 499 | const double min_ping{peer["minping"].isNull() ? -1 : peer["minping"].get_real()}; |
| 500 | const double ping{peer["pingtime"].isNull() ? -1 : peer["pingtime"].get_real()}; |
| 501 | const std::string addr{peer["addr"].get_str()}; |
| 502 | const std::string age{conn_time == 0 ? "" : ToString((m_time_now - conn_time) / 60)}; |
| 503 | const std::string sub_version{peer["subver"].get_str()}; |
| 504 | const bool is_addr_relay_enabled{peer["addr_relay_enabled"].isNull() ? false : peer["addr_relay_enabled"].get_bool()}; |
| 505 | const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()}; |
| 506 | const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()}; |
| 507 | m_peers.push_back({addr, sub_version, conn_type, network, age, 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_block_relay, is_outbound}); |
| 508 | m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length); |
| 509 | m_max_addr_processed_length = std::max(ToString(addr_processed).length(), m_max_addr_processed_length); |
| 510 | m_max_addr_rate_limited_length = std::max(ToString(addr_rate_limited).length(), m_max_addr_rate_limited_length); |
| 511 | m_max_age_length = std::max(age.length(), m_max_age_length); |
| 512 | m_max_id_length = std::max(ToString(peer_id).length(), m_max_id_length); |
| 513 | m_is_asmap_on |= (mapped_as != 0); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | // Generate report header. |
| 518 | std::string result{strprintf("%s client %s%s - server %i%s\n\n", PACKAGE_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].get_int(), networkinfo["subversion"].get_str())}; |
| 519 |
nothing calls this directly
no test coverage detected