aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorGleb Naumenko <naumenko.gs@gmail.com>2020-04-14 21:02:43 -0400
committerJon Atack <jon@atack.com>2022-03-13 16:40:36 +0100
commit77ccb7fce15e340080f14c7626cf3dc63fcdee88 (patch)
tree60107b533ae4e01c326df7df496afa0a74be995b /src/net_processing.cpp
parente04720ec3336e3df7fce522e3b1da972aa65ff62 (diff)
downloadbitcoin-77ccb7fce15e340080f14c7626cf3dc63fcdee88.tar.xz
Use std::chrono for salting when randomizing ADDR destination
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 59cd83e493..e78f136ec2 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -134,6 +134,8 @@ static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
static constexpr auto AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL{24h};
/** Average delay between peer address broadcasts */
static constexpr auto AVG_ADDRESS_BROADCAST_INTERVAL{30s};
+/** Delay between rotating the peers we relay a particular address to */
+static constexpr auto ROTATE_ADDR_RELAY_DEST_INTERVAL{24h};
/** Average delay between trickled inventory transmissions for inbound peers.
* Blocks and peers with NetPermissionFlags::NoBan permission bypass this. */
static constexpr auto INBOUND_INVENTORY_BROADCAST_INTERVAL{5s};
@@ -1776,9 +1778,12 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
// Use deterministic randomness to send to the same nodes for 24 hours
// at a time so the m_addr_knowns of the chosen nodes prevent repeats
const uint64_t hash_addr{CServiceHash(0, 0)(addr)};
+ const auto current_time{GetTime<std::chrono::seconds>()};
+ // Adding address hash makes exact rotation time different per address, while preserving periodicity.
+ const uint64_t time_addr{(static_cast<uint64_t>(count_seconds(current_time)) + hash_addr) / count_seconds(ROTATE_ADDR_RELAY_DEST_INTERVAL)};
const CSipHasher hasher{m_connman.GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY)
.Write(hash_addr)
- .Write((GetTime() + hash_addr) / (24 * 60 * 60))};
+ .Write(time_addr)};
FastRandomContext insecure_rand;
// Relay reachable addresses to 2 peers. Unreachable addresses are relayed randomly to 1 or 2 peers.