From: CryptoManiac Date: Tue, 22 Sep 2015 23:15:38 +0000 (+0300) Subject: Keep old GetAdjustedTime() behavior if no NTP data is available; X-Git-Tag: nvc-v0.5.4~8 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=1d8129375a4d646abb5c49075d2b1f065d932680 Keep old GetAdjustedTime() behavior if no NTP data is available; Give a warning if no p2p time data is available and NTP is not in agreement with system clock. --- diff --git a/src/ntp.cpp b/src/ntp.cpp index 84f3301..4cc422b 100644 --- a/src/ntp.cpp +++ b/src/ntp.cpp @@ -13,7 +13,8 @@ #include "netbase.h" #include "net.h" -#include "util.h" +//#include "util.h" +#include "ui_interface.h" extern int GetRandInt(int nMax); @@ -420,9 +421,7 @@ int64_t GetNtpOffset() { } void ThreadNtpSamples(void* parg) { - - // Maximum offset is 2 hours. - const int64_t nMaxOffset = 7200; + const int64_t nMaxOffset = 86400; // Not a real limit, just sanity threshold. printf("Trying to find NTP server at localhost...\n"); @@ -491,6 +490,15 @@ void ThreadNtpSamples(void* parg) { } } + if (GetNodesOffset() == INT_MAX && abs64(nNtpOffset) > 40 * 60) + { + // If there is not enough node offsets data and NTP time offset is greater than 40 minutes then give a warning. + std::string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong NovaCoin will not work properly."); + strMiscWarning = strMessage; + printf("*** %s\n", strMessage.c_str()); + uiInterface.ThreadSafeMessageBox(strMessage+" ", std::string("NovaCoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION); + } + printf("nNtpOffset = %+" PRId64 " (%+" PRId64 " minutes)\n", nNtpOffset, nNtpOffset/60); int nSleepHours = 1 + GetRandInt(5); // Sleep for 1-6 hours. diff --git a/src/util.cpp b/src/util.cpp index 7e0f662..d434c81 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1312,15 +1312,14 @@ extern int64_t nNtpOffset; static int64_t nNodesOffset = INT64_MAX; // Select time offset: -// -// * If NTP and system clock are in agreement within 40 minutes, then use NTP. -// * If not, then choose between median peer time and system clock using the same condition. int64_t GetTimeOffset() { + // If NTP and system clock are in agreement within 40 minutes, then use NTP. if (abs64(nNtpOffset) < 40 * 60) return nNtpOffset; - if (abs64(nNodesOffset) < 40 * 60) + // If not, then choose between median peer time and system clock. + if (abs64(nNodesOffset) < 70 * 60) return nNodesOffset; return 0;