mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-17 06:57:40 +08:00
feat: add Ipns.MaxCacheTTL
This commit is contained in:
@ -1,11 +1,23 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultIpnsMaxCacheTTL = time.Duration(math.MaxInt64)
|
||||
)
|
||||
|
||||
type Ipns struct {
|
||||
RepublishPeriod string
|
||||
RecordLifetime string
|
||||
|
||||
ResolveCacheSize int
|
||||
|
||||
// MaxCacheTTL is the maximum duration IPNS entries are valid in the cache.
|
||||
MaxCacheTTL *OptionalDuration `json:",omitempty"`
|
||||
|
||||
// Enable namesys pubsub (--enable-namesys-pubsub)
|
||||
UsePubsub Flag `json:",omitempty"`
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
provider "github.com/ipfs/boxo/provider"
|
||||
offlineroute "github.com/ipfs/boxo/routing/offline"
|
||||
ipld "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/kubo/config"
|
||||
coreiface "github.com/ipfs/kubo/core/coreiface"
|
||||
"github.com/ipfs/kubo/core/coreiface/options"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
@ -225,12 +226,16 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
|
||||
return nil, fmt.Errorf("cannot specify negative resolve cache size")
|
||||
}
|
||||
|
||||
subAPI.routing = offlineroute.NewOfflineRouter(subAPI.repo.Datastore(), subAPI.recordValidator)
|
||||
|
||||
subAPI.namesys, err = namesys.NewNameSystem(subAPI.routing,
|
||||
nsOptions := []namesys.Option{
|
||||
namesys.WithDatastore(subAPI.repo.Datastore()),
|
||||
namesys.WithDNSResolver(subAPI.dnsResolver),
|
||||
namesys.WithCache(cs))
|
||||
namesys.WithCache(cs),
|
||||
namesys.WithMaxCacheTTL(cfg.Ipns.MaxCacheTTL.WithDefault(config.DefaultIpnsMaxCacheTTL)),
|
||||
}
|
||||
|
||||
subAPI.routing = offlineroute.NewOfflineRouter(subAPI.repo.Datastore(), subAPI.recordValidator)
|
||||
|
||||
subAPI.namesys, err = namesys.NewNameSystem(subAPI.routing, nsOptions...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error constructing namesys: %w", err)
|
||||
}
|
||||
|
@ -135,11 +135,15 @@ func newGatewayBackend(n *core.IpfsNode) (gateway.IPFSBackend, error) {
|
||||
return nil, fmt.Errorf("cannot specify negative resolve cache size")
|
||||
}
|
||||
|
||||
vsRouting = offlineroute.NewOfflineRouter(n.Repo.Datastore(), n.RecordValidator)
|
||||
nsys, err = namesys.NewNameSystem(vsRouting,
|
||||
nsOptions := []namesys.Option{
|
||||
namesys.WithDatastore(n.Repo.Datastore()),
|
||||
namesys.WithDNSResolver(n.DNSResolver),
|
||||
namesys.WithCache(cs))
|
||||
namesys.WithCache(cs),
|
||||
namesys.WithMaxCacheTTL(cfg.Ipns.MaxCacheTTL.WithDefault(config.DefaultIpnsMaxCacheTTL)),
|
||||
}
|
||||
|
||||
vsRouting = offlineroute.NewOfflineRouter(n.Repo.Datastore(), n.RecordValidator)
|
||||
nsys, err = namesys.NewNameSystem(vsRouting, nsOptions...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error constructing namesys: %w", err)
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ func Online(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
|
||||
fx.Provide(BitswapOptions(cfg, shouldBitswapProvide)),
|
||||
fx.Provide(OnlineExchange()),
|
||||
fx.Provide(DNSResolver),
|
||||
fx.Provide(Namesys(ipnsCacheSize)),
|
||||
fx.Provide(Namesys(ipnsCacheSize, cfg.Ipns.MaxCacheTTL.WithDefault(config.DefaultIpnsMaxCacheTTL))),
|
||||
fx.Provide(Peering),
|
||||
PeerWith(cfg.Peering.Peers...),
|
||||
|
||||
@ -296,7 +296,7 @@ func Offline(cfg *config.Config) fx.Option {
|
||||
return fx.Options(
|
||||
fx.Provide(offline.Exchange),
|
||||
fx.Provide(DNSResolver),
|
||||
fx.Provide(Namesys(0)),
|
||||
fx.Provide(Namesys(0, 0)),
|
||||
fx.Provide(libp2p.Routing),
|
||||
fx.Provide(libp2p.ContentRouting),
|
||||
fx.Provide(libp2p.OfflineRouting),
|
||||
|
@ -28,11 +28,12 @@ func RecordValidator(ps peerstore.Peerstore) record.Validator {
|
||||
}
|
||||
|
||||
// Namesys creates new name system
|
||||
func Namesys(cacheSize int) func(rt irouting.ProvideManyRouter, rslv *madns.Resolver, repo repo.Repo) (namesys.NameSystem, error) {
|
||||
func Namesys(cacheSize int, cacheMaxTTL time.Duration) func(rt irouting.ProvideManyRouter, rslv *madns.Resolver, repo repo.Repo) (namesys.NameSystem, error) {
|
||||
return func(rt irouting.ProvideManyRouter, rslv *madns.Resolver, repo repo.Repo) (namesys.NameSystem, error) {
|
||||
opts := []namesys.Option{
|
||||
namesys.WithDatastore(repo.Datastore()),
|
||||
namesys.WithDNSResolver(rslv),
|
||||
namesys.WithMaxCacheTTL(cacheMaxTTL),
|
||||
}
|
||||
|
||||
if cacheSize > 0 {
|
||||
|
@ -20,6 +20,10 @@ Support for exposing the legacy subset of Kubo RPC via the Gateway port is depre
|
||||
|
||||
If you have a legacy software that relies on this behavior, and want to expose parts of `/api/v0` next to `/ipfs`, use reverse-proxy in front of Kubo to mount both Gateway and RPC on the same port. NOTE: exposing RPC to the internet comes with security risk: make sure to specify access control via [API.Authorizations](https://github.com/ipfs/kubo/blob/master/docs/config.md#apiauthorizations).
|
||||
|
||||
#### IPNS resolver cache's TTL can now be configured
|
||||
|
||||
You can now configure the upper-bound of a cached IPNS entry's Time-To-Live via [`Ipns.MaxCacheTTL`](https://github.com/ipfs/kubo/blob/master/docs/config.md#ipnsmaxcachettl).
|
||||
|
||||
### 📝 Changelog
|
||||
|
||||
### 👨👩👧👦 Contributors
|
||||
|
@ -84,6 +84,7 @@ config file at runtime.
|
||||
- [`Ipns.RepublishPeriod`](#ipnsrepublishperiod)
|
||||
- [`Ipns.RecordLifetime`](#ipnsrecordlifetime)
|
||||
- [`Ipns.ResolveCacheSize`](#ipnsresolvecachesize)
|
||||
- [`Ipns.MaxCacheTTL`](#ipnsmaxcachettl)
|
||||
- [`Ipns.UsePubsub`](#ipnsusepubsub)
|
||||
- [`Migration`](#migration)
|
||||
- [`Migration.DownloadSources`](#migrationdownloadsources)
|
||||
@ -1138,6 +1139,35 @@ Default: `128`
|
||||
|
||||
Type: `integer` (non-negative, 0 means the default)
|
||||
|
||||
### `Ipns.MaxCacheTTL`
|
||||
|
||||
Maximum duration for which entries are valid in the name system cache. Applied
|
||||
to everything under `/ipns/` namespace, allows you to cap
|
||||
the [Time-To-Live (TTL)](https://specs.ipfs.tech/ipns/ipns-record/#ttl-uint64) of
|
||||
[IPNS Records](https://specs.ipfs.tech/ipns/ipns-record/)
|
||||
AND also DNSLink TXT records (when DoH-specific [`DNS.MaxCacheTTL`](https://github.com/ipfs/kubo/blob/master/docs/config.md#dnsmaxcachettl)
|
||||
is not set to a lower value).
|
||||
|
||||
When `Ipns.MaxCacheTTL` is set, it defines the upper bound limit of how long a
|
||||
[IPNS Name](https://specs.ipfs.tech/ipns/ipns-record/#ipns-name) lookup result
|
||||
will be cached and read from cache before checking for updates.
|
||||
|
||||
**Examples:**
|
||||
* `"1m"` IPNS results are cached 1m or less (good compromise for system where
|
||||
faster updates are desired).
|
||||
* `"0s"` IPNS caching is effectively turned off (useful for testing, bad for production use)
|
||||
- **Note:** setting this to `0` will turn off TTL-based caching entirely.
|
||||
This is discouraged in production environments. It will make IPNS websites
|
||||
artificially slow because IPNS resolution results will expire as soon as
|
||||
they are retrieved, forcing expensive IPNS lookup to happen on every
|
||||
request. If you want near-real-time IPNS, set it to a low, but still
|
||||
sensible value, such as `1m`.
|
||||
|
||||
Default: No upper bound, [TTL from IPNS Record](https://specs.ipfs.tech/ipns/ipns-record/#ttl-uint64) (see `ipns name publish --help`) is always respected.
|
||||
|
||||
|
||||
Type: `optionalDuration`
|
||||
|
||||
### `Ipns.UsePubsub`
|
||||
|
||||
Enables IPFS over pubsub experiment for publishing IPNS records in real time.
|
||||
@ -2317,7 +2347,7 @@ If present, the upper bound is applied to DoH resolvers in [`DNS.Resolvers`](#dn
|
||||
Note: this does NOT work with Go's default DNS resolver. To make this a global setting, add a `.` entry to `DNS.Resolvers` first.
|
||||
|
||||
**Examples:**
|
||||
* `"5m"` DNS entries are kept for 5 minutes or less.
|
||||
* `"1m"` DNS entries are kept for 1 minute or less.
|
||||
* `"0s"` DNS entries expire as soon as they are retrieved.
|
||||
|
||||
Default: Respect DNS Response TTL
|
||||
|
@ -7,7 +7,7 @@ go 1.20
|
||||
replace github.com/ipfs/kubo => ./../../..
|
||||
|
||||
require (
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a
|
||||
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
|
||||
github.com/libp2p/go-libp2p v0.32.2
|
||||
github.com/multiformats/go-multiaddr v0.12.1
|
||||
|
@ -260,8 +260,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy
|
||||
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
|
||||
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
|
||||
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8 h1:/d+3/JOYsHS4Uo+6WIxu2oHHlM5WjWOySYItN9V+YHs=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a h1:BMxa0aXrjyGh5gAkzxVsjDN71YhAWGfjbOoNvZt4/jg=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
|
||||
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
|
||||
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
|
||||
github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk=
|
||||
|
2
go.mod
2
go.mod
@ -17,7 +17,7 @@ require (
|
||||
github.com/hashicorp/go-multierror v1.1.1
|
||||
github.com/ipfs-shipyard/nopfs v0.0.12
|
||||
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a
|
||||
github.com/ipfs/go-block-format v0.2.0
|
||||
github.com/ipfs/go-cid v0.4.1
|
||||
github.com/ipfs/go-cidutil v0.1.0
|
||||
|
4
go.sum
4
go.sum
@ -325,8 +325,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy
|
||||
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
|
||||
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
|
||||
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8 h1:/d+3/JOYsHS4Uo+6WIxu2oHHlM5WjWOySYItN9V+YHs=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a h1:BMxa0aXrjyGh5gAkzxVsjDN71YhAWGfjbOoNvZt4/jg=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
|
||||
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
|
||||
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
|
||||
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=
|
||||
|
@ -103,7 +103,7 @@ require (
|
||||
github.com/hexops/gotextdiff v1.0.3 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/ipfs/bbloom v0.0.4 // indirect
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8 // indirect
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a // indirect
|
||||
github.com/ipfs/go-block-format v0.2.0 // indirect
|
||||
github.com/ipfs/go-cid v0.4.1 // indirect
|
||||
github.com/ipfs/go-datastore v0.6.0 // indirect
|
||||
|
@ -342,8 +342,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
|
||||
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8 h1:/d+3/JOYsHS4Uo+6WIxu2oHHlM5WjWOySYItN9V+YHs=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240125173442-bf34cd0777d8/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a h1:BMxa0aXrjyGh5gAkzxVsjDN71YhAWGfjbOoNvZt4/jg=
|
||||
github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
|
||||
github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs=
|
||||
github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM=
|
||||
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
|
||||
|
Reference in New Issue
Block a user