mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
[move] Move PoissonNextSend to src/random and update comment
PoissonNextSend is used by net and net_processing and is stateless, so place it in the utility random.cpp translation unit.
This commit is contained in:
committed by
Martin Zumsande
parent
801aaac2b3
commit
9e64d69bf7
14
src/random.h
14
src/random.h
@@ -10,7 +10,7 @@
|
||||
#include <crypto/common.h>
|
||||
#include <uint256.h>
|
||||
|
||||
#include <chrono> // For std::chrono::microseconds
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
@@ -82,6 +82,18 @@ D GetRandomDuration(typename std::common_type<D>::type max) noexcept
|
||||
};
|
||||
constexpr auto GetRandMicros = GetRandomDuration<std::chrono::microseconds>;
|
||||
constexpr auto GetRandMillis = GetRandomDuration<std::chrono::milliseconds>;
|
||||
|
||||
/**
|
||||
* Return a timestamp in the future sampled from an exponential distribution
|
||||
* (https://en.wikipedia.org/wiki/Exponential_distribution). This distribution
|
||||
* is memoryless and should be used for repeated network events (e.g. sending a
|
||||
* certain type of message) to minimize leaking information to observers.
|
||||
*
|
||||
* The probability of an event occuring before time x is 1 - e^-(x/a) where a
|
||||
* is the average interval between events.
|
||||
* */
|
||||
std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval);
|
||||
|
||||
int GetRandInt(int nMax) noexcept;
|
||||
uint256 GetRandHash() noexcept;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user