From 2201a0808ea240617a66823f98dda3433d2546b0 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Fri, 20 Aug 2010 16:55:14 +0000 Subject: warning message if clock is too far off git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@141 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- util.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'util.cpp') diff --git a/util.cpp b/util.cpp index 8f06e30870..2be841d07c 100644 --- a/util.cpp +++ b/util.cpp @@ -14,6 +14,7 @@ char pszSetDataDir[MAX_PATH] = ""; bool fShutdown = false; bool fDaemon = false; bool fCommandLine = false; +string strWarning; @@ -742,14 +743,28 @@ void AddTimeData(unsigned int ip, int64 nTime) { sort(vTimeOffsets.begin(), vTimeOffsets.end()); int64 nMedian = vTimeOffsets[vTimeOffsets.size()/2]; - nTimeOffset = nMedian; - if ((nMedian > 0 ? nMedian : -nMedian) > 70 * 60) + // Only let other nodes change our time by so much + if (abs64(nMedian) < 70 * 60) + { + nTimeOffset = nMedian; + } + else { - // Only let other nodes change our clock so far before we - // go to the NTP servers - /// todo: Get time from NTP servers, then set a flag - /// to make sure it doesn't get changed again nTimeOffset = 0; + // If nobody else has the same time as us, give a warning + bool fMatch = false; + foreach(int64 nOffset, vTimeOffsets) + if (nOffset != 0 && abs64(nOffset) < 10 * 60) + fMatch = true; + static bool fDone; + if (!fMatch && !fDone) + { + fDone = true; + string strMessage = _("Warning: Check your system date and time, you may not be able to generate or receive the most recent blocks!"); + strWarning = strMessage; + printf("*** %s\n", strMessage.c_str()); + boost::thread(bind(ThreadSafeMessageBox, strMessage+" ", string("Bitcoin"), wxOK | wxICON_EXCLAMATION, (wxWindow*)NULL, -1, -1)); + } } foreach(int64 n, vTimeOffsets) printf("%+"PRI64d" ", n); -- cgit v1.2.3