From: Matt Joiner Date: Tue, 7 Dec 2021 03:19:44 +0000 (+1100) Subject: Only steal an odd request if the stealer more recently received a chunk X-Git-Tag: v1.39.0^2~4 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8c9a308c9afb9de13a7374cb9a64332e87f5cc66;p=btrtrc.git Only steal an odd request if the stealer more recently received a chunk This helps break the stealing cycle during endgame, and lets us trickle the request to the peer conn with the best record. It might not be sufficient but works nice in testing so far. --- diff --git a/requesting.go b/requesting.go index fdf638fe..aaaa4f9c 100644 --- a/requesting.go +++ b/requesting.go @@ -231,7 +231,14 @@ func (p *Peer) applyRequestState(next desiredRequestState) bool { continue } existing := t.requestingPeer(req) - if existing != nil && existing != p && existing.uncancelledRequests() > current.Requests.GetCardinality() { + if existing != nil && existing != p { + // 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)) { + continue + } t.cancelRequest(req) } more = p.mustRequest(req)