]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Check that chunks we request aren't being hashed or queued for hash
authorMatt Joiner <anacrolix@gmail.com>
Tue, 26 Jun 2018 03:04:15 +0000 (13:04 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 26 Jun 2018 03:04:15 +0000 (13:04 +1000)
connection.go
misc.go
torrent.go

index 6e9fd0288390d28831c4aeb1e0dd2a5d166b144f..cea8dab68b254285aea3eca8142e23d733d79d65 100644 (file)
@@ -498,6 +498,12 @@ func (cn *connection) request(r request, mw messageWriter) bool {
                        panic("requesting while choked and not allowed fast")
                }
        }
+       if cn.t.hashingPiece(pieceIndex(r.Index)) {
+               panic("piece is being hashed")
+       }
+       if cn.t.pieceQueuedForHash(pieceIndex(r.Index)) {
+               panic("piece is queued for hash")
+       }
        if cn.requests == nil {
                cn.requests = make(map[request]struct{})
        }
diff --git a/misc.go b/misc.go
index 10df12447466360a6715cffd0c775bdab0970122..bab40e1721952fd936e1625d4004e8c41ec44db2 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -168,3 +168,5 @@ func min(as ...int64) int64 {
 }
 
 var unlimited = rate.NewLimiter(rate.Inf, 0)
+
+type pieceIndex = int
index fe3df93f4ca125c1f5685f541d757d8bf3c1310c..5736dee5ff7ca891180a499b308014835d9fcf23 100644 (file)
@@ -1776,3 +1776,11 @@ func (t *Torrent) allStats(f func(*ConnStats)) {
        f(&t.stats)
        f(&t.cl.stats)
 }
+
+func (t *Torrent) hashingPiece(i pieceIndex) bool {
+       return t.pieces[i].hashing
+}
+
+func (t *Torrent) pieceQueuedForHash(i pieceIndex) bool {
+       return t.piecesQueuedForHash.Get(bitmap.BitIndex(i))
+}