Skip to content

Commit

Permalink
feat: ipns max cache ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Feb 19, 2024
1 parent 0a5ca88 commit f96b6b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 9 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,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.
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: "The maximum duration IPNS entries are valid in the cache. Set 0 to disable.",
},

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 @@ 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"),

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 @@ 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))
}

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

0 comments on commit f96b6b9

Please sign in to comment.