}
cn.validReceiveChunks[r]++
cn.t.pendingRequests.Inc(r)
+ cn.t.lastRequested[r] = time.Now()
cn.updateExpectingChunks()
ppReq := cn.t.requestIndexToRequest(r)
for _, f := range cn.callbacks.SentRequest {
}
c.updateExpectingChunks()
c.t.pendingRequests.Dec(r)
+ if c.t.pendingRequests.Get(r) == 0 {
+ delete(c.t.lastRequested, r)
+ }
return true
}
ml = ml.Int(
int(leftPiece.availability),
int(rightPiece.availability))
+ leftLastRequested := p.peer.t.lastRequested[leftRequest]
+ rightLastRequested := p.peer.t.lastRequested[rightRequest]
+ ml = ml.EagerSameLess(
+ leftLastRequested.Equal(rightLastRequested),
+ leftLastRequested.Before(rightLastRequested),
+ )
ml = ml.Uint32(leftPieceIndex, rightPieceIndex)
ml = ml.Uint32(leftRequest, rightRequest)
return ml.MustLess()
return
}
}
+ // Note that we can still be interested if we filter all requests due to being
+ // recently requested from another peer.
+ if !p.actualRequestState.Requests.Contains(r) {
+ if time.Since(p.t.lastRequested[r]) < time.Second {
+ return
+ }
+ }
requestHeap.requestIndexes = append(requestHeap.requestIndexes, r)
})
},
break
}
}
+ // TODO: This may need to change, we might want to update even if there were no requests due to
+ // filtering them for being recently requested already.
p.updateRequestsTimer.Stop()
if more {
p.needRequestUpdate = ""
- if !current.Requests.IsEmpty() {
+ if current.Interested {
p.updateRequestsTimer.Reset(3 * time.Second)
}
}
// Count of each request across active connections.
pendingRequests pendingRequests
+ lastRequested map[RequestIndex]time.Time
// Chunks we've written to since the corresponding piece was last checked.
dirtyChunks roaring.Bitmap
close(t.gotMetainfoC)
t.updateWantPeersEvent()
t.pendingRequests.Init(t.numRequests())
+ t.lastRequested = make(map[RequestIndex]time.Time)
t.tryCreateMorePieceHashers()
t.iterPeers(func(p *Peer) {
p.onGotInfo(t.info)
func (t *Torrent) piecePriorityChanged(piece pieceIndex, reason string) {
if t._pendingPieces.Contains(uint32(piece)) {
t.iterPeers(func(c *Peer) {
- if c.actualRequestState.Interested {
- return
- }
+ // if c.actualRequestState.Interested {
+ // return
+ // }
if !c.isLowOnRequests() {
return
}