Assert that a request isn't cancelled before requesting it again

This commit is contained in:
Matt Joiner 2021-12-13 11:56:57 +11:00
parent a671c06b94
commit 47ef8d9c2d
1 changed files with 3 additions and 0 deletions

View File

@ -570,6 +570,9 @@ type messageWriter func(pp.Message) bool
// when we want to go fast.
func (cn *Peer) shouldRequest(r RequestIndex) error {
pi := pieceIndex(r / cn.t.chunksPerRegularPiece())
if cn.requestState.Cancelled.Contains(r) {
return errors.New("request is cancelled and waiting acknowledgement")
}
if !cn.peerHasPiece(pi) {
return errors.New("requesting piece peer doesn't have")
}