Do checks for preallocated requests too
Otherwise we reserve requests with the assumption that they can be assigned later, and they actually might not be.
This commit is contained in:
parent
9dd85e5bd2
commit
8e9cb9f2be
|
@ -187,11 +187,18 @@ func allocatePendingChunks(p pieceRequestOrderPiece, peers []*requestsPeer) {
|
||||||
preallocated := make(map[ChunkSpec]*peersForPieceRequests, p.NumPendingChunks)
|
preallocated := make(map[ChunkSpec]*peersForPieceRequests, p.NumPendingChunks)
|
||||||
p.iterPendingChunksWrapper(func(spec ChunkSpec) {
|
p.iterPendingChunksWrapper(func(spec ChunkSpec) {
|
||||||
req := Request{pp.Integer(p.index), spec}
|
req := Request{pp.Integer(p.index), spec}
|
||||||
for _, p := range peersForPiece {
|
for _, peer := range peersForPiece {
|
||||||
if h := p.HasExistingRequest; h != nil && h(req) {
|
if h := peer.HasExistingRequest; h == nil || !h(req) {
|
||||||
preallocated[spec] = p
|
continue
|
||||||
p.addNextRequest(req)
|
|
||||||
}
|
}
|
||||||
|
if !peer.canFitRequest() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !peer.canRequestPiece(p.index) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
preallocated[spec] = peer
|
||||||
|
peer.addNextRequest(req)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
pendingChunksRemaining := int(p.NumPendingChunks)
|
pendingChunksRemaining := int(p.NumPendingChunks)
|
||||||
|
|
Loading…
Reference in New Issue