6 #if defined(HAVE_CONFIG_H)
21 static int64_t nTimeOffset = 0;
41 #define BITCOIN_TIMEDATA_MAX_SAMPLES 200
47 static std::set<CNetAddr> setKnown;
50 if (!
Params().IsRegTestNet() && !setKnown.insert(
ip).second)
55 vTimeOffsets.
input(nOffsetSample);
56 LogPrintf(
"Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.
size(), nOffsetSample, nOffsetSample / 60);
75 if (vTimeOffsets.
size() >= 5 && vTimeOffsets.
size() % 2 == 1) {
76 int64_t nMedian = vTimeOffsets.
median();
77 std::vector<int64_t> vSorted = vTimeOffsets.
sorted();
79 if (
abs64(nMedian) < nOffsetLimit) {
80 nTimeOffset = nMedian;
83 nTimeOffset = (nMedian > 0 ? 1 : -1) * nOffsetLimit;
84 std::string strMessage =
strprintf(
_(
"Warning: Please check that your computer's date and time are correct! If your clock is wrong %s will not work properly."),
PACKAGE_NAME);
86 LogPrintf(
"*** %s\n", strMessage);
90 for (int64_t n : vSorted)
94 LogPrintf(
"nTimeOffset = %+d\n", nTimeOffset);
103 return (nTime / slotLen) * slotLen;
const CChainParams & Params()
Return the currently selected parameters.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
bool DefaultShrinkDebugFile() const
const Consensus::Params & GetConsensus() const
boost::signals2::signal< bool(const std::string &message, const std::string &caption, unsigned int style), boost::signals2::last_value< bool > > ThreadSafeMessageBox
Show message box.
CClientUIInterface uiInterface
BCLog::Logger *const g_logger
NOTE: the logger instances is leaked on exit.
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
int64_t GetAdjustedTime()
int64_t GetCurrentTimeSlot()
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are:
#define BITCOIN_TIMEDATA_MAX_SAMPLES
int64_t GetTimeSlot(const int64_t nTime)
void AddTimeData(const CNetAddr &ip, int64_t nOffsetSample, int nOffsetLimit)
int64_t abs64(int64_t n)
Functions to keep track of adjusted P2P time.
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
void SetMiscWarning(const std::string &strWarning)