From 8e5d734998e249cb618ebfb519d5d3a84a426d2d Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 7 Dec 2022 14:36:46 +0100 Subject: [PATCH 1/3] feat: add namesys publish options --- options/namesys/opts.go | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/options/namesys/opts.go b/options/namesys/opts.go index ee2bd5a..da0301d 100644 --- a/options/namesys/opts.go +++ b/options/namesys/opts.go @@ -72,3 +72,48 @@ func ProcessOpts(opts []ResolveOpt) ResolveOpts { } return rsopts } + +// defaultRecordEOL 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. +const defaultRecordEOL = 48 * time.Hour + +// PublishOptions specifies options for publishing an IPNS record. +type PublishOptions struct { + EOL time.Time + TTL time.Duration +} + +// DefaultPublishOptions returns the default options for publishing an IPNS record. +func DefaultPublishOptions() PublishOptions { + return PublishOptions{ + EOL: time.Now().Add(defaultRecordEOL), + TTL: time.Minute, + } +} + +// PublishOption is used to set an option for PublishOpts. +type PublishOption func(*PublishOptions) + +// PublishWithEOL sets an EOL. +func PublishWithEOL(eol time.Time) PublishOption { + return func(o *PublishOptions) { + o.EOL = eol + } +} + +// PublishWithEOL sets a TTL. +func PublishWithTTL(ttl time.Duration) PublishOption { + return func(o *PublishOptions) { + o.TTL = ttl + } +} + +// ProcessPublishOptions converts an array of PublishOpt into a PublishOpts object. +func ProcessPublishOptions(opts []PublishOption) PublishOptions { + rsopts := DefaultPublishOptions() + for _, option := range opts { + option(&rsopts) + } + return rsopts +} From 428e5972188e2714ec16464fe478aa2bd70e89d9 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 24 Jan 2023 14:14:56 +0100 Subject: [PATCH 2/3] feat: export DefaultIPNSRecordEOL --- options/namesys/opts.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/options/namesys/opts.go b/options/namesys/opts.go index da0301d..138b378 100644 --- a/options/namesys/opts.go +++ b/options/namesys/opts.go @@ -13,6 +13,11 @@ const ( // trust resolution to eventually complete and can't put an upper // limit on how many steps it will take. UnlimitedDepth = 0 + + // 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 ) // ResolveOpts specifies options for resolving an IPNS path @@ -73,11 +78,6 @@ func ProcessOpts(opts []ResolveOpt) ResolveOpts { return rsopts } -// defaultRecordEOL 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. -const defaultRecordEOL = 48 * time.Hour - // PublishOptions specifies options for publishing an IPNS record. type PublishOptions struct { EOL time.Time @@ -87,7 +87,7 @@ type PublishOptions struct { // DefaultPublishOptions returns the default options for publishing an IPNS record. func DefaultPublishOptions() PublishOptions { return PublishOptions{ - EOL: time.Now().Add(defaultRecordEOL), + EOL: time.Now().Add(DefaultIPNSRecordEOL), TTL: time.Minute, } } From a5b18d489e07590eddb81f0274677131b2874455 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 24 Jan 2023 14:18:49 +0100 Subject: [PATCH 3/3] feat: export DefaultIPNSRecordTTL --- options/namesys/opts.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/options/namesys/opts.go b/options/namesys/opts.go index 138b378..0cd1ba7 100644 --- a/options/namesys/opts.go +++ b/options/namesys/opts.go @@ -14,6 +14,10 @@ const ( // limit on how many steps it will take. UnlimitedDepth = 0 + // DefaultIPNSRecordTTL specifies the time that the record can be cached + // before checking if its validity again. + DefaultIPNSRecordTTL = time.Minute + // 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. @@ -88,7 +92,7 @@ type PublishOptions struct { func DefaultPublishOptions() PublishOptions { return PublishOptions{ EOL: time.Now().Add(DefaultIPNSRecordEOL), - TTL: time.Minute, + TTL: DefaultIPNSRecordTTL, } }