#include "walletdb.h"
#include "net.h"
#include "ntp.h"
+#include "timedata.h"
using namespace json_spirit;
using namespace std;
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);
strFilterNetType = params[0].get_str();
Array ret;
- BOOST_FOREACH(const CAddrInfo &addr, vAddr) {
+ for(const CAddrInfo &addr : vAddr) {
if (!addr.IsRoutable() || addr.IsLocal())
continue;
Array ret;
- BOOST_FOREACH(const CNodeStats& stats, vstats) {
+ for(const CNodeStats& stats : vstats) {
Object obj;
obj.push_back(Pair("addr", stats.addrName));
}
LOCK(cs_vAddedNodes);
- vector<string>::iterator it = vAddedNodes.begin();
+ auto it = vAddedNodes.begin();
for(; it != vAddedNodes.end(); it++)
if (strNode == *it)
break;
if (params.size() == 1)
{
LOCK(cs_vAddedNodes);
- BOOST_FOREACH(string& strAddNode, vAddedNodes)
+ for(auto& strAddNode : vAddedNodes)
laddedNodes.push_back(strAddNode);
}
else
{
string strNode = params[1].get_str();
LOCK(cs_vAddedNodes);
- BOOST_FOREACH(string& strAddNode, vAddedNodes)
+ for(auto& strAddNode : vAddedNodes)
if (strAddNode == strNode)
{
laddedNodes.push_back(strAddNode);
if (!fDns)
{
Object ret;
- BOOST_FOREACH(string& strAddNode, laddedNodes)
+ for(string& strAddNode : laddedNodes)
ret.push_back(Pair("addednode", strAddNode));
return ret;
}
Array ret;
list<pair<string, vector<CService> > > laddedAddreses(0);
- BOOST_FOREACH(string& strAddNode, laddedNodes)
+ for(auto& strAddNode : laddedNodes)
{
vector<CService> vservNode(0);
if(Lookup(strAddNode.c_str(), vservNode, GetDefaultPort(), fNameLookup, 0))
}
LOCK(cs_vNodes);
- for (list<pair<string, vector<CService> > >::iterator it = laddedAddreses.begin(); it != laddedAddreses.end(); it++)
+ for (auto it = laddedAddreses.begin(); it != laddedAddreses.end(); it++)
{
Object obj;
obj.push_back(Pair("addednode", it->first));
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;
sMsg << (CUnsignedAlert)alert;
alert.vchMsg = vector<unsigned char>(sMsg.begin(), sMsg.end());
- vector<unsigned char> vchPrivKey = ParseHex(params[1].get_str());
+ auto vchPrivKey = ParseHex(params[1].get_str());
key.SetPrivKey(CPrivKey(vchPrivKey.begin(), vchPrivKey.end())); // if key is not correct openssl may crash
if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig))
throw runtime_error(
// Relay alert
{
LOCK(cs_vNodes);
- BOOST_FOREACH(CNode* pnode, vNodes)
+ for(CNode* pnode : vNodes)
alert.RelayTo(pnode);
}
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:53:59 ntptime time.windows.com
-05:54:00
-{
-"epoch" : 1442494439,
-"time" : "2015-09-17 12:53:59 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)
"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:
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;
}
+
+Value getnetworkinfo(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 0)
+ throw runtime_error(
+ "getnetworkinfo\n"
+ "Returns an object containing various state info regarding P2P networking.\n"
+ "\nResult:\n"
+ "{\n"
+ " \"version\": xxxxx, (numeric) the server version\n"
+ " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
+ " \"timeoffset\": xxxxx, (numeric) the time offset\n"
+ " \"connections\": xxxxx, (numeric) the number of connections\n"
+ " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
+ " \"localaddresses\": [, (array) list of local addresses\n"
+ " \"address\": \"xxxx\", (string) network address\n"
+ " \"port\": xxx, (numeric) network port\n"
+ " \"score\": xxx (numeric) relative score\n"
+ " ]\n"
+ "}\n"
+ );
+
+ proxyType proxy;
+ GetProxy(NET_IPV4, proxy);
+
+ Object obj;
+ obj.push_back(Pair("version", CLIENT_VERSION));
+ obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
+ obj.push_back(Pair("timeoffset", GetTimeOffset()));
+ obj.push_back(Pair("connections", (int)vNodes.size()));
+ obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.ToStringIPPort() : string())));
+ Array localAddresses;
+ {
+ LOCK(cs_mapLocalHost);
+ for(const auto &item : mapLocalHost)
+ {
+ Object rec;
+ rec.push_back(Pair("address", item.first.ToString()));
+ rec.push_back(Pair("port", (int)item.second.nPort));
+ rec.push_back(Pair("score", item.second.nScore));
+ localAddresses.push_back(rec);
+ }
+ }
+ obj.push_back(Pair("localaddresses", localAddresses));
+ return obj;
+}