From: Matt Joiner Date: Tue, 6 Dec 2016 05:10:10 +0000 (+1100) Subject: Fix piece failures not clearing dirty chunks X-Git-Tag: v1.0.0~513 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f510c5cf22d46802cc316c040f5ade1aee89647a;p=btrtrc.git Fix piece failures not clearing dirty chunks I don’t like how complicated piece completion/hashing management is, but it works. --- 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) } }