diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-12-20 08:55:55 -0800 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2011-12-20 08:55:55 -0800 |
commit | 387c8e3c5b1e00c6e9e57bfb069a6bfed09411d9 (patch) | |
tree | 714fbfb7eea626a1c921c0979fc1506c2fde726b /src/util.cpp | |
parent | 74f5435e104be76cd342a9a196ed4a10b8a7e248 (diff) | |
parent | 1c4aab926e0b25e0c896d4703d858eda1eb14ea5 (diff) |
Merge pull request #673 from mndrix/less-time-data
Store fewer time samples
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/util.cpp b/src/util.cpp index 80ce404593..a45ce33a1c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -31,7 +31,7 @@ string strMiscWarning; bool fTestNet = false; bool fNoListen = false; bool fLogTimestamps = false; - +CMedianFilter<int64> vTimeOffsets(200,0); @@ -941,15 +941,12 @@ void AddTimeData(unsigned int ip, int64 nTime) return; // Add data - static vector<int64> vTimeOffsets; - if (vTimeOffsets.empty()) - vTimeOffsets.push_back(0); - vTimeOffsets.push_back(nOffsetSample); - printf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), vTimeOffsets.back(), vTimeOffsets.back()/60); + vTimeOffsets.input(nOffsetSample); + printf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { - sort(vTimeOffsets.begin(), vTimeOffsets.end()); - int64 nMedian = vTimeOffsets[vTimeOffsets.size()/2]; + int64 nMedian = vTimeOffsets.median(); + std::vector<int64> vSorted = vTimeOffsets.sorted(); // Only let other nodes change our time by so much if (abs64(nMedian) < 70 * 60) { @@ -964,7 +961,7 @@ void AddTimeData(unsigned int ip, int64 nTime) { // If nobody has a time different than ours but within 5 minutes of ours, give a warning bool fMatch = false; - BOOST_FOREACH(int64 nOffset, vTimeOffsets) + BOOST_FOREACH(int64 nOffset, vSorted) if (nOffset != 0 && abs64(nOffset) < 5 * 60) fMatch = true; @@ -978,9 +975,12 @@ void AddTimeData(unsigned int ip, int64 nTime) } } } - BOOST_FOREACH(int64 n, vTimeOffsets) - printf("%+"PRI64d" ", n); - printf("| nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); + if (fDebug) { + BOOST_FOREACH(int64 n, vSorted) + printf("%+"PRI64d" ", n); + printf("| "); + } + printf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); } } |