| 504 | } |
| 505 | |
| 506 | UniValue ProcessReply(const UniValue &batch_in) override { |
| 507 | const std::vector<UniValue> batch{JSONRPCProcessBatchReply(batch_in)}; |
| 508 | if (!batch[ID_PEERINFO]["error"].isNull()) { |
| 509 | return batch[ID_PEERINFO]; |
| 510 | } |
| 511 | if (!batch[ID_NETWORKINFO]["error"].isNull()) { |
| 512 | return batch[ID_NETWORKINFO]; |
| 513 | } |
| 514 | |
| 515 | const UniValue &networkinfo{batch[ID_NETWORKINFO]["result"]}; |
| 516 | if (networkinfo["version"].getInt<int>() < 230000) { |
| 517 | throw std::runtime_error("-netinfo requires bitcoind server to be " |
| 518 | "running v0.23.0 and up"); |
| 519 | } |
| 520 | |
| 521 | // Count peer connection totals, and if DetailsRequested(), store peer |
| 522 | // data in a vector of structs. |
| 523 | for (const UniValue &peer : batch[ID_PEERINFO]["result"].getValues()) { |
| 524 | const std::string network{peer["network"].get_str()}; |
| 525 | const int8_t network_id{NetworkStringToId(network)}; |
| 526 | if (network_id == UNKNOWN_NETWORK) { |
| 527 | continue; |
| 528 | } |
| 529 | const bool is_outbound{!peer["inbound"].get_bool()}; |
| 530 | const bool is_block_relay{!peer["relaytxes"].get_bool()}; |
| 531 | // in/out by network |
| 532 | ++m_counts.at(is_outbound).at(network_id); |
| 533 | // in/out overall |
| 534 | ++m_counts.at(is_outbound).at(m_networks_size); |
| 535 | // total by network |
| 536 | ++m_counts.at(2).at(network_id); |
| 537 | // total overall |
| 538 | ++m_counts.at(2).at(m_networks_size); |
| 539 | if (is_block_relay) { |
| 540 | // in/out block-relay |
| 541 | ++m_counts.at(is_outbound).at(m_networks_size + 1); |
| 542 | // total block-relay |
| 543 | ++m_counts.at(2).at(m_networks_size + 1); |
| 544 | } |
| 545 | if (DetailsRequested()) { |
| 546 | // Push data for this peer to the peers vector. |
| 547 | const int peer_id{peer["id"].getInt<int>()}; |
| 548 | const int mapped_as{peer["mapped_as"].isNull() |
| 549 | ? 0 |
| 550 | : peer["mapped_as"].getInt<int>()}; |
| 551 | const int version{peer["version"].getInt<int>()}; |
| 552 | const int64_t conn_time{peer["conntime"].getInt<int64_t>()}; |
| 553 | const int64_t last_blck{peer["last_block"].getInt<int64_t>()}; |
| 554 | const int64_t last_recv{peer["lastrecv"].getInt<int64_t>()}; |
| 555 | const int64_t last_send{peer["lastsend"].getInt<int64_t>()}; |
| 556 | const int64_t last_trxn{ |
| 557 | peer["last_transaction"].getInt<int64_t>()}; |
| 558 | const double min_ping{ |
| 559 | peer["minping"].isNull() ? -1 : peer["minping"].get_real()}; |
| 560 | const double ping{peer["pingtime"].isNull() |
| 561 | ? -1 |
| 562 | : peer["pingtime"].get_real()}; |
| 563 | const std::string addr{peer["addr"].get_str()}; |
nothing calls this directly
no test coverage detected