diff --git a/config/init.go b/config/init.go index 29e960e8bc8..9800f0c7abf 100644 --- a/config/init.go +++ b/config/init.go @@ -76,8 +76,8 @@ func InitWithIdentity(identity Identity) (*Config, error) { APICommands: []string{}, }, Reprovider: Reprovider{ - Interval: "12h", - Strategy: "all", + Interval: nil, + Strategy: nil, }, Pinning: Pinning{ RemoteServices: map[string]RemotePinningService{}, diff --git a/config/profile.go b/config/profile.go index 6748b5fb2b7..1db956e79d5 100644 --- a/config/profile.go +++ b/config/profile.go @@ -176,7 +176,7 @@ fetching may be degraded. Transform: func(c *Config) error { c.Routing.Type = "dhtclient" c.AutoNAT.ServiceMode = AutoNATServiceDisabled - c.Reprovider.Interval = "0" + c.Reprovider.Interval = NewOptionalDuration(0) lowWater := int64(20) highWater := int64(40) diff --git a/config/reprovider.go b/config/reprovider.go index fa029c2fc21..aad3b33914c 100644 --- a/config/reprovider.go +++ b/config/reprovider.go @@ -1,6 +1,6 @@ package config type Reprovider struct { - Interval string // Time period to reprovide locally stored objects to the network - Strategy string // Which keys to announce + Interval *OptionalDuration `json:",omitempty"` // Time period to reprovide locally stored objects to the network + Strategy *OptionalString `json:",omitempty"` // Which keys to announce } diff --git a/config/types.go b/config/types.go index e3f61546b51..1af244f9ce4 100644 --- a/config/types.go +++ b/config/types.go @@ -218,6 +218,11 @@ type OptionalDuration struct { value *time.Duration } +// NewOptionalDuration returns an OptionalDuration from a string +func NewOptionalDuration(d time.Duration) *OptionalDuration { + return &OptionalDuration{value: &d} +} + func (d *OptionalDuration) UnmarshalJSON(input []byte) error { switch string(input) { case "null", "undefined", "\"null\"", "", "default", "\"\"", "\"default\"": diff --git a/core/node/groups.go b/core/node/groups.go index 7bc4e894cf2..79809263702 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -291,7 +291,12 @@ func Online(bcfg *BuildCfg, cfg *config.Config) fx.Option { fx.Provide(p2p.New), LibP2P(bcfg, cfg), - OnlineProviders(cfg.Experimental.StrategicProviding, cfg.Experimental.AcceleratedDHTClient, cfg.Reprovider.Strategy, cfg.Reprovider.Interval), + OnlineProviders( + cfg.Experimental.StrategicProviding, + cfg.Experimental.AcceleratedDHTClient, + cfg.Reprovider.Strategy.WithDefault(DefaultReproviderStrategy), + cfg.Reprovider.Interval.WithDefault(DefaultReproviderInterval), + ), ) } @@ -304,7 +309,12 @@ func Offline(cfg *config.Config) fx.Option { fx.Provide(libp2p.Routing), fx.Provide(libp2p.ContentRouting), fx.Provide(libp2p.OfflineRouting), - OfflineProviders(cfg.Experimental.StrategicProviding, cfg.Experimental.AcceleratedDHTClient, cfg.Reprovider.Strategy, cfg.Reprovider.Interval), + OfflineProviders( + cfg.Experimental.StrategicProviding, + cfg.Experimental.AcceleratedDHTClient, + cfg.Reprovider.Strategy.WithDefault(DefaultReproviderStrategy), + cfg.Reprovider.Interval.WithDefault(DefaultReproviderInterval), + ), ) } diff --git a/core/node/provider.go b/core/node/provider.go index cf625b8c686..43410573e9f 100644 --- a/core/node/provider.go +++ b/core/node/provider.go @@ -18,7 +18,8 @@ import ( irouting "github.com/ipfs/kubo/routing" ) -const kReprovideFrequency = time.Hour * 12 +const DefaultReproviderInterval = time.Hour * 22 // https://github.com/ipfs/kubo/pull/9326 +const DefaultReproviderStrategy = "all" // SIMPLE @@ -61,20 +62,10 @@ func SimpleProviderSys(isOnline bool) interface{} { } // BatchedProviderSys creates new provider system -func BatchedProviderSys(isOnline bool, reprovideInterval string) interface{} { +func BatchedProviderSys(isOnline bool, reprovideInterval time.Duration) interface{} { return func(lc fx.Lifecycle, cr irouting.ProvideManyRouter, q *q.Queue, keyProvider simple.KeyChanFunc, repo repo.Repo) (provider.System, error) { - reprovideIntervalDuration := kReprovideFrequency - if reprovideInterval != "" { - dur, err := time.ParseDuration(reprovideInterval) - if err != nil { - return nil, err - } - - reprovideIntervalDuration = dur - } - sys, err := batched.New(cr, q, - batched.ReproviderInterval(reprovideIntervalDuration), + batched.ReproviderInterval(reprovideInterval), batched.Datastore(repo.Datastore()), batched.KeyProvider(keyProvider)) if err != nil { @@ -100,7 +91,7 @@ func BatchedProviderSys(isOnline bool, reprovideInterval string) interface{} { // ONLINE/OFFLINE // OnlineProviders groups units managing provider routing records online -func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval string) fx.Option { +func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval time.Duration) fx.Option { if useStrategicProviding { return fx.Provide(provider.NewOfflineProvider) } @@ -113,7 +104,7 @@ func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, repro } // OfflineProviders groups units managing provider routing records offline -func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval string) fx.Option { +func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval time.Duration) fx.Option { if useStrategicProviding { return fx.Provide(provider.NewOfflineProvider) } @@ -126,17 +117,7 @@ func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, repr } // SimpleProviders creates the simple provider/reprovider dependencies -func SimpleProviders(reprovideStrategy string, reprovideInterval string) fx.Option { - reproviderInterval := kReprovideFrequency - if reprovideInterval != "" { - dur, err := time.ParseDuration(reprovideInterval) - if err != nil { - return fx.Error(err) - } - - reproviderInterval = dur - } - +func SimpleProviders(reprovideStrategy string, reproviderInterval time.Duration) fx.Option { var keyProvider fx.Option switch reprovideStrategy { case "all": diff --git a/docs/changelogs/v0.18.md b/docs/changelogs/v0.18.md index 4afa6793ea9..39d88562aa8 100644 --- a/docs/changelogs/v0.18.md +++ b/docs/changelogs/v0.18.md @@ -11,6 +11,7 @@ Below is an outline of all that is in this release, so you get a sense of all th - [Overview](#overview) - [🔦 Highlights](#-highlights) - [(DAG-)JSON and (DAG-)CBOR Response Formats on Gateways](#dag-json-and-dag-cbor-response-formats-on-gateways) + - [Increased `Reprovider.Interval`](#increased-reproviderinterval) - [Changelog](#changelog) - [Contributors](#contributors) @@ -68,6 +69,16 @@ $ curl "http://127.0.0.1:8080/ipfs/$DIR_CID?format=dag-json" | jq } ``` +#### Increased `Reprovider.Interval` + +Default changed from 12h to 22h. +We also stopped `ipfs init` from hardcoding the default value in user config, allowing Kubo to adjust implicit default in future releases. + +Rationale for increasing this can be found in [RFM 17: Provider Record Livenes Report](https://github.com/protocol/network-measurements/blob/master/results/rfm17-provider-record-liveness.md) +and [kubo#9326](https://github.com/ipfs/kubo/pull/9326). + +Learn more: [`Reprovider` config](https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#reprovider) + ### Changelog ### Contributors