Skip to content

Commit

Permalink
Remove peer's count of first responses when peer becomes unavailable (#…
Browse files Browse the repository at this point in the history
…757)

The peer response tracker counts the times each peer is first to response to block requests. When a peer becomes unavailabile, its count of first responses should be removed. This way we are not tracking the first response count for peers that are no longer available.
  • Loading branch information
gammazero authored Dec 17, 2024
1 parent 8854a6f commit a83de68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bitswap/client/internal/session/peerresponsetracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ func (prt *peerResponseTracker) getPeerCount(p peer.ID) int {
// will be chosen
return prt.firstResponder[p] + 1
}

func (prt *peerResponseTracker) remove(p peer.ID) {
delete(prt.firstResponder, p)
}
5 changes: 3 additions & 2 deletions bitswap/client/internal/session/sessionwantsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,15 @@ func (sws *sessionWantSender) processAvailability(availability map[peer.ID]bool)
if wasAvailable {
stateChange = true
newlyUnavailable = append(newlyUnavailable, p)
// Remove count of first responses from peer.
sws.peerRspTrkr.remove(p)
}
}

// If the state has changed
if stateChange {
sws.updateWantsPeerAvailability(p, isNowAvailable)
// Reset the count of consecutive DONT_HAVEs received from the
// peer
// Reset count of consecutive DONT_HAVEs received from the peer.
delete(sws.peerConsecutiveDontHaves, p)
}
}
Expand Down

0 comments on commit a83de68

Please sign in to comment.