From ccf57798a2e9da4c6c37735e1d96bea0f30217cd Mon Sep 17 00:00:00 2001
From: Matt Joiner <anacrolix@gmail.com>
Date: Mon, 25 Oct 2021 20:53:39 +1100
Subject: [PATCH] Fix iter pending chunk request offsets

---
 requesting.go | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/requesting.go b/requesting.go
index 74d1d682..669b0d2a 100644
--- a/requesting.go
+++ b/requesting.go
@@ -214,6 +214,7 @@ func (p *Peer) getDesiredRequestState() (desired requestState) {
 			}
 			allowedFast := p.peerAllowedFast.ContainsInt(pieceIndex)
 			rsp.IterPendingChunks.Iter(func(ci request_strategy.ChunkIndex) {
+				r := p.t.pieceRequestIndexOffset(pieceIndex) + ci
 				if !allowedFast {
 					// We must signal interest to request this
 					desired.Interested = true
@@ -221,14 +222,12 @@ func (p *Peer) getDesiredRequestState() (desired requestState) {
 					// have made the request previously (presumably while unchoked), and haven't had
 					// the peer respond yet (and the request was retained because we are using the
 					// fast extension).
-					if p.peerChoking && !p.actualRequestState.Requests.Contains(ci) {
+					if p.peerChoking && !p.actualRequestState.Requests.Contains(r) {
 						// We can't request this right now.
 						return
 					}
 				}
-				requestHeap.requestIndexes = append(
-					requestHeap.requestIndexes,
-					p.t.pieceRequestIndexOffset(pieceIndex)+ci)
+				requestHeap.requestIndexes = append(requestHeap.requestIndexes, r)
 			})
 		},
 	)
-- 
2.51.0