From f26502e9fc8a669b30717525597e3f468eaecf79 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Thu, 23 Jul 2020 15:34:40 +0100 Subject: [addrman] Specify max addresses and pct when calling GetAddresses() CAddrMan.GetAddr() would previously limit the number and percentage of addresses returned (to ADDRMAN_GETADDR_MAX (1000) and ADDRMAN_GETADDR_MAX_PCT (23) respectively). Instead, make it the callers responsibility to specify the maximum addresses and percentage they want returned. For net_processing, the maximums are MAX_ADDR_TO_SEND (1000) and MAX_PCT_ADDR_TO_SEND (23). For rpc/net, the maximum is specified by the client. --- src/net.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index 9c72c62df..931c08a71 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2528,9 +2528,9 @@ void CConnman::AddNewAddresses(const std::vector& vAddr, const CAddres addrman.Add(vAddr, addrFrom, nTimePenalty); } -std::vector CConnman::GetAddresses() +std::vector CConnman::GetAddresses(size_t max_addresses, size_t max_pct) { - std::vector addresses = addrman.GetAddr(); + std::vector addresses = addrman.GetAddr(max_addresses, max_pct); if (m_banman) { addresses.erase(std::remove_if(addresses.begin(), addresses.end(), [this](const CAddress& addr){return m_banman->IsDiscouraged(addr) || m_banman->IsBanned(addr);}), @@ -2539,12 +2539,12 @@ std::vector CConnman::GetAddresses() return addresses; } -std::vector CConnman::GetAddresses(Network requestor_network) +std::vector CConnman::GetAddresses(Network requestor_network, size_t max_addresses, size_t max_pct) { const auto current_time = GetTime(); if (m_addr_response_caches.find(requestor_network) == m_addr_response_caches.end() || m_addr_response_caches[requestor_network].m_update_addr_response < current_time) { - m_addr_response_caches[requestor_network].m_addrs_response_cache = GetAddresses(); + m_addr_response_caches[requestor_network].m_addrs_response_cache = GetAddresses(max_addresses, max_pct); m_addr_response_caches[requestor_network].m_update_addr_response = current_time + std::chrono::hours(21) + GetRandMillis(std::chrono::hours(6)); } return m_addr_response_caches[requestor_network].m_addrs_response_cache; -- cgit v1.2.3