]> Sergey Matveev's repositories - btrtrc.git/commitdiff
When banning an IP drop peers that match
authorMatt Joiner <anacrolix@gmail.com>
Thu, 27 Jan 2022 04:12:26 +0000 (15:12 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 11 Mar 2022 02:59:47 +0000 (13:59 +1100)
client.go

index 4815d53a8d40917057742d6c1bc3243cc45f8022..86c83e20e91b3412d9a95469b083a4a4b4ba223c 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1489,6 +1489,14 @@ func (cl *Client) banPeerIP(ip net.IP) {
                cl.badPeerIPs = make(map[string]struct{})
        }
        cl.badPeerIPs[ip.String()] = 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)
+                               p.drop()
+                       }
+               })
+       }
 }
 
 func (cl *Client) newConnection(nc net.Conn, outgoing bool, remoteAddr PeerRemoteAddr, network, connString string) (c *PeerConn) {