Add time samples from NTP while starting up.
[novacoin.git] / src / init.cpp
index ca7c8b1..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>
@@ -31,7 +32,6 @@ CClientUIInterface uiInterface;
 std::string strWalletFileName;
 bool fConfChange;
 unsigned int nNodeLifespan;
-unsigned int nMinerSleep;
 bool fUseFastIndex;
 bool fUseMemoryLog;
 enum Checkpoints::CPMode CheckpointsMode;
@@ -39,6 +39,7 @@ enum Checkpoints::CPMode CheckpointsMode;
 // Ping and address broadcast intervals
 extern int64_t nPingInterval;
 extern int64_t nBroadcastInterval;
+extern int64_t nReserveBalance;
 
 //////////////////////////////////////////////////////////////////////////////
 //
@@ -377,7 +378,6 @@ bool AppInit2()
     nNodeLifespan = (unsigned int)(GetArg("-addrlifespan", 7));
     fUseFastIndex = GetBoolArg("-fastindex", true);
     fUseMemoryLog = GetBoolArg("-memorylog", true);
-    nMinerSleep = (unsigned int)(GetArg("-minersleep", 500));
 
     // Ping and address broadcast intervals
     nPingInterval = max<int64_t>(10 * 60, GetArg("-keepalive", 30 * 60));
@@ -490,12 +490,8 @@ bool AppInit2()
             nConnectTimeout = nNewTimeout;
     }
 
-    // Continue to put "/P2SH/" in the coinbase to monitor
-    // BIP16 support.
-    // This can be removed eventually...
-    const char* pszP2SH = "/P2SH/";
-    COINBASE_FLAGS << std::vector<unsigned char>(pszP2SH, pszP2SH+strlen(pszP2SH));
-
+    // Put client version data into coinbase flags.
+    COINBASE_FLAGS << PROTOCOL_VERSION << DISPLAY_VERSION_MAJOR << DISPLAY_VERSION_MINOR << DISPLAY_VERSION_REVISION;
 
     if (mapArgs.count("-paytxfee"))
     {
@@ -574,9 +570,6 @@ bool AppInit2()
 
     int64_t nStart;
 
-#ifdef USE_SSE2
-    scrypt_detect_sse2();
-#endif
     // ********************************************************* Step 5: verify database integrity
 
     uiInterface.InitMessage(_("Verifying database integrity..."));
@@ -642,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()));
 
@@ -664,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);
@@ -741,7 +734,6 @@ bool AppInit2()
 
     if (mapArgs.count("-reservebalance")) // ppcoin: reserve balance amount
     {
-        int64_t nReserveBalance = 0;
         if (!ParseMoney(mapArgs["-reservebalance"], nReserveBalance))
         {
             InitError(_("Invalid amount for -reservebalance=<amount>"));
@@ -1004,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"));