MCPcopy Create free account
hub / github.com/ElementsProject/elements / listbanned

Function listbanned

src/rpc/net.cpp:752–800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

750}
751
752static RPCHelpMan listbanned()
753{
754 return RPCHelpMan{"listbanned",
755 "\nList all manually banned IPs/Subnets.\n",
756 {},
757 RPCResult{RPCResult::Type::ARR, "", "",
758 {
759 {RPCResult::Type::OBJ, "", "",
760 {
761 {RPCResult::Type::STR, "address", "The IP/Subnet of the banned node"},
762 {RPCResult::Type::NUM_TIME, "ban_created", "The " + UNIX_EPOCH_TIME + " the ban was created"},
763 {RPCResult::Type::NUM_TIME, "banned_until", "The " + UNIX_EPOCH_TIME + " the ban expires"},
764 {RPCResult::Type::NUM_TIME, "ban_duration", "The ban duration, in seconds"},
765 {RPCResult::Type::NUM_TIME, "time_remaining", "The time remaining until the ban expires, in seconds"},
766 }},
767 }},
768 RPCExamples{
769 HelpExampleCli("listbanned", "")
770 + HelpExampleRpc("listbanned", "")
771 },
772 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
773{
774 NodeContext& node = EnsureAnyNodeContext(request.context);
775 if(!node.banman) {
776 throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
777 }
778
779 banmap_t banMap;
780 node.banman->GetBanned(banMap);
781 const int64_t current_time{GetTime()};
782
783 UniValue bannedAddresses(UniValue::VARR);
784 for (const auto& entry : banMap)
785 {
786 const CBanEntry& banEntry = entry.second;
787 UniValue rec(UniValue::VOBJ);
788 rec.pushKV("address", entry.first.ToString());
789 rec.pushKV("ban_created", banEntry.nCreateTime);
790 rec.pushKV("banned_until", banEntry.nBanUntil);
791 rec.pushKV("ban_duration", (banEntry.nBanUntil - banEntry.nCreateTime));
792 rec.pushKV("time_remaining", (banEntry.nBanUntil - current_time));
793
794 bannedAddresses.push_back(rec);
795 }
796
797 return bannedAddresses;
798},
799 };
800}
801
802static RPCHelpMan clearbanned()
803{

Callers

nothing calls this directly

Calls 8

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
GetTimeFunction · 0.85
GetBannedMethod · 0.80
pushKVMethod · 0.45
ToStringMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected