Handle allowed fast while choked when requests already exist in the same piece

This commit is contained in:
Matt Joiner 2021-10-11 22:04:53 +11:00
parent 4258ff7c60
commit b2cabe7dbf
1 changed files with 17 additions and 8 deletions

View File

@ -1118,15 +1118,24 @@ func (c *PeerConn) mainReadLoop() (err error) {
torrent.Add("allowed fasts received", 1)
log.Fmsg("peer allowed fast: %d", msg.Index).AddValues(c).SetLevel(log.Debug).Log(c.t.logger)
pieceIndex := msg.Index.Int()
c.peerAllowedFast.AddInt(pieceIndex)
n := roaringBitmapRangeCardinality(
&c.actualRequestState.Requests,
t.pieceRequestIndexOffset(pieceIndex),
t.pieceRequestIndexOffset(pieceIndex+1))
if n != 0 {
panic(n)
// If we have outstanding requests that aren't currently counted toward the combined
// outstanding request count, increment them.
if c.peerAllowedFast.CheckedAdd(msg.Index.Uint32()) && c.peerChoking &&
// The check here could be against having the info, but really what we need to know
// is if there are any existing requests.
!c.actualRequestState.Requests.IsEmpty() {
i := c.actualRequestState.Requests.Iterator()
i.AdvanceIfNeeded(t.pieceRequestIndexOffset(pieceIndex))
for i.HasNext() {
r := i.Next()
if r >= t.pieceRequestIndexOffset(pieceIndex+1) {
break
}
c.t.pendingRequests.Inc(i.Next())
}
}
c.updateRequests("allowed fast")
c.updateRequests("PeerConn.mainReadLoop allowed fast")
case pp.Extended:
err = c.onReadExtendedMsg(msg.ExtendedID, msg.ExtendedPayload)
default: