X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcnet.cpp;h=35e4cb9cc9eaddbff3cca64d53c85aab1886874b;hb=HEAD;hp=d0f4516ea9e51dd0dbc96ca66d85cbee9dbef9d8;hpb=5a73a5bcab66ec1012ac88b4d61bdc1e0213286c;p=novacoin.git diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index d0f4516..f4519b9 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -6,7 +6,6 @@ #include "alert.h" #include "wallet.h" #include "db.h" -#include "walletdb.h" #include "net.h" #include "ntp.h" @@ -30,7 +29,7 @@ static void CopyNodeStats(std::vector& vstats) LOCK(cs_vNodes); vstats.reserve(vNodes.size()); - BOOST_FOREACH(CNode* pnode, vNodes) { + for (CNode* pnode : vNodes) { CNodeStats stats; pnode->copyStats(stats); vstats.push_back(stats); @@ -62,7 +61,7 @@ Value getaddrmaninfo(const Array& params, bool fHelp) strFilterNetType = params[0].get_str(); Array ret; - BOOST_FOREACH(const CAddrInfo &addr, vAddr) { + for (const CAddrInfo &addr : vAddr) { if (!addr.IsRoutable() || addr.IsLocal()) continue; @@ -112,7 +111,7 @@ Value getpeerinfo(const Array& params, bool fHelp) Array ret; - BOOST_FOREACH(const CNodeStats& stats, vstats) { + for (const CNodeStats& stats : vstats) { Object obj; obj.push_back(Pair("addr", stats.addrName)); @@ -194,14 +193,14 @@ Value getaddednodeinfo(const Array& params, bool fHelp) if (params.size() == 1) { LOCK(cs_vAddedNodes); - BOOST_FOREACH(string& strAddNode, vAddedNodes) + for (string& strAddNode : vAddedNodes) laddedNodes.push_back(strAddNode); } else { string strNode = params[1].get_str(); LOCK(cs_vAddedNodes); - BOOST_FOREACH(string& strAddNode, vAddedNodes) + for (string& strAddNode : vAddedNodes) if (strAddNode == strNode) { laddedNodes.push_back(strAddNode); @@ -214,7 +213,7 @@ Value getaddednodeinfo(const Array& params, bool fHelp) if (!fDns) { Object ret; - BOOST_FOREACH(string& strAddNode, laddedNodes) + for (string& strAddNode : laddedNodes) ret.push_back(Pair("addednode", strAddNode)); return ret; } @@ -222,7 +221,7 @@ Value getaddednodeinfo(const Array& params, bool fHelp) Array ret; list > > laddedAddreses(0); - BOOST_FOREACH(string& strAddNode, laddedNodes) + for (string& strAddNode : laddedNodes) { vector vservNode(0); if(Lookup(strAddNode.c_str(), vservNode, GetDefaultPort(), fNameLookup, 0)) @@ -245,12 +244,12 @@ Value getaddednodeinfo(const Array& params, bool fHelp) Array addresses; bool fConnected = false; - BOOST_FOREACH(CService& addrNode, it->second) + for (CService& addrNode : it->second) { bool fFound = false; Object node; node.push_back(Pair("address", addrNode.ToString())); - BOOST_FOREACH(CNode* pnode, vNodes) + for (CNode* pnode : vNodes) if (pnode->addr == addrNode) { fFound = true; @@ -316,7 +315,7 @@ Value sendalert(const Array& params, bool fHelp) // Relay alert { LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) + for (CNode* pnode : vNodes) alert.RelayTo(pnode); } @@ -347,6 +346,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,19 +376,32 @@ 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(); - - if (nTime < 0) - throw runtime_error("Request error"); + else { + CNetAddr ip; + nTime = NtpGetTime(ip); + } Object obj; - obj.push_back(Pair("epoch", nTime)); - obj.push_back(Pair("time", DateTimeStrFormat(nTime))); + 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; }