mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
refactor: Make FEELER_SLEEP_WINDOW type safe (std::chrono)
This commit is contained in:
10
src/net.cpp
10
src/net.cpp
@@ -86,8 +86,8 @@ static constexpr int DNSSEEDS_DELAY_PEER_THRESHOLD = 1000; // "many" vs "few" pe
|
||||
/** The default timeframe for -maxuploadtarget. 1 day. */
|
||||
static constexpr std::chrono::seconds MAX_UPLOAD_TIMEFRAME{60 * 60 * 24};
|
||||
|
||||
// We add a random period time (0 to 1 seconds) to feeler connections to prevent synchronization.
|
||||
#define FEELER_SLEEP_WINDOW 1
|
||||
// A random time period (0 to 1 seconds) is added to feeler connections to prevent synchronization.
|
||||
static constexpr auto FEELER_SLEEP_WINDOW{1s};
|
||||
|
||||
/** Used to pass flags to the Bind() function */
|
||||
enum BindFlags {
|
||||
@@ -1574,6 +1574,7 @@ int CConnman::GetExtraBlockRelayCount() const
|
||||
void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
{
|
||||
SetSyscallSandboxPolicy(SyscallSandboxPolicy::NET_OPEN_CONNECTION);
|
||||
FastRandomContext rng;
|
||||
// Connect to specific addresses
|
||||
if (!connect.empty())
|
||||
{
|
||||
@@ -1827,12 +1828,11 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
}
|
||||
|
||||
if (addrConnect.IsValid()) {
|
||||
|
||||
if (fFeeler) {
|
||||
// Add small amount of random noise before connection to avoid synchronization.
|
||||
int randsleep = GetRand<int>(FEELER_SLEEP_WINDOW * 1000);
|
||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(randsleep)))
|
||||
if (!interruptNet.sleep_for(rng.rand_uniform_duration<CThreadInterrupt::Clock>(FEELER_SLEEP_WINDOW))) {
|
||||
return;
|
||||
}
|
||||
LogPrint(BCLog::NET, "Making feeler connection to %s\n", addrConnect.ToString());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user