requesting.go | 21 +++++++++++---------- diff --git a/requesting.go b/requesting.go index c5cd459e50669250cf01f4613c6e9fba1d1a3b5f..737771fec97a64ee0dda497b832c0a05c579ada0 100644 --- a/requesting.go +++ b/requesting.go @@ -180,8 +180,7 @@ func (p *Peer) getDesiredRequestState() (desired requestState) { input := p.t.cl.getRequestStrategyInput() requestHeap := peerRequests{ - requestIndexes: nil, - peer: p, + peer: p, } for _, t := range input.Torrents { if t.InfoHash == p.t.infoHash { @@ -198,6 +197,15 @@ } if !p.peerHasPiece(pieceIndex) { return } + allowedFast := p.peerAllowedFast.ContainsInt(pieceIndex) + if !allowedFast { + // We must signal interest to request this piece. + desired.Interested = true + if p.peerChoking { + // We can't request from this piece right now then. + return + } + } rsp.IterPendingChunks.Iter(func(ci request_strategy.ChunkIndex) { requestHeap.requestIndexes = append( requestHeap.requestIndexes, @@ -208,14 +216,7 @@ ) heap.Init(&requestHeap) for requestHeap.Len() != 0 && desired.Requests.GetCardinality() < uint64(p.nominalMaxRequests()) { requestIndex := heap.Pop(&requestHeap).(RequestIndex) - pieceIndex := requestIndex / p.t.chunksPerRegularPiece() - allowedFast := p.peerAllowedFast.Contains(pieceIndex) - if !allowedFast { - desired.Interested = true - } - if allowedFast || !p.peerChoking { - desired.Requests.Add(requestIndex) - } + desired.Requests.Add(requestIndex) } return }