BIP155 (addrv2)
Tor v3 + i2p
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "clientversion.h"
|
||||
#include "main.h"
|
||||
#include "net.h"
|
||||
#include "addrman.h"
|
||||
#include "netbase.h"
|
||||
#include "protocol.h"
|
||||
#include "sync.h"
|
||||
@@ -75,6 +76,36 @@ UniValue ping(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
UniValue getpeerlist(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"getpeerlist\n"
|
||||
"\nReturns a list of connected network node addresses that have connected to the\n"
|
||||
"in the last 30 days as a json array of objects.\n"
|
||||
"\nbResult:\n"
|
||||
"[\n"
|
||||
" \"host:port\", (string) The ip address and port of the peer\n"
|
||||
"]\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getpeerlist", "")
|
||||
+ HelpExampleRpc("getpeerlist", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
std::map<std::string, int64_t> info;
|
||||
addrman.GetAllPeers(info);
|
||||
int64_t nCutOff = GetTime() - (60 * 60 * 24 * 30); //Connected within last 30 days.
|
||||
for (std::map<std::string, int64_t>::iterator it = info.begin(); it != info.end(); it++) {
|
||||
if ((*it).second >= nCutOff)
|
||||
ret.push_back((*it).first);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue getpeerinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
@@ -159,6 +190,7 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
// corrupting or modifying the JSON output by putting special characters in
|
||||
// their ver message.
|
||||
obj.push_back(Pair("subver", stats.cleanSubVer));
|
||||
obj.push_back(Pair("addrv2", stats.m_wants_addrv2));
|
||||
obj.push_back(Pair("inbound", stats.fInbound));
|
||||
obj.push_back(Pair("startingheight", stats.nStartingHeight));
|
||||
if (fStateStats) {
|
||||
@@ -447,13 +479,12 @@ static UniValue GetNetworksInfo()
|
||||
for(int n=0; n<NET_MAX; ++n)
|
||||
{
|
||||
enum Network network = static_cast<enum Network>(n);
|
||||
if(network == NET_UNROUTABLE)
|
||||
if(network == NET_UNROUTABLE || network == NET_INTERNAL)
|
||||
continue;
|
||||
proxyType proxy;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
GetProxy(network, proxy);
|
||||
obj.push_back(Pair("name", GetNetworkName(network)));
|
||||
obj.push_back(Pair("limited", IsLimited(network)));
|
||||
obj.push_back(Pair("reachable", IsReachable(network)));
|
||||
obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()));
|
||||
obj.push_back(Pair("proxy_randomize_credentials", proxy.randomize_credentials));
|
||||
@@ -586,10 +617,13 @@ UniValue setban(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
if (params[0].get_str().find("/") != string::npos)
|
||||
isSubnet = true;
|
||||
|
||||
if (!isSubnet)
|
||||
netAddr = CNetAddr(params[0].get_str());
|
||||
else
|
||||
subNet = CSubNet(params[0].get_str());
|
||||
if (!isSubnet) {
|
||||
CNetAddr resolved;
|
||||
LookupHost(params[0].get_str().c_str(), resolved, false);
|
||||
netAddr = resolved;
|
||||
} else {
|
||||
LookupSubNet(params[0].get_str().c_str(), subNet);
|
||||
}
|
||||
|
||||
if (! (isSubnet ? subNet.IsValid() : netAddr.IsValid()) )
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Invalid IP/Subnet");
|
||||
@@ -607,7 +641,7 @@ UniValue setban(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
if (params.size() == 4 && params[3].isTrue())
|
||||
absolute = true;
|
||||
|
||||
isSubnet ? CNode::Ban(subNet, banTime, absolute) : CNode::Ban(netAddr, banTime, absolute);
|
||||
isSubnet ? CNode::Ban(subNet, BanReasonManuallyAdded, banTime, absolute) : CNode::Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
|
||||
|
||||
//disconnect possible nodes
|
||||
while(CNode *bannedNode = (isSubnet ? FindNode(subNet) : FindNode(netAddr)))
|
||||
@@ -633,17 +667,21 @@ UniValue listbanned(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
+ HelpExampleRpc("listbanned", "")
|
||||
);
|
||||
|
||||
std::map<CSubNet, int64_t> banMap;
|
||||
CNode::GetBanned(banMap);
|
||||
const int64_t current_time{GetTime()};
|
||||
banmap_t banMap;
|
||||
GetBanned(banMap);
|
||||
|
||||
UniValue bannedAddresses(UniValue::VARR);
|
||||
for (std::map<CSubNet, int64_t>::iterator it = banMap.begin(); it != banMap.end(); it++)
|
||||
const int64_t current_time{GetTime()};
|
||||
|
||||
for (banmap_t::iterator it = banMap.begin(); it != banMap.end(); it++)
|
||||
{
|
||||
CBanEntry banEntry = (*it).second;
|
||||
UniValue rec(UniValue::VOBJ);
|
||||
rec.push_back(Pair("address", (*it).first.ToString()));
|
||||
rec.push_back(Pair("banned_until", (*it).second));
|
||||
rec.push_back(Pair("time_remaining", (*it).second - current_time));
|
||||
rec.push_back(Pair("banned_until", banEntry.nBanUntil));
|
||||
rec.push_back(Pair("time_remaining", banEntry.nBanUntil - current_time));
|
||||
rec.push_back(Pair("ban_created", banEntry.nCreateTime));
|
||||
rec.push_back(Pair("ban_reason", banEntry.banReasonToString()));
|
||||
bannedAddresses.push_back(rec);
|
||||
}
|
||||
|
||||
@@ -672,6 +710,7 @@ static const CRPCCommand commands[] =
|
||||
{ "network", "getconnectioncount", &getconnectioncount, true },
|
||||
{ "network", "getdeprecationinfo", &getdeprecationinfo, true },
|
||||
{ "network", "ping", &ping, true },
|
||||
{ "network", "getpeerlist", &getpeerlist, true },
|
||||
{ "network", "getpeerinfo", &getpeerinfo, true },
|
||||
{ "network", "addnode", &addnode, true },
|
||||
{ "network", "disconnectnode", &disconnectnode, true },
|
||||
|
||||
Reference in New Issue
Block a user