aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordergoegge <n.goeggi@gmail.com>2023-10-02 14:13:05 +0100
committerdergoegge <n.goeggi@gmail.com>2023-10-03 11:23:24 +0100
commita648dd79e5ebfdb627d0221b1207862efb664dfc (patch)
tree72adadb7bef74573d2a8a940554b8e5702dd7d38 /src
parent87c706713e5d1c78bad943a42bf7c69047d28ea5 (diff)
downloadbitcoin-a648dd79e5ebfdb627d0221b1207862efb664dfc.tar.xz
[net processing] PushAddress uses PeerManager's rng
Diffstat (limited to 'src')
-rw-r--r--src/net_processing.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 8963424c9b..77d7f168bf 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1022,7 +1022,7 @@ private:
bool SetupAddressRelay(const CNode& node, Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
void AddAddressKnown(Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
- void PushAddress(Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
+ void PushAddress(Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
};
const CNodeState* PeerManagerImpl::State(NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@@ -1054,7 +1054,7 @@ void PeerManagerImpl::AddAddressKnown(Peer& peer, const CAddress& addr)
peer.m_addr_known->insert(addr.GetKey());
}
-void PeerManagerImpl::PushAddress(Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand)
+void PeerManagerImpl::PushAddress(Peer& peer, const CAddress& addr)
{
// Known checking here is only to save space from duplicates.
// Before sending, we'll filter it again for known addresses that were
@@ -1062,7 +1062,7 @@ void PeerManagerImpl::PushAddress(Peer& peer, const CAddress& addr, FastRandomCo
assert(peer.m_addr_known);
if (addr.IsValid() && !peer.m_addr_known->contains(addr.GetKey()) && IsAddrCompatible(peer, addr)) {
if (peer.m_addrs_to_send.size() >= MAX_ADDR_TO_SEND) {
- peer.m_addrs_to_send[insecure_rand.randrange(peer.m_addrs_to_send.size())] = addr;
+ peer.m_addrs_to_send[m_rng.randrange(peer.m_addrs_to_send.size())] = addr;
} else {
peer.m_addrs_to_send.push_back(addr);
}
@@ -2108,7 +2108,6 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
const CSipHasher hasher{m_connman.GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY)
.Write(hash_addr)
.Write(time_addr)};
- FastRandomContext insecure_rand;
// Relay reachable addresses to 2 peers. Unreachable addresses are relayed randomly to 1 or 2 peers.
unsigned int nRelayNodes = (fReachable || (hasher.Finalize() & 1)) ? 2 : 1;
@@ -2132,7 +2131,7 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
};
for (unsigned int i = 0; i < nRelayNodes && best[i].first != 0; i++) {
- PushAddress(*best[i].second, addr, insecure_rand);
+ PushAddress(*best[i].second, addr);
}
}
@@ -4657,9 +4656,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
} else {
vAddr = m_connman.GetAddresses(pfrom, MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND);
}
- FastRandomContext insecure_rand;
for (const CAddress &addr : vAddr) {
- PushAddress(*peer, addr, insecure_rand);
+ PushAddress(*peer, addr);
}
return;
}
@@ -5261,8 +5259,7 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::micros
}
if (std::optional<CService> local_service = GetLocalAddrForPeer(node)) {
CAddress local_addr{*local_service, peer.m_our_services, Now<NodeSeconds>()};
- FastRandomContext insecure_rand;
- PushAddress(peer, local_addr, insecure_rand);
+ PushAddress(peer, local_addr);
}
peer.m_next_local_addr_send = GetExponentialRand(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
}