diff --git a/provider/reprovider.go b/provider/reprovider.go index 055cfe5c9..2d79a62d8 100644 --- a/provider/reprovider.go +++ b/provider/reprovider.go @@ -18,6 +18,24 @@ import ( "github.com/multiformats/go-multihash" ) +const ( + // MAGIC: how long we wait before reproviding a key + DefaultReproviderInterval = time.Hour * 22 // https://github.com/ipfs/kubo/pull/9326 + + // MAGIC: If the reprovide ticker is larger than a minute (likely), provide + // once after we've been up a minute. Don't provide _immediately_ as we + // might be just about to stop. + defaultInitialReprovideDelay = time.Minute + + // MAGIC: how long we wait between the first provider we hear about and + // batching up the provides to send out + pauseDetectionThreshold = time.Millisecond * 500 + + // MAGIC: how long we are willing to collect providers for the batch after + // we receive the first one + maxCollectionDuration = time.Minute * 10 +) + var log = logging.Logger("provider.batched") type reprovider struct { @@ -83,7 +101,7 @@ var DefaultKeyPrefix = datastore.NewKey("/provider") // If provider casts to [Ready], it will wait until [Ready.Ready] is true. func New(ds datastore.Batching, opts ...Option) (System, error) { s := &reprovider{ - reprovideInterval: time.Hour * 24, + reprovideInterval: DefaultReproviderInterval, maxReprovideBatchSize: math.MaxUint, keyPrefix: DefaultKeyPrefix, reprovideCh: make(chan cid.Cid), @@ -96,13 +114,8 @@ func New(ds datastore.Batching, opts ...Option) (System, error) { } // Setup default behavior for the initial reprovide delay - // - // If the reprovide ticker is larger than a minute (likely), - // provide once after we've been up a minute. - // - // Don't provide _immediately_ as we might be just about to stop. - if !s.initialReprovideDelaySet && s.reprovideInterval > time.Minute { - s.initalReprovideDelay = time.Minute + if !s.initialReprovideDelaySet && s.reprovideInterval > defaultInitialReprovideDelay { + s.initalReprovideDelay = defaultInitialReprovideDelay s.initialReprovideDelaySet = true } @@ -194,12 +207,6 @@ func initialReprovideDelay(duration time.Duration) Option { } } -// how long we wait between the first provider we hear about and batching up the provides to send out -const pauseDetectionThreshold = time.Millisecond * 500 - -// how long we are willing to collect providers for the batch after we receive the first one -const maxCollectionDuration = time.Minute * 10 - func (s *reprovider) run() { provCh := s.q.Dequeue()