Track requests that are preserved across chokings

This commit is contained in:
Matt Joiner 2021-10-12 13:06:11 +11:00
parent 0a8e66c7fc
commit 3f3bcab0d8
1 changed files with 8 additions and 0 deletions

View File

@ -1057,12 +1057,20 @@ func (c *PeerConn) mainReadLoop() (err error) {
return errors.New("got unchoke but not choked")
}
c.peerChoking = false
preservedCount := 0
c.actualRequestState.Requests.Iterate(func(x uint32) bool {
if !c.peerAllowedFast.Contains(x / c.t.chunksPerRegularPiece()) {
preservedCount++
c.t.pendingRequests.Inc(x)
}
return true
})
if preservedCount != 0 {
// TODO: Yes this is a debug log but I'm not happy with the state of the logging lib
// right now.
log.Printf("%v requests were preserved while being choked", preservedCount)
torrent.Add("requestsPreservedThroughChoking", int64(preservedCount))
}
c.updateRequests("unchoked")
c.updateExpectingChunks()
case pp.Interested: