]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Reduce ban logging
authorMatt Joiner <anacrolix@gmail.com>
Mon, 14 Jul 2025 05:32:31 +0000 (15:32 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 14 Jul 2025 05:32:31 +0000 (15:32 +1000)
client.go
internal/math/math.go [new file with mode: 0644]
metainfo/piece-key.go [moved from metainfo/piece_key.go with 100% similarity]
torrent.go

index 442b7138b13c81a48aff7dbe06830c2467c10173..de598591141ecc97c7f27aff5e3e8091f6e9da3a 100644 (file)
--- 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 (file)
index 0000000..c91c24e
--- /dev/null
@@ -0,0 +1 @@
+package math
similarity index 100%
rename from metainfo/piece_key.go
rename to metainfo/piece-key.go
index 02556bfc4df4c97719168aa3c1950b8daba6a2ac..c2407696b2a1627e009d28a4f56605bdaeb70db6 100644 (file)
@@ -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.
                                }
                        }
                }