From f0e326be58f5ac78e3aa1de29db848a895f5e62b Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 1 Mar 2023 16:56:17 +0000 Subject: p2p: avoid spam blocking ipv4 addresses in a blocked subnet --- src/p2p/net_node.inl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index ee6bd8b19..733c7acf7 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -247,7 +247,23 @@ namespace nodetool if (it == m_blocked_hosts.end()) { m_blocked_hosts[host_str] = limit; - added = true; + + // if the host was already blocked due to being in a blocked subnet, let it be silent + bool matches_blocked_subnet = false; + if (addr.get_type_id() == epee::net_utils::address_type::ipv4) + { + auto ipv4_address = addr.template as(); + for (auto jt = m_blocked_subnets.begin(); jt != m_blocked_subnets.end(); ++jt) + { + if (jt->first.matches(ipv4_address)) + { + matches_blocked_subnet = true; + break; + } + } + } + if (!matches_blocked_subnet) + added = true; } else if (it->second < limit || !add_only) it->second = limit; -- cgit v1.2.3 From c4cfaa4567106d53f397b1e61f9ed9ea76dae579 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 9 Mar 2023 17:17:59 +0000 Subject: p2p: do not log to global when re-blocking a subnet --- src/p2p/net_node.inl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 733c7acf7..30e3d31b9 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -333,6 +333,7 @@ namespace nodetool limit = std::numeric_limits::max(); else limit = now + seconds; + const bool added = m_blocked_subnets.find(subnet) == m_blocked_subnets.end(); m_blocked_subnets[subnet] = limit; // drop any connection to that subnet. This should only have to look into @@ -365,7 +366,10 @@ namespace nodetool conns.clear(); } - MCLOG_CYAN(el::Level::Info, "global", "Subnet " << subnet.host_str() << " blocked."); + if (added) + MCLOG_CYAN(el::Level::Info, "global", "Subnet " << subnet.host_str() << " blocked."); + else + MINFO("Subnet " << subnet.host_str() << " blocked."); return true; } //----------------------------------------------------------------------------------- -- cgit v1.2.3