From: Matt Joiner Date: Thu, 13 Jan 2022 03:04:02 +0000 (+1100) Subject: Apply smart bans under Client lock X-Git-Tag: v1.42.0~8^2^2~14 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4fb45412970a4020dc51a79931f6a92aa95824aa;p=btrtrc.git Apply smart bans under Client lock --- diff --git a/torrent.go b/torrent.go index a70bbd7d..688ca3f8 100644 --- a/torrent.go +++ b/torrent.go @@ -2155,13 +2155,6 @@ func (t *Torrent) pieceHasher(index pieceIndex) { p := t.piece(index) sum, failedPeers, copyErr := t.hashPiece(index) correct := sum == *p.hash - if correct { - for peer := range failedPeers { - t.cl.banPeerIP(peer.AsSlice()) - log.Printf("smart banned %v for piece %v", peer, index) - } - t.dropBannedPeers() - } switch copyErr { case nil, io.EOF: default: @@ -2170,6 +2163,13 @@ func (t *Torrent) pieceHasher(index pieceIndex) { t.storageLock.RUnlock() t.cl.lock() defer t.cl.unlock() + if correct { + for peer := range failedPeers { + t.cl.banPeerIP(peer.AsSlice()) + log.Printf("smart banned %v for piece %v", peer, index) + } + t.dropBannedPeers() + } p.hashing = false t.pieceHashed(index, correct, copyErr) t.updatePiecePriority(index, "Torrent.pieceHasher")