@@ -94,6 +94,7 @@ const std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
9494
9595static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL ; // SHA256("netgroup")[0:8]
9696static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL ; // SHA256("localhostnonce")[0:8]
97+ static const uint64_t RANDOMIZER_ID_ADDRCACHE = 0x1cf2e4ddd306dda9ULL ; // SHA256("addrcache")[0:8]
9798//
9899// Global state variables
99100//
@@ -2539,12 +2540,19 @@ std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pc
25392540 return addresses;
25402541}
25412542
2542- std::vector<CAddress> CConnman::GetAddresses (Network requestor_network , size_t max_addresses, size_t max_pct)
2543+ std::vector<CAddress> CConnman::GetAddresses (CNode& requestor , size_t max_addresses, size_t max_pct)
25432544{
2545+ SOCKET socket;
2546+ WITH_LOCK (requestor.cs_hSocket , socket = requestor.hSocket );
2547+ auto local_socket_bytes = GetBindAddress (socket).GetAddrBytes ();
2548+ uint64_t cache_id = GetDeterministicRandomizer (RANDOMIZER_ID_ADDRCACHE)
2549+ .Write (requestor.addr .GetNetwork ())
2550+ .Write (local_socket_bytes.data (), local_socket_bytes.size ())
2551+ .Finalize ();
25442552 const auto current_time = GetTime<std::chrono::microseconds>();
2545- if (m_addr_response_caches.find (requestor_network ) == m_addr_response_caches.end () ||
2546- m_addr_response_caches[requestor_network ].m_update_addr_response < current_time) {
2547- m_addr_response_caches[requestor_network ].m_addrs_response_cache = GetAddresses (max_addresses, max_pct);
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);
25482556
25492557 // Choosing a proper cache lifetime is a trade-off between the privacy leak minimization
25502558 // and the usefulness of ADDR responses to honest users.
@@ -2570,9 +2578,9 @@ std::vector<CAddress> CConnman::GetAddresses(Network requestor_network, size_t m
25702578 // nodes to be "terrible" (see IsTerrible()) if the timestamps are older than 30 days,
25712579 // max. 24 hours of "penalty" due to cache shouldn't make any meaningful difference
25722580 // in terms of the freshness of the response.
2573- m_addr_response_caches[requestor_network ].m_update_addr_response = current_time + std::chrono::hours (21 ) + GetRandMillis (std::chrono::hours (6 ));
2581+ m_addr_response_caches[cache_id ].m_update_addr_response = current_time + std::chrono::hours (21 ) + GetRandMillis (std::chrono::hours (6 ));
25742582 }
2575- return m_addr_response_caches[requestor_network ].m_addrs_response_cache ;
2583+ return m_addr_response_caches[cache_id ].m_addrs_response_cache ;
25762584}
25772585
25782586bool CConnman::AddNode (const std::string& strNode)
0 commit comments