connection.go | 6 ++++++ misc.go | 2 ++ torrent.go | 8 ++++++++ diff --git a/connection.go b/connection.go index 6e9fd0288390d28831c4aeb1e0dd2a5d166b144f..cea8dab68b254285aea3eca8142e23d733d79d65 100644 --- a/connection.go +++ b/connection.go @@ -498,6 +498,12 @@ } else { 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 --- a/misc.go +++ b/misc.go @@ -168,3 +168,5 @@ return ret } var unlimited = rate.NewLimiter(rate.Inf, 0) + +type pieceIndex = int diff --git a/torrent.go b/torrent.go index fe3df93f4ca125c1f5685f541d757d8bf3c1310c..5736dee5ff7ca891180a499b308014835d9fcf23 100644 --- a/torrent.go +++ b/torrent.go @@ -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)) +}