From: CryptoManiac Date: Tue, 22 Sep 2015 00:41:24 +0000 (+0300) Subject: Additional randomization of NTP requests. Also add timestamping information to output... X-Git-Tag: nvc-v0.5.4~15 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=0c15e9be384df1db22a714c3ec77e9902df0492f Additional randomization of NTP requests. Also add timestamping information to output of getinfo RPC call. --- diff --git a/src/ntp.cpp b/src/ntp.cpp index b069f39..2ce65e1 100644 --- a/src/ntp.cpp +++ b/src/ntp.cpp @@ -442,11 +442,12 @@ void ThreadNtpSamples(void* parg) { nNtpOffset = nClockOffset; } else { - // Something went wrong. Disable trusted offset sampling and wait 600 seconds. + // Something went wrong, disable trusted offset sampling. nNtpOffset = INT64_MAX; strTrustedUpstream = "localhost"; - for (int i = 0; i < 600 && !fShutdown; i++) // Sleep for 5 minutes + int nSleepMinutes = 1 + GetRandInt(9); // Sleep for 1-10 minutes. + for (int i = 0; i < nSleepMinutes * 60 && !fShutdown; i++) Sleep(1000); continue; @@ -469,9 +470,10 @@ void ThreadNtpSamples(void* parg) { nNtpOffset = vTimeOffsets.median(); } else { - // Not enough offsets yet, try again 300 seconds later. + // Not enough offsets yet, try again later. nNtpOffset = INT64_MAX; - for (int i = 0; i < 300 && !fShutdown; i++) + int nSleepMinutes = 1 + GetRandInt(4); // Sleep for 1-5 minutes. + for (int i = 0; i < nSleepMinutes * 60 && !fShutdown; i++) Sleep(1000); continue; } @@ -479,7 +481,8 @@ void ThreadNtpSamples(void* parg) { printf("nNtpOffset = %+" PRId64 " (%+" PRId64 " minutes)\n", nNtpOffset, nNtpOffset/60); - for (int i = 0; i < 43200 && !fShutdown; i++) // Sleep for 12 hours + int nSleepHours = 1 + GetRandInt(5); // Sleep for 1-6 hours. + for (int i = 0; i < nSleepHours * 3600 && !fShutdown; i++) Sleep(1000); } diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 2414bdf..67c24e3 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -7,6 +7,8 @@ #include "walletdb.h" #include "bitcoinrpc.h" #include "init.h" +#include "util.h" +#include "ntp.h" #include "base58.h" using namespace json_spirit; @@ -70,7 +72,7 @@ Value getinfo(const Array& params, bool fHelp) proxyType proxy; GetProxy(NET_IPV4, proxy); - Object obj, diff; + Object obj, diff, timestamping; obj.push_back(Pair("version", FormatFullVersion())); obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); @@ -79,7 +81,18 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint()))); obj.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake()))); obj.push_back(Pair("blocks", (int)nBestHeight)); - obj.push_back(Pair("timeoffset", (int64_t)GetTimeOffset())); + + timestamping.push_back(Pair("systemclock", GetTime())); + timestamping.push_back(Pair("adjustedtime", GetAdjustedTime())); + + int64_t nNtpOffset = GetNtpOffset(), + nP2POffset = GetNodesOffset(); + + timestamping.push_back(Pair("ntpoffset", nNtpOffset != INT64_MAX ? nNtpOffset : Value::null)); + timestamping.push_back(Pair("p2poffset", nP2POffset != INT64_MAX ? nP2POffset : Value::null)); + + obj.push_back(Pair("timestamping", timestamping)); + obj.push_back(Pair("moneysupply", ValueFromAmount(pindexBest->nMoneySupply))); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); diff --git a/src/util.cpp b/src/util.cpp index 63c684b..7e0f662 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1326,6 +1326,11 @@ int64_t GetTimeOffset() return 0; } +int64_t GetNodesOffset() +{ + return nNodesOffset; +} + int64_t GetAdjustedTime() { return GetTime() + GetTimeOffset(); diff --git a/src/util.h b/src/util.h index 6ddc7a6..5835e90 100644 --- a/src/util.h +++ b/src/util.h @@ -226,6 +226,7 @@ int64_t GetTime(); void SetMockTime(int64_t nMockTimeIn); int64_t GetAdjustedTime(); int64_t GetTimeOffset(); +int64_t GetNodesOffset(); std::string FormatFullVersion(); std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector& comments); void AddTimeData(const CNetAddr& ip, int64_t nTime);