Skip to content

Commit

Permalink
steal stability
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt authored and AskAlexSharov committed Apr 24, 2024
1 parent 9ff12f4 commit 1ef0afe
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion requesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ef0afe

Please sign in to comment.