5 #if defined(HAVE_CONFIG_H)
6 #include "config/bitcoin-config.h"
18 #include <boost/foreach.hpp>
21 static int64_t nTimeOffset = 0;
41 static int64_t abs64(int64_t n)
43 return (n >= 0 ? n : -n);
46 #define BITCOIN_TIMEDATA_MAX_SAMPLES 200
52 static std::set<CNetAddr> setKnown;
55 if (!setKnown.insert(ip).second)
60 vTimeOffsets.
input(nOffsetSample);
61 LogPrint(
"net",
"added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.
size(), nOffsetSample, nOffsetSample/60);
80 if (vTimeOffsets.
size() >= 5 && vTimeOffsets.
size() % 2 == 1)
82 int64_t nMedian = vTimeOffsets.
median();
83 std::vector<int64_t> vSorted = vTimeOffsets.
sorted();
85 if (abs64(nMedian) <= std::max<int64_t>(0,
GetArg(
"-maxtimeadjustment", DEFAULT_MAX_TIME_ADJUSTMENT)))
87 nTimeOffset = nMedian;
98 BOOST_FOREACH(int64_t nOffset, vSorted)
99 if (nOffset != 0 && abs64(nOffset) < 5 * 60)
105 std::string strMessage =
strprintf(
_(
"Please check that your computer's date and time are correct! If your clock is wrong, %s will not work properly."),
_(PACKAGE_NAME));
112 BOOST_FOREACH(int64_t n, vSorted)
116 LogPrint(
"net",
"nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60);
boost::signals2::signal< bool(const std::string &message, const std::string &caption, unsigned int style), boost::signals2::last_value< bool > > ThreadSafeMessageBox
Show message box.
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
int64_t GetAdjustedTime()
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are:
#define BITCOIN_TIMEDATA_MAX_SAMPLES
void AddTimeData(const CNetAddr &ip, int64_t nOffsetSample)
CClientUIInterface uiInterface
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
#define LogPrint(category,...)
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
int64_t GetTime()
GetTimeMicros() and GetTimeMillis() both return the system time, but in different units.
void SetMiscWarning(const std::string &strWarning)