Changeset View
Changeset View
Standalone View
Standalone View
src/timedata.cpp
Show All 29 Lines | int64_t GetTimeOffset() { | ||||
LOCK(cs_nTimeOffset); | LOCK(cs_nTimeOffset); | ||||
return nTimeOffset; | return nTimeOffset; | ||||
} | } | ||||
int64_t GetAdjustedTime() { | int64_t GetAdjustedTime() { | ||||
return GetTime() + GetTimeOffset(); | return GetTime() + GetTimeOffset(); | ||||
} | } | ||||
static int64_t abs64(int64_t n) { | static uint64_t abs64(int64_t n) { | ||||
return (n >= 0 ? n : -n); | const uint64_t un = n; | ||||
return (n >= 0) ? un : -un; | |||||
} | } | ||||
#define BITCOIN_TIMEDATA_MAX_SAMPLES 200 | #define BITCOIN_TIMEDATA_MAX_SAMPLES 200 | ||||
void AddTimeData(const CNetAddr &ip, int64_t nOffsetSample) { | void AddTimeData(const CNetAddr &ip, int64_t nOffsetSample) { | ||||
LOCK(cs_nTimeOffset); | LOCK(cs_nTimeOffset); | ||||
// Ignore duplicates | // Ignore duplicates | ||||
static std::set<CNetAddr> setKnown; | static std::set<CNetAddr> setKnown; | ||||
Show All 28 Lines | void AddTimeData(const CNetAddr &ip, int64_t nOffsetSample) { | ||||
// So we should hold off on fixing this and clean it up as part of a timing | // So we should hold off on fixing this and clean it up as part of a timing | ||||
// cleanup that strengthens it in a number of other ways. | // cleanup that strengthens it in a number of other ways. | ||||
// | // | ||||
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { | if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { | ||||
int64_t nMedian = vTimeOffsets.median(); | int64_t nMedian = vTimeOffsets.median(); | ||||
std::vector<int64_t> vSorted = vTimeOffsets.sorted(); | std::vector<int64_t> vSorted = vTimeOffsets.sorted(); | ||||
// Only let other nodes change our time by so much | // Only let other nodes change our time by so much | ||||
if (abs64(nMedian) <= | if (abs64(nMedian) <= | ||||
std::max<int64_t>(0, gArgs.GetArg("-maxtimeadjustment", | uint64_t(std::max<int64_t>( | ||||
DEFAULT_MAX_TIME_ADJUSTMENT))) { | 0, gArgs.GetArg("-maxtimeadjustment", | ||||
DEFAULT_MAX_TIME_ADJUSTMENT)))) { | |||||
nTimeOffset = nMedian; | nTimeOffset = nMedian; | ||||
} else { | } else { | ||||
nTimeOffset = 0; | nTimeOffset = 0; | ||||
static bool fDone; | static bool fDone; | ||||
if (!fDone) { | if (!fDone) { | ||||
// If nobody has a time different than ours but within 5 minutes | // If nobody has a time different than ours but within 5 minutes | ||||
// of ours, give a warning | // of ours, give a warning | ||||
Show All 32 Lines |