]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Handle allowed fast while choked when requests already exist in the same piece
authorMatt Joiner <anacrolix@gmail.com>
Mon, 11 Oct 2021 11:04:53 +0000 (22:04 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 19 Oct 2021 03:08:56 +0000 (14:08 +1100)
peerconn.go

index a4ad595243d13b290dd9d7c926b6a3dd575adce8..e00006ffcb365380903a22bc7fcc60661d458fae 100644 (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: