X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcnet.cpp;h=35e4cb9cc9eaddbff3cca64d53c85aab1886874b;hb=5a7a2125b6b4ed7d3ea55f333d0cf2345bd1d916;hp=614552ff5a5dc011324a172f79f9c6e2fddb290c;hpb=52332d9954a3fb6589e7efb4c90ce0c15a3a3540;p=novacoin.git diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 614552f..35e4cb9 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -8,6 +8,7 @@ #include "db.h" #include "walletdb.h" #include "net.h" +#include "ntp.h" using namespace json_spirit; using namespace std; @@ -116,15 +117,15 @@ Value getpeerinfo(const Array& params, bool fHelp) obj.push_back(Pair("addr", stats.addrName)); obj.push_back(Pair("services", strprintf("%08" PRIx64, stats.nServices))); - obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend)); - obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv)); - obj.push_back(Pair("bytessent", (boost::int64_t)stats.nSendBytes)); - obj.push_back(Pair("bytesrecv", (boost::int64_t)stats.nRecvBytes)); - obj.push_back(Pair("conntime", (boost::int64_t)stats.nTimeConnected)); + obj.push_back(Pair("lastsend", (int64_t)stats.nLastSend)); + obj.push_back(Pair("lastrecv", (int64_t)stats.nLastRecv)); + obj.push_back(Pair("bytessent", (int64_t)stats.nSendBytes)); + obj.push_back(Pair("bytesrecv", (int64_t)stats.nRecvBytes)); + obj.push_back(Pair("conntime", (int64_t)stats.nTimeConnected)); obj.push_back(Pair("version", stats.nVersion)); obj.push_back(Pair("subver", stats.strSubVer)); obj.push_back(Pair("inbound", stats.fInbound)); - obj.push_back(Pair("releasetime", (boost::int64_t)stats.nReleaseTime)); + obj.push_back(Pair("releasetime", (int64_t)stats.nReleaseTime)); obj.push_back(Pair("startingheight", stats.nStartingHeight)); obj.push_back(Pair("banscore", stats.nMisbehavior)); if (stats.fSyncNode) @@ -340,8 +341,68 @@ Value getnettotals(const Array& params, bool fHelp) "and current time."); Object obj; - obj.push_back(Pair("totalbytesrecv", static_cast< boost::uint64_t>(CNode::GetTotalBytesRecv()))); - obj.push_back(Pair("totalbytessent", static_cast(CNode::GetTotalBytesSent()))); - obj.push_back(Pair("timemillis", static_cast(GetTimeMillis()))); + obj.push_back(Pair("totalbytesrecv", static_cast(CNode::GetTotalBytesRecv()))); + obj.push_back(Pair("totalbytessent", static_cast(CNode::GetTotalBytesSent()))); + obj.push_back(Pair("timemillis", static_cast(GetTimeMillis()))); return obj; -} \ No newline at end of file +} + +/* +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) + throw runtime_error( + "ntptime [ntpserver]\n" + "Returns current time from specific or random NTP server."); + + int64_t nTime; + if (params.size() > 0) { + string strHostName = params[0].get_str(); + nTime = NtpGetTime(strHostName); + } + else { + CNetAddr ip; + nTime = NtpGetTime(ip); + } + + Object obj; + switch (nTime) { + case -1: + throw runtime_error("Socket initialization error"); + case -2: + throw runtime_error("Switching socket mode to non-blocking failed"); + case -3: + throw runtime_error("Unable to send data"); + case -4: + throw runtime_error("Receive timed out"); + default: + 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; +}