]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix piece failures not clearing dirty chunks
authorMatt Joiner <anacrolix@gmail.com>
Tue, 6 Dec 2016 05:10:10 +0000 (16:10 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 6 Dec 2016 05:10:10 +0000 (16:10 +1100)
I don’t like how complicated piece completion/hashing management is, but it works.

torrent.go

index 68cfb05bedb82d0136ac8cf920eea25a05ae21ca..2b9e4531763078241b4497cfb4f64befc4a9ce8b 100644 (file)
@@ -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)
        }
 }