Skip to content

Commit 2783fb8

Browse files
hacdiaslidel
andauthored
feat: ipns max cache ttl (#91)
* feat: ipns max cache ttl * docs: clarify TTL cap also applies to DNSLink * docs: clarify default respects original TTL --------- Co-authored-by: Marcin Rataj <[email protected]>
1 parent 0a5ca88 commit 2783fb8

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/environment-variables.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [`RAINBOW_TRUSTLESS_GATEWAY_DOMAINS`](#rainbow_trustless_gateway_domains)
99
- [`RAINBOW_GC_INTERVAL`](#rainbow_gc_interval)
1010
- [`RAINBOW_GC_THRESHOLD`](#rainbow_gc_threshold)
11+
- [`RAINBOW_IPNS_MAX_CACHE_TTL`](#rainbow_ipns_max_cache_ttl)
1112
- [`KUBO_RPC_URL`](#kubo_rpc_url)
1213
- [Logging](#logging)
1314
- [`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
6768

6869
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.
6970

70-
7171
Default: `60m`
7272

7373
## `RAINBOW_GC_THRESHOLD`
@@ -78,6 +78,19 @@ When the periodic GC runs, it checks for the total and available space on disk.
7878

7979
Default: `0.3` (always keep 30% of the disk available)
8080

81+
## `RAINBOW_IPNS_MAX_CACHE_TTL`
82+
83+
When set, it defines the upper bound limit (in ms) of how long a `/ipns/{id}`
84+
lookup result will be cached and read from cache before checking for updates.
85+
86+
The limit is applied to everything under the `/ipns/` namespace, and allows to cap both
87+
the [Time-To-Live (TTL)](https://specs.ipfs.tech/ipns/ipns-record/#ttl-uint64)
88+
of [IPNS Records](https://specs.ipfs.tech/ipns/ipns-record/)
89+
and the [TTL of DNS TXT records](https://datatracker.ietf.org/doc/html/rfc2181#section-8)
90+
with [DNSLink](https://dnslink.dev/).
91+
92+
Default: No upper bound, [TTL from IPNS Record](https://specs.ipfs.tech/ipns/ipns-record/#ttl-uint64) or [TTL from DNSLink](https://datatracker.ietf.org/doc/html/rfc2181#section-8) used as-is.
93+
8194
### `KUBO_RPC_URL`
8295

8396
Single URL or a comma separated list of RPC endpoints that provide legacy `/api/v0` from Kubo.

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ Generate an identity seed and launch a gateway:
198198
EnvVars: []string{"RAINBOW_BLOCKSTORE"},
199199
Usage: "Type of blockstore to use, such as flatfs or badger. See https://github.com/ipfs/rainbow/blockstore.md for more details",
200200
},
201+
&cli.DurationFlag{
202+
Name: "ipns-max-cache-ttl",
203+
Value: 0,
204+
EnvVars: []string{"RAINBOW_IPNS_MAX_CACHE_TTL"},
205+
Usage: "Optional cap on caching duration for IPNS/DNSLink lookups. Set to 0 to respect original TTLs.",
206+
},
201207
}
202208

203209
app.Commands = []*cli.Command{
@@ -296,6 +302,7 @@ share the same seed as long as the indexes are different.
296302
RoutingV1: cctx.String("routing"),
297303
KuboRPCURLs: getEnvs(EnvKuboRPC, DefaultKuboRPC),
298304
DHTSharedHost: cctx.Bool("dht-shared-host"),
305+
IpnsMaxCacheTTL: cctx.Duration("ipns-max-cache-ttl"),
299306
DenylistSubs: getCommaSeparatedList(cctx.String("denylists")),
300307
Peering: peeringAddrs,
301308
GCInterval: cctx.Duration("gc-interval"),

setup.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type Config struct {
101101
RoutingV1 string
102102
KuboRPCURLs []string
103103
DHTSharedHost bool
104+
IpnsMaxCacheTTL time.Duration
104105

105106
DenylistSubs []string
106107
Peering []peer.AddrInfo
@@ -346,7 +347,11 @@ func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cached
346347
if err != nil {
347348
return nil, err
348349
}
349-
ns, err := namesys.NewNameSystem(vs, namesys.WithDNSResolver(dns))
350+
nsOptions := []namesys.Option{namesys.WithDNSResolver(dns)}
351+
if cfg.IpnsMaxCacheTTL > 0 {
352+
nsOptions = append(nsOptions, namesys.WithMaxCacheTTL(cfg.IpnsMaxCacheTTL))
353+
}
354+
ns, err := namesys.NewNameSystem(vs, nsOptions...)
350355
if err != nil {
351356
return nil, err
352357
}

0 commit comments

Comments
 (0)