From 106da41487e4a0536215533b76d32e2e0e8c6138 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 14 Jul 2025 15:32:31 +1000 Subject: [PATCH] Reduce ban logging --- client.go | 9 ++++----- internal/math/math.go | 1 + metainfo/{piece_key.go => piece-key.go} | 0 torrent.go | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 internal/math/math.go rename metainfo/{piece_key.go => piece-key.go} (100%) diff --git a/client.go b/client.go index 442b7138..de598591 100644 --- a/client.go +++ b/client.go @@ -1674,14 +1674,13 @@ func (cl *Client) banPeerIP(ip net.IP) { // We can't take this from string, because it will lose netip's v4on6. net.ParseIP parses v4 // addresses directly to v4on6, which doesn't compare equal with v4. ipAddr, ok := netip.AddrFromSlice(ip) - if !ok { - panic(ip) - } - g.MakeMapIfNilAndSet(&cl.badPeerIPs, ipAddr, struct{}{}) + panicif.False(ok) + g.MakeMapIfNil(&cl.badPeerIPs) + cl.badPeerIPs[ipAddr] = struct{}{} for t := range cl.torrents { t.iterPeers(func(p *Peer) { if p.remoteIp().Equal(ip) { - t.logger.Levelf(log.Warning, "dropping peer %v with banned ip %v", p, ip) + t.slogger().Debug("dropping peer with banned ip", "peer", p, "ip", ip) // Should this be a close? p.drop() } diff --git a/internal/math/math.go b/internal/math/math.go new file mode 100644 index 00000000..c91c24e9 --- /dev/null +++ b/internal/math/math.go @@ -0,0 +1 @@ +package math diff --git a/metainfo/piece_key.go b/metainfo/piece-key.go similarity index 100% rename from metainfo/piece_key.go rename to metainfo/piece-key.go diff --git a/torrent.go b/torrent.go index 02556bfc..c2407696 100644 --- a/torrent.go +++ b/torrent.go @@ -2559,11 +2559,12 @@ func (t *Torrent) pieceHashed(piece pieceIndex, passed bool, hashIoErr error) { // single peer for a piece, and we never progress that piece to completion, we // will never smart-ban them. Discovered in // https://github.com/anacrolix/torrent/issues/715. - t.slogger().Warn( + t.slogger().Info( "piece failed hash. banning peer", "piece", piece, "peer", c) c.ban() + // TODO: Check if we now have no available peers for pieces we want. } } } -- 2.51.0