aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/net.cpp
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2017-10-05 13:10:58 -0400
committerCarl Dong <accounts@carldong.me>2019-01-16 13:54:18 -0500
commit4c0d961eb0d7825a1e6f8389d7f5545114ee18c6 (patch)
tree9d5058c91632293540636bb540818539b216676f /src/rpc/net.cpp
parent83c1ea2e5e66b8a83072e3d5ad6a4ced406eb1ba (diff)
banman: create and split out banman
Some say he has always been.
Diffstat (limited to 'src/rpc/net.cpp')
-rw-r--r--src/rpc/net.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 59bc8e8091..19561c4fc7 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -531,8 +531,9 @@ static UniValue setban(const JSONRPCRequest& request)
+ HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"")
+ HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")
);
- if(!g_connman)
- throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
+ if (!g_banman) {
+ throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
+ }
CSubNet subNet;
CNetAddr netAddr;
@@ -554,8 +555,9 @@ static UniValue setban(const JSONRPCRequest& request)
if (strCommand == "add")
{
- if (isSubnet ? g_connman->IsBanned(subNet) : g_connman->IsBanned(netAddr))
+ if (isSubnet ? g_banman->IsBanned(subNet) : g_banman->IsBanned(netAddr)) {
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
+ }
int64_t banTime = 0; //use standard bantime if not specified
if (!request.params[2].isNull())
@@ -566,17 +568,22 @@ static UniValue setban(const JSONRPCRequest& request)
absolute = true;
if (isSubnet) {
- g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute);
- g_connman->DisconnectNode(subNet);
+ g_banman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute);
+ if (g_connman) {
+ g_connman->DisconnectNode(subNet);
+ }
} else {
- g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
- g_connman->DisconnectNode(netAddr);
+ g_banman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
+ if (g_connman) {
+ g_connman->DisconnectNode(netAddr);
+ }
}
}
else if(strCommand == "remove")
{
- if (!( isSubnet ? g_connman->Unban(subNet) : g_connman->Unban(netAddr) ))
+ if (!( isSubnet ? g_banman->Unban(subNet) : g_banman->Unban(netAddr) )) {
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously banned.");
+ }
}
return NullUniValue;
}
@@ -593,11 +600,12 @@ static UniValue listbanned(const JSONRPCRequest& request)
+ HelpExampleRpc("listbanned", "")
);
- if(!g_connman)
- throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
+ if(!g_banman) {
+ throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
+ }
banmap_t banMap;
- g_connman->GetBanned(banMap);
+ g_banman->GetBanned(banMap);
UniValue bannedAddresses(UniValue::VARR);
for (const auto& entry : banMap)
@@ -626,10 +634,11 @@ static UniValue clearbanned(const JSONRPCRequest& request)
+ HelpExampleCli("clearbanned", "")
+ HelpExampleRpc("clearbanned", "")
);
- if(!g_connman)
- throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
+ if (!g_banman) {
+ throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
+ }
- g_connman->ClearBanned();
+ g_banman->ClearBanned();
return NullUniValue;
}