aboutsummaryrefslogtreecommitdiff
path: root/src/banman.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2020-07-07 11:10:32 -0700
committerPieter Wuille <pieter@wuille.net>2020-07-07 11:20:34 -0700
commitabdfd2d0e3ebec7dbead89317ee9192189a35809 (patch)
tree1143a8929a61f2d205d41d7183492528db7cf981 /src/banman.cpp
parentb52e25cc1be3771cad26c6c3cdbc0b81f96597ec (diff)
parent2ad58381fffb33d611abf900b73d9e6b5a4e35f8 (diff)
downloadbitcoin-abdfd2d0e3ebec7dbead89317ee9192189a35809.tar.xz
Merge #19219: Replace automatic bans with discouragement filter
2ad58381fffb33d611abf900b73d9e6b5a4e35f8 Clean up separated ban/discourage interface (Pieter Wuille) b691f2df5f7d443c0c9ee056ab94aa0fc19566d5 Replace automatic bans with discouragement filter (Pieter Wuille) Pull request description: This patch improves performance and resource usage around IP addresses that are banned for misbehavior. They're already not actually banned since #14929, as connections from them are still allowed, but they are preferred for eviction if the inbound connection slots are full. Stop treating these like manually banned IP ranges, and instead just keep them in a rolling Bloom filter of misbehaving nodes, which isn't persisted to disk or exposed through the ban framework. The effect remains the same: preferred for eviction, avoided for outgoing connections, and not relayed to other peers. Also change the name of this mechanism to "discouraged" to better reflect reality. ACKs for top commit: naumenkogs: utACK 2ad58381fffb33d611abf900b73d9e6b5a4e35f8 amitiuttarwar: code review ACK 2ad58381ff jonatack: ACK 2ad5838 per changes since last review `git range-diff 3276c14 1f7e0ca 2ad5838` jnewbery: Code review ACK 2ad58381fffb33d611abf900b73d9e6b5a4e35f8 Tree-SHA512: 5dedef401d9cbfa026812651303e6286223563dbeed7a10766ed536ac9e3f29ed4bd0df29cc6deadceeb35cbe9f066346add14ef0833958ca9f93d123fe7aab5
Diffstat (limited to 'src/banman.cpp')
-rw-r--r--src/banman.cpp41
1 files changed, 16 insertions, 25 deletions
diff --git a/src/banman.cpp b/src/banman.cpp
index 422904bb33..2fabacda0e 100644
--- a/src/banman.cpp
+++ b/src/banman.cpp
@@ -68,28 +68,13 @@ void BanMan::ClearBanned()
if (m_client_interface) m_client_interface->BannedListChanged();
}
-int BanMan::IsBannedLevel(CNetAddr net_addr)
+bool BanMan::IsDiscouraged(const CNetAddr& net_addr)
{
- // Returns the most severe level of banning that applies to this address.
- // 0 - Not banned
- // 1 - Automatic misbehavior ban
- // 2 - Any other ban
- int level = 0;
- auto current_time = GetTime();
LOCK(m_cs_banned);
- for (const auto& it : m_banned) {
- CSubNet sub_net = it.first;
- CBanEntry ban_entry = it.second;
-
- if (current_time < ban_entry.nBanUntil && sub_net.Match(net_addr)) {
- if (ban_entry.banReason != BanReasonNodeMisbehaving) return 2;
- level = 1;
- }
- }
- return level;
+ return m_discouraged.contains(net_addr.GetAddrBytes());
}
-bool BanMan::IsBanned(CNetAddr net_addr)
+bool BanMan::IsBanned(const CNetAddr& net_addr)
{
auto current_time = GetTime();
LOCK(m_cs_banned);
@@ -104,7 +89,7 @@ bool BanMan::IsBanned(CNetAddr net_addr)
return false;
}
-bool BanMan::IsBanned(CSubNet sub_net)
+bool BanMan::IsBanned(const CSubNet& sub_net)
{
auto current_time = GetTime();
LOCK(m_cs_banned);
@@ -118,15 +103,21 @@ bool BanMan::IsBanned(CSubNet sub_net)
return false;
}
-void BanMan::Ban(const CNetAddr& net_addr, const BanReason& ban_reason, int64_t ban_time_offset, bool since_unix_epoch)
+void BanMan::Ban(const CNetAddr& net_addr, int64_t ban_time_offset, bool since_unix_epoch)
{
CSubNet sub_net(net_addr);
- Ban(sub_net, ban_reason, ban_time_offset, since_unix_epoch);
+ Ban(sub_net, ban_time_offset, since_unix_epoch);
+}
+
+void BanMan::Discourage(const CNetAddr& net_addr)
+{
+ LOCK(m_cs_banned);
+ m_discouraged.insert(net_addr.GetAddrBytes());
}
-void BanMan::Ban(const CSubNet& sub_net, const BanReason& ban_reason, int64_t ban_time_offset, bool since_unix_epoch)
+void BanMan::Ban(const CSubNet& sub_net, int64_t ban_time_offset, bool since_unix_epoch)
{
- CBanEntry ban_entry(GetTime(), ban_reason);
+ CBanEntry ban_entry(GetTime());
int64_t normalized_ban_time_offset = ban_time_offset;
bool normalized_since_unix_epoch = since_unix_epoch;
@@ -146,8 +137,8 @@ void BanMan::Ban(const CSubNet& sub_net, const BanReason& ban_reason, int64_t ba
}
if (m_client_interface) m_client_interface->BannedListChanged();
- //store banlist to disk immediately if user requested ban
- if (ban_reason == BanReasonManuallyAdded) DumpBanlist();
+ //store banlist to disk immediately
+ DumpBanlist();
}
bool BanMan::Unban(const CNetAddr& net_addr)