Skip to content

Commit 438b8a6

Browse files
authored
bitswap/client: explain what the options do
1 parent fe55533 commit 438b8a6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bitswap/client/client.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,21 @@ var log = logging.Logger("bitswap-client")
4444
// bitswap instances
4545
type Option func(*Client)
4646

47-
// ProviderSearchDelay overwrites the global provider search delay
47+
// ProviderSearchDelay sets the initial dely before triggering a provider
48+
// search to find more peers and broadcast the want list. It also partially
49+
// controls re-broadcasts delay when the session idles (does not receive any
50+
// blocks), but these have back-off logic to increase the interval. See
51+
// [defaults.ProvSearchDelay] for the default.
4852
func ProviderSearchDelay(newProvSearchDelay time.Duration) Option {
4953
return func(bs *Client) {
5054
bs.provSearchDelay = newProvSearchDelay
5155
}
5256
}
5357

54-
// RebroadcastDelay overwrites the global provider rebroadcast delay
58+
// RebroadcastDelay sets a custom delay for periodic search of a random want.
59+
// When the value ellapses, a random CID from the wantlist is chosen and the
60+
// client attempts to find more peers for it and sends them the single want.
61+
// [defaults.RebroadcastDelay] for the default.
5562
func RebroadcastDelay(newRebroadcastDelay delay.D) Option {
5663
return func(bs *Client) {
5764
bs.rebroadcastDelay = newRebroadcastDelay
@@ -168,7 +175,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, bstore blockstore
168175
dupMetric: bmetrics.DupHist(ctx),
169176
allMetric: bmetrics.AllHist(ctx),
170177
provSearchDelay: defaults.ProvSearchDelay,
171-
rebroadcastDelay: delay.Fixed(time.Minute),
178+
rebroadcastDelay: delay.Fixed(defaults.RebroadcastDelay),
172179
simulateDontHavesOnTimeout: true,
173180
}
174181

bitswap/internal/defaults/defaults.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ const (
3333
// FIXME: expose this in go-verifcid.
3434
MaximumHashLength = 128
3535
MaximumAllowedCid = binary.MaxVarintLen64*4 + MaximumHashLength
36+
37+
// RebroadcastDelay is the default delay to trigger broadcast of
38+
// random CIDs in the wantlist.
39+
RebroadcastDelay = time.Minute
3640
)

0 commit comments

Comments
 (0)