Add time samples from NTP while starting up.
[novacoin.git] / src / init.cpp
index 7cc0e0f..b93f2bd 100644 (file)
@@ -8,6 +8,7 @@
 #include "net.h"
 #include "init.h"
 #include "util.h"
+#include "ntp.h"
 #include "ui_interface.h"
 #include "checkpoints.h"
 #include <boost/format.hpp>
@@ -634,7 +635,7 @@ bool AppInit2()
     CService addrProxy;
     bool fProxy = false;
     if (mapArgs.count("-proxy")) {
-        addrProxy = CService(mapArgs["-proxy"], 9050);
+        addrProxy = CService(mapArgs["-proxy"], nSocksDefault);
         if (!addrProxy.IsValid())
             return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"].c_str()));
 
@@ -656,7 +657,7 @@ bool AppInit2()
         if (!mapArgs.count("-tor"))
             addrOnion = addrProxy;
         else
-            addrOnion = CService(mapArgs["-tor"], 9050);
+            addrOnion = CService(mapArgs["-tor"], nSocksDefault);
         if (!addrOnion.IsValid())
             return InitError(strprintf(_("Invalid -tor address: '%s'"), mapArgs["-tor"].c_str()));
         SetProxy(NET_TOR, addrOnion, 5);
@@ -995,6 +996,23 @@ bool AppInit2()
     if (fServer)
         NewThread(ThreadRPCServer, NULL);
 
+    // ********************************************************* Step 12: add time data from four random NTP servers.
+    uiInterface.InitMessage(_("Synchronizing time through NTP..."));
+    printf("Synchronizing time through NTP...\n");
+    int i = 0;
+    while(i < 4) {
+        CNetAddr ip;
+        int64_t nTime = NtpGetTime(ip);
+
+        if (nTime > 0 && nTime != 2085978496) { // Skip the deliberately wrong timestamps
+            AddTimeData(ip, nTime);
+            printf("AddTimeData(%s, %" PRId64 ")\n", ip.ToString().c_str(), nTime);
+        }
+
+        i++;
+    }
+    uiInterface.InitMessage(_("Done"));
+    printf("Done\n");
     // ********************************************************* Step 12: finished
 
     uiInterface.InitMessage(_("Done loading"));