5 #if defined(HAVE_CONFIG_H) 6 #include <config/bitcoin-config.h> 19 static int64_t nTimeOffset
GUARDED_BY(cs_nTimeOffset) = 0;
38 static uint64_t
abs64(int64_t n) {
39 const uint64_t un = n;
40 return (n >= 0) ? un : -un;
43 #define BITCOIN_TIMEDATA_MAX_SAMPLES 200 48 static std::set<CNetAddr> setKnown;
52 if (!setKnown.insert(ip).second) {
58 vTimeOffsets.
input(nOffsetSample);
60 "added time data, samples %d, offset %+d (%+d minutes)\n",
61 vTimeOffsets.
size(), nOffsetSample, nOffsetSample / 60);
80 if (vTimeOffsets.
size() >= 5 && vTimeOffsets.
size() % 2 == 1) {
81 int64_t nMedian = vTimeOffsets.
median();
82 std::vector<int64_t> vSorted = vTimeOffsets.
sorted();
85 uint64_t(std::max<int64_t>(
88 nTimeOffset = nMedian;
97 for (
const int64_t nOffset : vSorted) {
98 if (nOffset != 0 &&
abs64(nOffset) < 5 * 60) {
106 strprintf(
_(
"Please check that your computer's date " 107 "and time are correct! If your clock is " 108 "wrong, %s will not work properly."),
118 for (
const int64_t n : vSorted) {
124 nTimeOffset, nTimeOffset / 60);
#define LogPrint(category,...)
#define LogPrintToBeContinued
#define BITCOIN_TIMEDATA_MAX_SAMPLES
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are: ...
static RecursiveMutex cs_nTimeOffset
static int64_t nTimeOffset GUARDED_BY(cs_nTimeOffset)=0
bilingual_str _(const char *psz)
Translation function.
static bool LogAcceptCategory(BCLog::LogFlags category)
Return true if log accepts specified category.
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
int64_t GetAdjustedTime()
void SetMiscWarning(const std::string &strWarning)
CClientUIInterface uiInterface
void AddTimeData(const CNetAddr &ip, int64_t nOffsetSample)
int64_t GetTime()
Return system time (or mocked time, if set)
static const int64_t DEFAULT_MAX_TIME_ADJUSTMENT
static uint64_t abs64(int64_t n)