| 770 | } |
| 771 | |
| 772 | std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const |
| 773 | { |
| 774 | AssertLockHeld(cs); |
| 775 | |
| 776 | size_t nNodes = vRandom.size(); |
| 777 | if (max_pct != 0) { |
| 778 | nNodes = max_pct * nNodes / 100; |
| 779 | } |
| 780 | if (max_addresses != 0) { |
| 781 | nNodes = std::min(nNodes, max_addresses); |
| 782 | } |
| 783 | |
| 784 | // gather a list of random nodes, skipping those of low quality |
| 785 | const int64_t now{GetAdjustedTime()}; |
| 786 | std::vector<CAddress> addresses; |
| 787 | for (unsigned int n = 0; n < vRandom.size(); n++) { |
| 788 | if (addresses.size() >= nNodes) |
| 789 | break; |
| 790 | |
| 791 | int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n; |
| 792 | SwapRandom(n, nRndPos); |
| 793 | const auto it{mapInfo.find(vRandom[n])}; |
| 794 | assert(it != mapInfo.end()); |
| 795 | |
| 796 | const AddrInfo& ai{it->second}; |
| 797 | |
| 798 | // Filter by network (optional) |
| 799 | if (network != std::nullopt && ai.GetNetClass() != network) continue; |
| 800 | |
| 801 | // Filter for quality |
| 802 | if (ai.IsTerrible(now)) continue; |
| 803 | |
| 804 | addresses.push_back(ai); |
| 805 | } |
| 806 | LogPrint(BCLog::ADDRMAN, "GetAddr returned %d random addresses\n", addresses.size()); |
| 807 | return addresses; |
| 808 | } |
| 809 | |
| 810 | void AddrManImpl::Connected_(const CService& addr, int64_t nTime) |
| 811 | { |
nothing calls this directly
no test coverage detected