]> Sergey Matveev's repositories - btrtrc.git/blobdiff - requesting.go
cmd/btrtrc client
[btrtrc.git] / requesting.go
index b70f2645e990b234b28703ab64927d42ae31d1a9..8b9db971b537630e65dd41ca9618f8a708f6a698 100644 (file)
@@ -173,9 +173,6 @@ func (p *Peer) getDesiredRequestState() (desired desiredRequestState) {
        if t.closed.IsSet() {
                return
        }
-       if t.dataDownloadDisallowed.Bool() {
-               return
-       }
        input := t.getRequestStrategyInput()
        requestHeap := desiredPeerRequests{
                peer:           p,
@@ -260,14 +257,14 @@ func (p *Peer) applyRequestState(next desiredRequestState) {
 
        t := p.t
        originalRequestCount := current.Requests.GetCardinality()
-       for {
-               if requestHeap.Len() == 0 {
-                       break
-               }
-               numPending := maxRequests(current.Requests.GetCardinality() + current.Cancelled.GetCardinality())
-               if numPending >= p.nominalMaxRequests() {
-                       break
-               }
+       // We're either here on a timer, or because we ran out of requests. Both are valid reasons to
+       // alter peakRequests.
+       if originalRequestCount != 0 && p.needRequestUpdate != peerUpdateRequestsTimerReason {
+               panic(fmt.Sprintf(
+                       "expected zero existing requests (%v) for update reason %q",
+                       originalRequestCount, p.needRequestUpdate))
+       }
+       for requestHeap.Len() != 0 && maxRequests(current.Requests.GetCardinality()+current.Cancelled.GetCardinality()) < p.nominalMaxRequests() {
                req := heap.Pop(requestHeap)
                existing := t.requestingPeer(req)
                if existing != nil && existing != p {