mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 03:33:32 +01:00
net, net_processing: use existing RNG objects more
PeerManagerImpl, as well as several net functions, already have existing FastRandomContext objects. Reuse them instead of constructing new ones.
This commit is contained in:
12
src/net.cpp
12
src/net.cpp
@@ -2481,9 +2481,9 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
auto start = GetTime<std::chrono::microseconds>();
|
||||
|
||||
// Minimum time before next feeler connection (in microseconds).
|
||||
auto next_feeler = start + FastRandomContext().rand_exp_duration(FEELER_INTERVAL);
|
||||
auto next_extra_block_relay = start + FastRandomContext().rand_exp_duration(EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
|
||||
auto next_extra_network_peer{start + FastRandomContext().rand_exp_duration(EXTRA_NETWORK_PEER_INTERVAL)};
|
||||
auto next_feeler = start + rng.rand_exp_duration(FEELER_INTERVAL);
|
||||
auto next_extra_block_relay = start + rng.rand_exp_duration(EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
|
||||
auto next_extra_network_peer{start + rng.rand_exp_duration(EXTRA_NETWORK_PEER_INTERVAL)};
|
||||
const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED);
|
||||
bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS);
|
||||
const bool use_seednodes{gArgs.IsArgSet("-seednode")};
|
||||
@@ -2642,10 +2642,10 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
// Because we can promote these connections to block-relay-only
|
||||
// connections, they do not get their own ConnectionType enum
|
||||
// (similar to how we deal with extra outbound peers).
|
||||
next_extra_block_relay = now + FastRandomContext().rand_exp_duration(EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
|
||||
next_extra_block_relay = now + rng.rand_exp_duration(EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
|
||||
conn_type = ConnectionType::BLOCK_RELAY;
|
||||
} else if (now > next_feeler) {
|
||||
next_feeler = now + FastRandomContext().rand_exp_duration(FEELER_INTERVAL);
|
||||
next_feeler = now + rng.rand_exp_duration(FEELER_INTERVAL);
|
||||
conn_type = ConnectionType::FEELER;
|
||||
fFeeler = true;
|
||||
} else if (nOutboundFullRelay == m_max_outbound_full_relay &&
|
||||
@@ -2658,7 +2658,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
// This is not attempted if the user changed -maxconnections to a value
|
||||
// so low that less than MAX_OUTBOUND_FULL_RELAY_CONNECTIONS are made,
|
||||
// to prevent interactions with otherwise protected outbound peers.
|
||||
next_extra_network_peer = now + FastRandomContext().rand_exp_duration(EXTRA_NETWORK_PEER_INTERVAL);
|
||||
next_extra_network_peer = now + rng.rand_exp_duration(EXTRA_NETWORK_PEER_INTERVAL);
|
||||
} else {
|
||||
// skip to next iteration of while loop
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user