aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorGleb Naumenko <naumenko.gs@gmail.com>2020-08-11 13:39:56 +0300
committerGleb Naumenko <naumenko.gs@gmail.com>2020-09-02 10:33:17 +0300
commit83ad65f31b5c9441ae1618614082e584854a14e1 (patch)
tree84a31614121e669ba64148876c0d4dd5aade0312 /src/net.cpp
parent81b00f87800f40cb14f2131ff27668bd2bb9e551 (diff)
downloadbitcoin-83ad65f31b5c9441ae1618614082e584854a14e1.tar.xz
Address nits in ADDR caching
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/net.cpp b/src/net.cpp
index e43b480612..8ac45dbcb5 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2550,10 +2550,10 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
.Write(local_socket_bytes.data(), local_socket_bytes.size())
.Finalize();
const auto current_time = GetTime<std::chrono::microseconds>();
- if (m_addr_response_caches.find(cache_id) == m_addr_response_caches.end() ||
- m_addr_response_caches[cache_id].m_update_addr_response < current_time) {
- m_addr_response_caches[cache_id].m_addrs_response_cache = GetAddresses(max_addresses, max_pct);
-
+ auto r = m_addr_response_caches.emplace(cache_id, CachedAddrResponse{});
+ CachedAddrResponse& cache_entry = r.first->second;
+ if (cache_entry.m_cache_entry_expiration < current_time) { // If emplace() added new one it has expiration 0.
+ cache_entry.m_addrs_response_cache = GetAddresses(max_addresses, max_pct);
// Choosing a proper cache lifetime is a trade-off between the privacy leak minimization
// and the usefulness of ADDR responses to honest users.
//
@@ -2578,9 +2578,9 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
// nodes to be "terrible" (see IsTerrible()) if the timestamps are older than 30 days,
// max. 24 hours of "penalty" due to cache shouldn't make any meaningful difference
// in terms of the freshness of the response.
- m_addr_response_caches[cache_id].m_update_addr_response = current_time + std::chrono::hours(21) + GetRandMillis(std::chrono::hours(6));
+ cache_entry.m_cache_entry_expiration = current_time + std::chrono::hours(21) + GetRandMillis(std::chrono::hours(6));
}
- return m_addr_response_caches[cache_id].m_addrs_response_cache;
+ return cache_entry.m_addrs_response_cache;
}
bool CConnman::AddNode(const std::string& strNode)