X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Finit.cpp;h=9655f2a290905a74871dd54389425685d15e4ab7;hp=b93f2bd0e49069a0d1a0da7090150a8a808e0614;hb=9de5ff869fb469db2d821f4ecfda44657259ec26;hpb=cd37f49194e0f377335ecbf8990b7c92e0a19ef0 diff --git a/src/init.cpp b/src/init.cpp index b93f2bd..9655f2a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -996,23 +996,33 @@ 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); + // ********************************************************* Step 12: NTP synchronization + + // First, do a simple check whether there is a local ntp server. + string strLocalHost = "127.0.0.1"; + int64_t nTime = NtpGetTime(strLocalHost); + + if (nTime < 0 || nTime != GetTime()) { + // If not, then request current timestamp from three random NTP servers. + uiInterface.InitMessage(_("Synchronizing time through NTP...")); + printf("Synchronizing time through NTP...\n"); + + for(int i = 0; i < 2; i++) { + 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++; + // When done, start a periodical sampling thread + NewThread(ThreadNtpSamples, NULL); + + uiInterface.InitMessage(_("Done")); + printf("Done\n"); } - uiInterface.InitMessage(_("Done")); - printf("Done\n"); // ********************************************************* Step 12: finished uiInterface.InitMessage(_("Done loading"));