@@ -94,6 +94,7 @@ const std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
94
94
95
95
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL ; // SHA256("netgroup")[0:8]
96
96
static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL ; // SHA256("localhostnonce")[0:8]
97
+ static const uint64_t RANDOMIZER_ID_ADDRCACHE = 0x1cf2e4ddd306dda9ULL ; // SHA256("addrcache")[0:8]
97
98
//
98
99
// Global state variables
99
100
//
@@ -2539,12 +2540,19 @@ std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pc
2539
2540
return addresses;
2540
2541
}
2541
2542
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)
2543
2544
{
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 ();
2544
2552
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);
2548
2556
2549
2557
// Choosing a proper cache lifetime is a trade-off between the privacy leak minimization
2550
2558
// and the usefulness of ADDR responses to honest users.
@@ -2570,9 +2578,9 @@ std::vector<CAddress> CConnman::GetAddresses(Network requestor_network, size_t m
2570
2578
// nodes to be "terrible" (see IsTerrible()) if the timestamps are older than 30 days,
2571
2579
// max. 24 hours of "penalty" due to cache shouldn't make any meaningful difference
2572
2580
// 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 ));
2574
2582
}
2575
- return m_addr_response_caches[requestor_network ].m_addrs_response_cache ;
2583
+ return m_addr_response_caches[cache_id ].m_addrs_response_cache ;
2576
2584
}
2577
2585
2578
2586
bool CConnman::AddNode (const std::string& strNode)
0 commit comments