Skip to content

Commit

Permalink
relocated magic numbers, updated Reprovide Interval from 24h to 22h
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel authored and Jorropo committed May 24, 2023
1 parent d8be28c commit 316ed68
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions provider/reprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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
}

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 316ed68

Please sign in to comment.