diff options
author | Gleb Naumenko <naumenko.gs@gmail.com> | 2020-05-16 21:05:44 -0400 |
---|---|---|
committer | Gleb Naumenko <naumenko.gs@gmail.com> | 2020-07-30 14:38:48 +0300 |
commit | acd6135b43941fa51d52f5fcdb2ce944280ad01e (patch) | |
tree | 4d49cad92bd7a620e2b48fee2ad5b29201aade63 /src/net.cpp | |
parent | 7cc0e8101f01891aa8be093a00d993bb7579c385 (diff) |
Cache responses to addr requests
Prevents a spy from scraping victim's AddrMan by
reconnecting and re-requesting addrs.
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index 171358bb5f..bf29d928a1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2539,6 +2539,17 @@ std::vector<CAddress> CConnman::GetAddresses() return addresses; } +std::vector<CAddress> CConnman::GetAddresses(Network requestor_network) +{ + const auto current_time = GetTime<std::chrono::microseconds>(); + 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_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; +} + bool CConnman::AddNode(const std::string& strNode) { LOCK(cs_vAddedNodes); |