Keep old GetAdjustedTime() behavior if no NTP data is available;
authorCryptoManiac <balthazar@yandex.ru>
Tue, 22 Sep 2015 23:15:38 +0000 (02:15 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Tue, 22 Sep 2015 23:15:38 +0000 (02:15 +0300)
Give a warning if no p2p time data is available and NTP is not in agreement with system clock.

src/ntp.cpp
src/util.cpp

index 84f3301..4cc422b 100644 (file)
@@ -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.
index 7e0f662..d434c81 100644 (file)
@@ -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;