From f96b6b93dae4e865b3322d7a84d6bc345fd7c3c9 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 19 Feb 2024 16:06:14 +0100 Subject: [PATCH] feat: ipns max cache ttl --- docs/environment-variables.md | 10 +++++++++- main.go | 7 +++++++ setup.go | 7 ++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/environment-variables.md b/docs/environment-variables.md index 3baca0a..315d84f 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -8,6 +8,7 @@ - [`RAINBOW_TRUSTLESS_GATEWAY_DOMAINS`](#rainbow_trustless_gateway_domains) - [`RAINBOW_GC_INTERVAL`](#rainbow_gc_interval) - [`RAINBOW_GC_THRESHOLD`](#rainbow_gc_threshold) + - [`RAINBOW_IPNS_MAX_CACHE_TTL`](#rainbow_ipns_max_cache_ttl) - [`KUBO_RPC_URL`](#kubo_rpc_url) - [Logging](#logging) - [`GOLOG_LOG_LEVEL`](#golog_log_level) @@ -67,7 +68,6 @@ Default: none (`Host` is ignored and gateway at `127.0.0.1` supports both deseri The interval at which the garbage collector will be called. This is given as a string that corresponds to the duration of the interval. Set 0 to disable. - Default: `60m` ## `RAINBOW_GC_THRESHOLD` @@ -78,6 +78,14 @@ When the periodic GC runs, it checks for the total and available space on disk. Default: `0.3` (always keep 30% of the disk available) +## `RAINBOW_IPNS_MAX_CACHE_TTL` + +The maximum duration which entries are valid in the name system cache. They are applied to everything under the `/ipns/` namespace, and 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/). + +When `RAINBOW_IPNS_MAX_CACHE_TTL` 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. + +Default: No upper bound, [TTL from IPNS Record](https://specs.ipfs.tech/ipns/ipns-record/#ttl-uint64) + ### `KUBO_RPC_URL` Single URL or a comma separated list of RPC endpoints that provide legacy `/api/v0` from Kubo. diff --git a/main.go b/main.go index ad0607b..7e7d748 100644 --- a/main.go +++ b/main.go @@ -198,6 +198,12 @@ Generate an identity seed and launch a gateway: EnvVars: []string{"RAINBOW_BLOCKSTORE"}, Usage: "Type of blockstore to use, such as flatfs or badger. See https://github.com/ipfs/rainbow/blockstore.md for more details", }, + &cli.DurationFlag{ + Name: "ipns-max-cache-ttl", + Value: 0, + EnvVars: []string{"RAINBOW_IPNS_MAX_CACHE_TTL"}, + Usage: "The maximum duration IPNS entries are valid in the cache. Set 0 to disable.", + }, } app.Commands = []*cli.Command{ @@ -296,6 +302,7 @@ share the same seed as long as the indexes are different. RoutingV1: cctx.String("routing"), KuboRPCURLs: getEnvs(EnvKuboRPC, DefaultKuboRPC), DHTSharedHost: cctx.Bool("dht-shared-host"), + IpnsMaxCacheTTL: cctx.Duration("ipns-max-cache-ttl"), DenylistSubs: getCommaSeparatedList(cctx.String("denylists")), Peering: peeringAddrs, GCInterval: cctx.Duration("gc-interval"), diff --git a/setup.go b/setup.go index fa3224d..4217f34 100644 --- a/setup.go +++ b/setup.go @@ -101,6 +101,7 @@ type Config struct { RoutingV1 string KuboRPCURLs []string DHTSharedHost bool + IpnsMaxCacheTTL time.Duration DenylistSubs []string Peering []peer.AddrInfo @@ -346,7 +347,11 @@ func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cached if err != nil { return nil, err } - ns, err := namesys.NewNameSystem(vs, namesys.WithDNSResolver(dns)) + nsOptions := []namesys.Option{namesys.WithDNSResolver(dns)} + if cfg.IpnsMaxCacheTTL > 0 { + nsOptions = append(nsOptions, namesys.WithMaxCacheTTL(cfg.IpnsMaxCacheTTL)) + } + ns, err := namesys.NewNameSystem(vs, nsOptions...) if err != nil { return nil, err }