Changeset View
Changeset View
Standalone View
Standalone View
src/randomenv.cpp
Show All 13 Lines | |||||
#include <crypto/sha512.h> | #include <crypto/sha512.h> | ||||
#include <support/cleanse.h> | #include <support/cleanse.h> | ||||
#include <util/time.h> // for GetTime() | #include <util/time.h> // for GetTime() | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
#include <compat.h> // for Windows API | #include <compat.h> // for Windows API | ||||
#endif | #endif | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <atomic> | |||||
#include <chrono> | #include <chrono> | ||||
#include <climits> | #include <climits> | ||||
#include <thread> | #include <thread> | ||||
#include <vector> | #include <vector> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <cstring> | #include <cstring> | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
Show All 37 Lines | |||||
namespace { | namespace { | ||||
void RandAddSeedPerfmon(CSHA512 &hasher) { | void RandAddSeedPerfmon(CSHA512 &hasher) { | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
// Don't need this on Linux, OpenSSL automatically uses /dev/urandom | // Don't need this on Linux, OpenSSL automatically uses /dev/urandom | ||||
// Seed with the entire set of perfmon data | // Seed with the entire set of perfmon data | ||||
// This can take up to 2 seconds, so only do it every 10 minutes | // This can take up to 2 seconds, so only do it every 10 minutes | ||||
static int64_t nLastPerfmon; | static std::atomic<std::chrono::seconds> last_perfmon{ | ||||
if (GetTime() < nLastPerfmon + 10 * 60) { | std::chrono::seconds{0}}; | ||||
auto last_time = last_perfmon.load(); | |||||
auto current_time = GetTime<std::chrono::seconds>(); | |||||
if (current_time < last_time + std::chrono::minutes{10}) { | |||||
return; | return; | ||||
} | } | ||||
nLastPerfmon = GetTime(); | last_perfmon = current_time; | ||||
std::vector<uint8_t> vData(250000, 0); | std::vector<uint8_t> vData(250000, 0); | ||||
long ret = 0; | long ret = 0; | ||||
unsigned long nSize = 0; | unsigned long nSize = 0; | ||||
// Bail out at more than 10MB of performance data | // Bail out at more than 10MB of performance data | ||||
const size_t nMaxSize = 10000000; | const size_t nMaxSize = 10000000; | ||||
while (true) { | while (true) { | ||||
nSize = vData.size(); | nSize = vData.size(); | ||||
▲ Show 20 Lines • Show All 461 Lines • Show Last 20 Lines |