aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-06-19 15:08:37 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-06-25 09:24:50 +0200
commit14f888ca804386b111b07e8988753d67f507ba30 (patch)
tree22193675a85be98cbc9030d973a388834803b80a /src/util.cpp
parent208bf5b9e0a86900bddf5722dc192c3262480e36 (diff)
Move network-time related functions to timedata.cpp/h
The network time-offset-mangement functions from util.cpp are moved to timedata.(cpp|h). This breaks the dependency of util on netbase.
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 30590912ff..a19c015da6 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -6,7 +6,6 @@
#include "util.h"
#include "chainparams.h"
-#include "netbase.h"
#include "sync.h"
#include "ui_interface.h"
#include "uint256.h"
@@ -1157,13 +1156,6 @@ void ShrinkDebugFile()
fclose(file);
}
-//
-// "Never go to sea with two chronometers; take one or three."
-// Our three time sources are:
-// - System clock
-// - Median of other nodes clocks
-// - The user (asking the user to fix the system clock if the first two disagree)
-//
static int64_t nMockTime = 0; // For unit testing
int64_t GetTime()
@@ -1178,75 +1170,6 @@ void SetMockTime(int64_t nMockTimeIn)
nMockTime = nMockTimeIn;
}
-static CCriticalSection cs_nTimeOffset;
-static int64_t nTimeOffset = 0;
-
-int64_t GetTimeOffset()
-{
- LOCK(cs_nTimeOffset);
- return nTimeOffset;
-}
-
-int64_t GetAdjustedTime()
-{
- return GetTime() + GetTimeOffset();
-}
-
-void AddTimeData(const CNetAddr& ip, int64_t nTime)
-{
- int64_t nOffsetSample = nTime - GetTime();
-
- LOCK(cs_nTimeOffset);
- // Ignore duplicates
- static set<CNetAddr> setKnown;
- if (!setKnown.insert(ip).second)
- return;
-
- // Add data
- static CMedianFilter<int64_t> vTimeOffsets(200,0);
- vTimeOffsets.input(nOffsetSample);
- LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
- if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
- {
- int64_t nMedian = vTimeOffsets.median();
- std::vector<int64_t> vSorted = vTimeOffsets.sorted();
- // Only let other nodes change our time by so much
- if (abs64(nMedian) < 70 * 60)
- {
- nTimeOffset = nMedian;
- }
- else
- {
- nTimeOffset = 0;
-
- static bool fDone;
- if (!fDone)
- {
- // If nobody has a time different than ours but within 5 minutes of ours, give a warning
- bool fMatch = false;
- BOOST_FOREACH(int64_t nOffset, vSorted)
- if (nOffset != 0 && abs64(nOffset) < 5 * 60)
- fMatch = true;
-
- if (!fMatch)
- {
- fDone = true;
- string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly.");
- strMiscWarning = strMessage;
- LogPrintf("*** %s\n", strMessage);
- uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING);
- }
- }
- }
- if (fDebug) {
- BOOST_FOREACH(int64_t n, vSorted)
- LogPrintf("%+d ", n);
- LogPrintf("| ");
- }
- LogPrintf("nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60);
- }
-}
-
uint32_t insecure_rand_Rz = 11;
uint32_t insecure_rand_Rw = 11;
void seed_insecure_rand(bool fDeterministic)