From f510c5cf22d46802cc316c040f5ade1aee89647a Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 6 Dec 2016 16:10:10 +1100 Subject: [PATCH] Fix piece failures not clearing dirty chunks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I don’t like how complicated piece completion/hashing management is, but it works. --- torrent.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/torrent.go b/torrent.go index 68cfb05b..2b9e4531 100644 --- a/torrent.go +++ b/torrent.go @@ -1445,21 +1445,24 @@ func (t *Torrent) pieceHashed(piece int, correct bool) { log.Printf("%T: error completing piece %d: %s", t.storage, piece, err) } t.updatePieceCompletion(piece) - } else if len(touchers) != 0 { - for _, c := range touchers { - // Y u do dis peer?! - c.badPiecesDirtied++ - } - slices.Sort(touchers, connLessTrusted) - log.Printf("dropping first corresponding conn from trust: %v", func() (ret []int) { + } else { + if len(touchers) != 0 { for _, c := range touchers { - ret = append(ret, c.netGoodPiecesDirtied()) + // Y u do dis peer?! + c.badPiecesDirtied++ } - return - }()) - c := touchers[0] - t.cl.banPeerIP(missinggo.AddrIP(c.remoteAddr())) - c.Drop() + slices.Sort(touchers, connLessTrusted) + log.Printf("dropping first corresponding conn from trust: %v", func() (ret []int) { + for _, c := range touchers { + ret = append(ret, c.netGoodPiecesDirtied()) + } + return + }()) + c := touchers[0] + t.cl.banPeerIP(missinggo.AddrIP(c.remoteAddr())) + c.Drop() + } + t.onIncompletePiece(piece) } } -- 2.48.1