From: Matt Joiner Date: Tue, 26 Jun 2018 03:04:15 +0000 (+1000) Subject: Check that chunks we request aren't being hashed or queued for hash X-Git-Tag: v1.0.0~118 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=7dd532d46fa84144c63e5ad6aa4d976a08d0b25b;p=btrtrc.git Check that chunks we request aren't being hashed or queued for hash --- diff --git a/connection.go b/connection.go index 6e9fd028..cea8dab6 100644 --- a/connection.go +++ b/connection.go @@ -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 10df1244..bab40e17 100644 --- 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 diff --git a/torrent.go b/torrent.go index fe3df93f..5736dee5 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)) +}