From 162cef5d1b40a2c0282f0c967796c82477a7d803 Mon Sep 17 00:00:00 2001
From: Matt Joiner <anacrolix@gmail.com>
Date: Thu, 27 Jan 2022 15:12:26 +1100
Subject: [PATCH] When banning an IP drop peers that match

---
 client.go | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/client.go b/client.go
index 4815d53a..86c83e20 100644
--- 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) {
-- 
2.51.0