From: MASM fan Date: Wed, 14 Jan 2015 17:48:52 +0000 (-0800) Subject: RPC: getaddrmaninfo X-Git-Tag: nvc-v0.5.1~2 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=b811745be7df169fcb75dd84c1e57aef20649b1b RPC: getaddrmaninfo This new call allows user to get a list of random address entries from addrman store. --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 86c062d..bd711d1 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -242,6 +242,7 @@ static const CRPCCommand vRPCCommands[] = { "getbestblockhash", &getbestblockhash, true, false }, { "getblockcount", &getblockcount, true, false }, { "getconnectioncount", &getconnectioncount, true, false }, + { "getaddrmaninfo", &getaddrmaninfo, true, false }, { "getpeerinfo", &getpeerinfo, true, false }, { "addnode", &addnode, true, true }, { "getaddednodeinfo", &getaddednodeinfo, true, true }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 72f7128..ecb14f8 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -146,6 +146,7 @@ extern std::vector ParseHexO(const json_spirit::Object& o, std::s extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getaddrmaninfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 604db0f..5404c01 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -36,6 +36,52 @@ static void CopyNodeStats(std::vector& vstats) } } +Value getaddrmaninfo(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getaddrmaninfo\n" + "Returns a dump of addrman data."); + + vector vAddr = addrman.GetAddr(); + + Array ret; + + BOOST_FOREACH(const CAddress &addr, vAddr) { + // Don't return addresses older than nCutOff timestamp + int64_t nCutOff = GetTime() - (nNodeLifespan * 24 * 60 * 60); + + if (!addr.IsRoutable() || addr.IsLocal() || addr.nTime > nCutOff) + continue; + + Object addrManItem; + addrManItem.push_back(Pair("address", addr.ToString())); + + string strNetType; + switch(addr.GetNetwork()) + { + case NET_TOR: + strNetType = "tor"; + break; + case NET_I2P: + strNetType = "i2p"; + case NET_IPV4: + strNetType = "ipv4"; + break; + default: + case NET_IPV6: + strNetType = "ipv6"; + + } + addrManItem.push_back(Pair("type", strNetType)); + addrManItem.push_back(Pair("time", (int64_t)addr.nTime)); + + ret.push_back(addrManItem); + } + + return ret; +} + Value getpeerinfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0)