Skip to content

Commit

Permalink
refactor: DefaultRecordTTL DefaultRecordLifetime
Browse files Browse the repository at this point in the history
Moving defaults that are not specific to (re)publisher
  • Loading branch information
lidel committed Oct 17, 2023
1 parent 7662bd5 commit 0fdcc1f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ The following emojis are used to highlight certain changes:
is not.
* `namesys/resolver.ResolveIPNS` has been moved to `namesys.ResolveIPNS` and now returns a TTL
in addition to the resolved path.
*`boxo/ipns` record defaults follow recommendations from [IPNS Record Specification](https://specs.ipfs.tech/ipns/ipns-record/#ipns-record):
* `DefaultRecordTTL` is now set to 1h
* `DefaultRecordLifetime` now match the expiration window of Amino DHT and is set to 48h
* 🛠 The `gateway`'s `IPFSBackend.ResolveMutable` is now expected to return a TTL in addition to
the resolved path. If the TTL is unknown, 0 should be returned.

Expand Down
17 changes: 17 additions & 0 deletions ipns/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ipns

import "time"

const (

// DefaultRecordLifetime defines for how long IPNS record should be valid
// when ValidityType is 0. The default here aims to match the record
// expiration window of Amino DHT.
DefaultRecordLifetime = 48 * time.Hour

// DefaultRecordTTL specifies how long the record can be returned from
// cache before checking for update again. The function of this TTL is
// similar to TTL of DNS record, and the default here is a trade-off
// between faster updates and benefiting from various types of caching.
DefaultRecordTTL = 1 * time.Hour
)
15 changes: 3 additions & 12 deletions namesys/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ const (
// complete and can't put an upper limit on how many steps it will take.
UnlimitedDepth = 0

// DefaultIPNSRecordTTL specifies how long the record can be returned from
// cache before checking for update again.
DefaultIPNSRecordTTL = 1 * time.Hour

// DefaultIPNSRecordEOL specifies the time that the network will cache IPNS
// records after being published. Records should be re-published before this
// interval expires. We use the same default expiration as the DHT.
DefaultIPNSRecordEOL = 48 * time.Hour

// DefaultResolverCacheTTL defines max TTL of a record placed in [NameSystem] cache.
// DefaultResolverCacheTTL defines default TTL of a record placed in [NameSystem] cache.
DefaultResolverCacheTTL = time.Minute
)

Expand Down Expand Up @@ -184,8 +175,8 @@ type PublishOptions struct {
// DefaultPublishOptions returns the default options for publishing an IPNS Record.
func DefaultPublishOptions() PublishOptions {
return PublishOptions{
EOL: time.Now().Add(DefaultIPNSRecordEOL),
TTL: DefaultIPNSRecordTTL,
EOL: time.Now().Add(ipns.DefaultRecordLifetime),
TTL: ipns.DefaultRecordTTL,
}
}

Expand Down
2 changes: 1 addition & 1 deletion namesys/ipns_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// IPNSResolver implements [Resolver] for IPNS Records. This resolver always returns
// a TTL if the record is still valid. It happens as follows:
//
// 1. Provisory TTL is chosen: record TTL if it exists, otherwise [DefaultIPNSRecordTTL].
// 1. Provisory TTL is chosen: record TTL if it exists, otherwise `ipns.DefaultRecordTTL`.
// 2. If provisory TTL expires before EOL, then returned TTL is duration between EOL and now.
// 3. If record is expired, 0 is returned as TTL.
type IPNSResolver struct {
Expand Down
2 changes: 1 addition & 1 deletion namesys/republisher/repub.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
FailureRetryInterval = time.Minute * 5

// DefaultRecordLifetime is the default lifetime for IPNS records
DefaultRecordLifetime = time.Hour * 24
DefaultRecordLifetime = ipns.DefaultRecordLifetime
)

// Republisher facilitates the regular publishing of all the IPNS records
Expand Down

0 comments on commit 0fdcc1f

Please sign in to comment.