Skip to content

Commit

Permalink
Improve timedata logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Remapper authored Dec 16, 2019
1 parent 88a21e6 commit ea7c594
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/timedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ static int64_t abs64(int64_t n)
return (n >= 0 ? n : -n);
}

#define XBI_TIMEDATA_MAX_SAMPLES 200

void AddTimeData(const CNetAddr& ip, int64_t nTime)
{
int64_t nOffsetSample = nTime - GetTime();

LOCK(cs_nTimeOffset);
// Ignore duplicates
static set<CNetAddr> setKnown;
if (setKnown.size() == XBI_TIMEDATA_MAX_SAMPLES)
return;
if (!setKnown.insert(ip).second)
return;

// Add data
static CMedianFilter<int64_t> vTimeOffsets(200, 0);
static CMedianFilter<int64_t> vTimeOffsets(XBI_TIMEDATA_MAX_SAMPLES, 0);
vTimeOffsets.input(nOffsetSample);
LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample / 60);

Expand Down

0 comments on commit ea7c594

Please sign in to comment.