Skip to content

Commit

Permalink
feat: ipns max cache ttl (#91)
Browse files Browse the repository at this point in the history
* feat: ipns max cache ttl

* docs: clarify TTL cap also applies to DNSLink

* docs: clarify default respects original TTL

---------

Co-authored-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
hacdias and lidel authored Feb 19, 2024
1 parent 0a5ca88 commit 2783fb8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
15 changes: 14 additions & 1 deletion docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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`
Expand All @@ -78,6 +78,19 @@ 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`

When set, it defines the upper bound limit (in ms) of how long a `/ipns/{id}`
lookup result will be cached and read from cache before checking for updates.

The limit is applied to everything under the `/ipns/` namespace, and allows to cap both
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 the [TTL of DNS TXT records](https://datatracker.ietf.org/doc/html/rfc2181#section-8)
with [DNSLink](https://dnslink.dev/).

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.

### `KUBO_RPC_URL`

Single URL or a comma separated list of RPC endpoints that provide legacy `/api/v0` from Kubo.
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "Optional cap on caching duration for IPNS/DNSLink lookups. Set to 0 to respect original TTLs.",
},
}

app.Commands = []*cli.Command{
Expand Down Expand Up @@ -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"),
Expand Down
7 changes: 6 additions & 1 deletion setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type Config struct {
RoutingV1 string
KuboRPCURLs []string
DHTSharedHost bool
IpnsMaxCacheTTL time.Duration

DenylistSubs []string
Peering []peer.AddrInfo
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 2783fb8

Please sign in to comment.