Skip to content

Commit

Permalink
bitswap: address feedback on client options. Expose RebroadcastDelay …
Browse files Browse the repository at this point in the history
…default.
  • Loading branch information
hsanjuan authored and hacdias committed Nov 22, 2023
1 parent a1dcd40 commit 11e43b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions bitswap/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ var log = logging.Logger("bitswap-client")
// bitswap instances
type Option func(*Client)

// ProviderSearchDelay sets idle-delay value. When the session
// idles (does not receive any blocks) for this duration, a broadcast is
// triggered. The broadcast finds new peers and sends the wantlist. See
// [defaults.ProvSearchDelay] for the default (1s as of this writing).
// ProviderSearchDelay sets the initial dely before triggering a provider
// search to find more peers and broadcast the want list. It also partially
// controls re-broadcasts delay when the session idles (does not receive any
// blocks), but these have back-off logic to increase the interval. See
// [defaults.ProvSearchDelay] for the default.
func ProviderSearchDelay(newProvSearchDelay time.Duration) Option {
return func(bs *Client) {
bs.provSearchDelay = newProvSearchDelay
Expand All @@ -57,7 +58,7 @@ func ProviderSearchDelay(newProvSearchDelay time.Duration) Option {
// RebroadcastDelay sets a custom delay for periodic search of a random want.
// When the value ellapses, a random CID from the wantlist is chosen and the
// client attempts to find more peers for it and sends them the single want.
// Default is set to 1 minute in [New].
// [defaults.RebroadcastDelay] for the default.
func RebroadcastDelay(newRebroadcastDelay delay.D) Option {
return func(bs *Client) {
bs.rebroadcastDelay = newRebroadcastDelay
Expand Down
8 changes: 8 additions & 0 deletions bitswap/internal/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package defaults
import (
"encoding/binary"
"time"

delay "github.com/ipfs/go-ipfs-delay"
)

const (
Expand Down Expand Up @@ -34,3 +36,9 @@ const (
MaximumHashLength = 128
MaximumAllowedCid = binary.MaxVarintLen64*4 + MaximumHashLength
)

var (
// RebroadcastDelay is the default delay to trigger broadcast of
// random CIDs in the wantlist.
RebroadcastDelay = delay.Fixed(time.Minute)
)

0 comments on commit 11e43b9

Please sign in to comment.