Skip to content

Commit a648dd7

Browse files
committed
[net processing] PushAddress uses PeerManager's rng
1 parent 87c7067 commit a648dd7

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/net_processing.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ class PeerManagerImpl final : public PeerManager
10221022
bool SetupAddressRelay(const CNode& node, Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
10231023

10241024
void AddAddressKnown(Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1025-
void PushAddress(Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1025+
void PushAddress(Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
10261026
};
10271027

10281028
const CNodeState* PeerManagerImpl::State(NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@@ -1054,15 +1054,15 @@ void PeerManagerImpl::AddAddressKnown(Peer& peer, const CAddress& addr)
10541054
peer.m_addr_known->insert(addr.GetKey());
10551055
}
10561056

1057-
void PeerManagerImpl::PushAddress(Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand)
1057+
void PeerManagerImpl::PushAddress(Peer& peer, const CAddress& addr)
10581058
{
10591059
// Known checking here is only to save space from duplicates.
10601060
// Before sending, we'll filter it again for known addresses that were
10611061
// added after addresses were pushed.
10621062
assert(peer.m_addr_known);
10631063
if (addr.IsValid() && !peer.m_addr_known->contains(addr.GetKey()) && IsAddrCompatible(peer, addr)) {
10641064
if (peer.m_addrs_to_send.size() >= MAX_ADDR_TO_SEND) {
1065-
peer.m_addrs_to_send[insecure_rand.randrange(peer.m_addrs_to_send.size())] = addr;
1065+
peer.m_addrs_to_send[m_rng.randrange(peer.m_addrs_to_send.size())] = addr;
10661066
} else {
10671067
peer.m_addrs_to_send.push_back(addr);
10681068
}
@@ -2108,7 +2108,6 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
21082108
const CSipHasher hasher{m_connman.GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY)
21092109
.Write(hash_addr)
21102110
.Write(time_addr)};
2111-
FastRandomContext insecure_rand;
21122111

21132112
// Relay reachable addresses to 2 peers. Unreachable addresses are relayed randomly to 1 or 2 peers.
21142113
unsigned int nRelayNodes = (fReachable || (hasher.Finalize() & 1)) ? 2 : 1;
@@ -2132,7 +2131,7 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
21322131
};
21332132

21342133
for (unsigned int i = 0; i < nRelayNodes && best[i].first != 0; i++) {
2135-
PushAddress(*best[i].second, addr, insecure_rand);
2134+
PushAddress(*best[i].second, addr);
21362135
}
21372136
}
21382137

@@ -4657,9 +4656,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
46574656
} else {
46584657
vAddr = m_connman.GetAddresses(pfrom, MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND);
46594658
}
4660-
FastRandomContext insecure_rand;
46614659
for (const CAddress &addr : vAddr) {
4662-
PushAddress(*peer, addr, insecure_rand);
4660+
PushAddress(*peer, addr);
46634661
}
46644662
return;
46654663
}
@@ -5261,8 +5259,7 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::micros
52615259
}
52625260
if (std::optional<CService> local_service = GetLocalAddrForPeer(node)) {
52635261
CAddress local_addr{*local_service, peer.m_our_services, Now<NodeSeconds>()};
5264-
FastRandomContext insecure_rand;
5265-
PushAddress(peer, local_addr, insecure_rand);
5262+
PushAddress(peer, local_addr);
52665263
}
52675264
peer.m_next_local_addr_send = GetExponentialRand(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
52685265
}

0 commit comments

Comments
 (0)