From a1dcd40071e9475ac85ff03580096c9155c5986a Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 13 Oct 2023 18:26:21 +0200 Subject: [PATCH 1/3] bitswap/client: explain what the options do Added godoc explanation of what the client options do in more detail, since given information was useless. --- bitswap/client/client.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bitswap/client/client.go b/bitswap/client/client.go index 2b4d76a54..d75b7c861 100644 --- a/bitswap/client/client.go +++ b/bitswap/client/client.go @@ -44,14 +44,20 @@ var log = logging.Logger("bitswap-client") // bitswap instances type Option func(*Client) -// ProviderSearchDelay overwrites the global provider search delay +// 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). func ProviderSearchDelay(newProvSearchDelay time.Duration) Option { return func(bs *Client) { bs.provSearchDelay = newProvSearchDelay } } -// RebroadcastDelay overwrites the global provider rebroadcast delay +// 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]. func RebroadcastDelay(newRebroadcastDelay delay.D) Option { return func(bs *Client) { bs.rebroadcastDelay = newRebroadcastDelay From 11e43b965546da51c96f94fb84e8112e2d45e48e Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 18 Oct 2023 12:46:48 +0200 Subject: [PATCH 2/3] bitswap: address feedback on client options. Expose RebroadcastDelay default. --- bitswap/client/client.go | 11 ++++++----- bitswap/internal/defaults/defaults.go | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bitswap/client/client.go b/bitswap/client/client.go index d75b7c861..f1308793d 100644 --- a/bitswap/client/client.go +++ b/bitswap/client/client.go @@ -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 @@ -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 diff --git a/bitswap/internal/defaults/defaults.go b/bitswap/internal/defaults/defaults.go index f9494a0da..c7ac566f5 100644 --- a/bitswap/internal/defaults/defaults.go +++ b/bitswap/internal/defaults/defaults.go @@ -3,6 +3,8 @@ package defaults import ( "encoding/binary" "time" + + delay "github.com/ipfs/go-ipfs-delay" ) const ( @@ -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) +) From 999944499b4968106c9c31a4eae601987787f28b Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 22 Nov 2023 12:27:57 +0100 Subject: [PATCH 3/3] bitswap: make use of default broadcast delay on initialization --- bitswap/client/client.go | 2 +- bitswap/internal/defaults/defaults.go | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bitswap/client/client.go b/bitswap/client/client.go index f1308793d..aa9ab78fa 100644 --- a/bitswap/client/client.go +++ b/bitswap/client/client.go @@ -175,7 +175,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, bstore blockstore dupMetric: bmetrics.DupHist(ctx), allMetric: bmetrics.AllHist(ctx), provSearchDelay: defaults.ProvSearchDelay, - rebroadcastDelay: delay.Fixed(time.Minute), + rebroadcastDelay: delay.Fixed(defaults.RebroadcastDelay), simulateDontHavesOnTimeout: true, } diff --git a/bitswap/internal/defaults/defaults.go b/bitswap/internal/defaults/defaults.go index c7ac566f5..f5511cc7a 100644 --- a/bitswap/internal/defaults/defaults.go +++ b/bitswap/internal/defaults/defaults.go @@ -3,8 +3,6 @@ package defaults import ( "encoding/binary" "time" - - delay "github.com/ipfs/go-ipfs-delay" ) const ( @@ -35,10 +33,8 @@ const ( // FIXME: expose this in go-verifcid. 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) + RebroadcastDelay = time.Minute )