X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcnet.cpp;h=35e4cb9cc9eaddbff3cca64d53c85aab1886874b;hb=0a18ce8f4cd1a723f50333945d94c84b45c8d56b;hp=ab3f281163bd7b77dcaeea9b1b9797e72120eb53;hpb=03faadc0d045a9683d1ce0b8aca6af7f7b287767;p=novacoin.git diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index ab3f281..35e4cb9 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -347,6 +347,28 @@ Value getnettotals(const Array& params, bool fHelp) return obj; } +/* +05:53:45 ntptime +05:53:48 +{ +"epoch" : 1442494427, +"time" : "2015-09-17 12:53:47 UTC" +} + +05:53:56 ntptime time.windows.com +05:53:57 +{ +"epoch" : 1442494436, +"time" : "2015-09-17 12:53:56 UTC" +} + +05:54:33 ntptime time-a.nist.gov +05:54:34 +{ +"epoch" : 1442494473, +"time" : "2015-09-17 12:54:33 UTC" +}*/ + Value ntptime(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) @@ -355,17 +377,17 @@ Value ntptime(const Array& params, bool fHelp) "Returns current time from specific or random NTP server."); int64_t nTime; - if (params.size() > 0) - { + if (params.size() > 0) { string strHostName = params[0].get_str(); nTime = NtpGetTime(strHostName); } - else - nTime = NtpGetTime(); + else { + CNetAddr ip; + nTime = NtpGetTime(ip); + } Object obj; - switch (nTime) - { + switch (nTime) { case -1: throw runtime_error("Socket initialization error"); case -2: @@ -375,8 +397,11 @@ Value ntptime(const Array& params, bool fHelp) case -4: throw runtime_error("Receive timed out"); default: - obj.push_back(Pair("epoch", nTime)); - obj.push_back(Pair("time", DateTimeStrFormat(nTime))); + if (nTime > 0 && nTime != 2085978496) { + obj.push_back(Pair("epoch", nTime)); + obj.push_back(Pair("time", DateTimeStrFormat(nTime))); + } + else throw runtime_error("Unexpected response"); } return obj;