Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ipns max cache ttl #91

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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.",
},

Check warning on line 206 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L201-L206

Added lines #L201 - L206 were not covered by tests
}

app.Commands = []*cli.Command{
Expand Down Expand Up @@ -296,6 +302,7 @@
RoutingV1: cctx.String("routing"),
KuboRPCURLs: getEnvs(EnvKuboRPC, DefaultKuboRPC),
DHTSharedHost: cctx.Bool("dht-shared-host"),
IpnsMaxCacheTTL: cctx.Duration("ipns-max-cache-ttl"),

Check warning on line 305 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L305

Added line #L305 was not covered by tests
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 @@
RoutingV1 string
KuboRPCURLs []string
DHTSharedHost bool
IpnsMaxCacheTTL time.Duration

DenylistSubs []string
Peering []peer.AddrInfo
Expand Down Expand Up @@ -346,7 +347,11 @@
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))
}

Check warning on line 353 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L352-L353

Added lines #L352 - L353 were not covered by tests
ns, err := namesys.NewNameSystem(vs, nsOptions...)
if err != nil {
return nil, err
}
Expand Down
Loading