]> Sergey Matveev's repositories - btrtrc.git/commitdiff
steal stability
authorMark Holt <mark@distributed.vision>
Sat, 20 Apr 2024 07:17:09 +0000 (08:17 +0100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 26 Apr 2024 07:06:49 +0000 (17:06 +1000)
requesting.go

index a59250375ada02b3dd3f8672d75a63bca9493bd5..7ecb4e222169bc0c8129e731ca8d3df393db3433 100644 (file)
@@ -311,13 +311,22 @@ func (p *Peer) applyRequestState(next desiredRequestState) {
                if cap(next.Requests.requestIndexes) != cap(orig) {
                        panic("changed")
                }
+
+               if p.needRequestUpdate == "Peer.remoteRejectedRequest" {
+                       continue
+               }
+
                existing := t.requestingPeer(req)
                if existing != nil && existing != p {
+                       if p.needRequestUpdate == "Peer.cancel" {
+                               continue
+                       }
+
                        // Don't steal from the poor.
                        diff := int64(current.Requests.GetCardinality()) + 1 - (int64(existing.uncancelledRequests()) - 1)
                        // Steal a request that leaves us with one more request than the existing peer
                        // connection if the stealer more recently received a chunk.
-                       if diff > 1 || (diff == 1 && p.lastUsefulChunkReceived.Before(existing.lastUsefulChunkReceived)) {
+                       if diff > 1 || (diff == 1 && !p.lastUsefulChunkReceived.After(existing.lastUsefulChunkReceived)) {
                                continue
                        }
                        t.cancelRequest(req)