From 1ef0afe9d44b42b38fa33b246210172d3668c51b Mon Sep 17 00:00:00 2001 From: Mark Holt Date: Sat, 20 Apr 2024 08:17:09 +0100 Subject: [PATCH] steal stability --- requesting.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/requesting.go b/requesting.go index 1440207d52..2254d362ae 100644 --- a/requesting.go +++ b/requesting.go @@ -308,13 +308,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)