]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Support banning webseeds
authorMatt Joiner <anacrolix@gmail.com>
Fri, 11 Mar 2022 02:33:34 +0000 (13:33 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 11 Mar 2022 03:05:31 +0000 (14:05 +1100)
client.go
peer-impl.go
peerconn.go
torrent.go
webseed-peer.go

index 86c83e20e91b3412d9a95469b083a4a4b4ba223c..0d158395f96310bfe0ae06e98a93aeefec85c2de 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1493,6 +1493,7 @@ func (cl *Client) banPeerIP(ip net.IP) {
                t.iterPeers(func(p *Peer) {
                        if p.remoteIp().Equal(ip) {
                                t.logger.Levelf(log.Warning, "dropping peer %v with banned ip %v", p, ip)
+                               // Should this be a close?
                                p.drop()
                        }
                })
index e29fb43967cb255086dc3fa73dead6b077749df4..1b9cf978205506a598fbfbad1812a31cf5cafb40 100644 (file)
@@ -20,7 +20,10 @@ type peerImpl interface {
        connectionFlags() string
        onClose()
        onGotInfo(*metainfo.Info)
+       // Drop connection. This may be a no-op if there is no connection.
        drop()
+       // Rebuke the peer
+       ban()
        String() string
        connStatusString() string
 
index bc16ae6c63cabad8a18680e5ac9da3cb280c4574..6615d79c5a4573bab13a3561b5be4d95463fe170 100644 (file)
@@ -1590,6 +1590,10 @@ func (cn *PeerConn) drop() {
        cn.t.dropConnection(cn)
 }
 
+func (cn *PeerConn) ban() {
+       cn.t.cl.banPeerIP(cn.remoteIp())
+}
+
 func (cn *Peer) netGoodPiecesDirtied() int64 {
        return cn._stats.PiecesDirtiedGood.Int64() - cn._stats.PiecesDirtiedBad.Int64()
 }
index e148d38bd98de87ccdccf2ad53e57b79bf780c63..1c197f9b66bbf351ac1c010ad24a71e294195316 100644 (file)
@@ -2020,8 +2020,7 @@ func (t *Torrent) pieceHashed(piece pieceIndex, passed bool, hashIoErr error) {
 
                        if len(bannableTouchers) >= 1 {
                                c := bannableTouchers[0]
-                               t.cl.banPeerIP(c.remoteIp())
-                               c.drop()
+                               c.ban()
                        }
                }
                t.onIncompletePiece(piece)
index 9b1cba2233ec82f05d09a94b4a5177d3d592b138..0cdf4cacd4950300d27b2c4625fc92d10229f712 100644 (file)
@@ -114,10 +114,13 @@ func (ws *webseedPeer) connectionFlags() string {
        return "WS"
 }
 
-// TODO: This is called when banning peers. Perhaps we want to be able to ban webseeds too. We could
-// return bool if this is even possible, and if it isn't, skip to the next drop candidate.
+// Maybe this should drop all existing connections, or something like that.
 func (ws *webseedPeer) drop() {}
 
+func (cn *webseedPeer) ban() {
+       cn.peer.close()
+}
+
 func (ws *webseedPeer) handleUpdateRequests() {
        // Because this is synchronous, webseed peers seem to get first dibs on newly prioritized
        // pieces.