@@ -2550,10 +2550,10 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
2550
2550
.Write (local_socket_bytes.data (), local_socket_bytes.size ())
2551
2551
.Finalize ();
2552
2552
const auto current_time = GetTime<std::chrono::microseconds>();
2553
- if (m_addr_response_caches. find (cache_id) == m_addr_response_caches.end () ||
2554
- m_addr_response_caches[cache_id]. m_update_addr_response < current_time) {
2555
- m_addr_response_caches[cache_id]. m_addrs_response_cache = GetAddresses (max_addresses, max_pct);
2556
-
2553
+ auto r = m_addr_response_caches.emplace (cache_id, CachedAddrResponse{});
2554
+ CachedAddrResponse& cache_entry = r. first -> second ;
2555
+ if (cache_entry. m_cache_entry_expiration < current_time) { // If emplace() added new one it has expiration 0.
2556
+ cache_entry. m_addrs_response_cache = GetAddresses (max_addresses, max_pct);
2557
2557
// Choosing a proper cache lifetime is a trade-off between the privacy leak minimization
2558
2558
// and the usefulness of ADDR responses to honest users.
2559
2559
//
@@ -2578,9 +2578,9 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
2578
2578
// nodes to be "terrible" (see IsTerrible()) if the timestamps are older than 30 days,
2579
2579
// max. 24 hours of "penalty" due to cache shouldn't make any meaningful difference
2580
2580
// in terms of the freshness of the response.
2581
- m_addr_response_caches[cache_id]. m_update_addr_response = current_time + std::chrono::hours (21 ) + GetRandMillis (std::chrono::hours (6 ));
2581
+ cache_entry. m_cache_entry_expiration = current_time + std::chrono::hours (21 ) + GetRandMillis (std::chrono::hours (6 ));
2582
2582
}
2583
- return m_addr_response_caches[cache_id] .m_addrs_response_cache ;
2583
+ return cache_entry .m_addrs_response_cache ;
2584
2584
}
2585
2585
2586
2586
bool CConnman::AddNode (const std::string& strNode)
0 commit comments