feat: add namesys publish options (#94)
* feat: add namesys publish options * feat: export DefaultIPNSRecordEOL * feat: export DefaultIPNSRecordTTL This commit was moved from ipfs/interface-go-ipfs-core@468dea4bb45aec6ddce2a6225334dcc062d6e752 This commit was moved from ipfs/boxo@bcb9190c2bdbc0ad4823a1b1785fb87ec8014723
Henrique Dias committed
Jan 24, 2023 at 23:44 UTC
b3cc938630bc7607f86afed9ba4c1cdfda07e828
1 file changed
+49
core/coreiface/options/namesys/opts.go
+49
@@ -13,6 +13,15 @@ const (
13
// trust resolution to eventually complete and can't put an upper
14
// limit on how many steps it will take.
15
UnlimitedDepth = 0
16
+
17
+ // DefaultIPNSRecordTTL specifies the time that the record can be cached
18
+ // before checking if its validity again.
19
+ DefaultIPNSRecordTTL = time.Minute
20
+
21
+ // DefaultIPNSRecordEOL specifies the time that the network will cache IPNS
22
+ // records after being published. Records should be re-published before this
23
+ // interval expires. We use the same default expiration as the DHT.
24
+ DefaultIPNSRecordEOL = 48 * time.Hour
25
)
26
27
// ResolveOpts specifies options for resolving an IPNS path
@@ -72,3 +81,43 @@ func ProcessOpts(opts []ResolveOpt) ResolveOpts {
81
}
82
return rsopts
83
}
84
+
85
+// PublishOptions specifies options for publishing an IPNS record.
86
+type PublishOptions struct {
87
+ EOL time.Time
88
+ TTL time.Duration
89
+}
90
+
91
+// DefaultPublishOptions returns the default options for publishing an IPNS record.
92
+func DefaultPublishOptions() PublishOptions {
93
+ return PublishOptions{
94
+ EOL: time.Now().Add(DefaultIPNSRecordEOL),
95
+ TTL: DefaultIPNSRecordTTL,
96
+ }
97
+}
98
+
99
+// PublishOption is used to set an option for PublishOpts.
100
+type PublishOption func(*PublishOptions)
101
+
102
+// PublishWithEOL sets an EOL.
103
+func PublishWithEOL(eol time.Time) PublishOption {
104
+ return func(o *PublishOptions) {
105
+ o.EOL = eol
106
+ }
107
+}
108
+
109
+// PublishWithEOL sets a TTL.
110
+func PublishWithTTL(ttl time.Duration) PublishOption {
111
+ return func(o *PublishOptions) {
112
+ o.TTL = ttl
113
+ }
114
+}
115
+
116
+// ProcessPublishOptions converts an array of PublishOpt into a PublishOpts object.
117
+func ProcessPublishOptions(opts []PublishOption) PublishOptions {
118
+ rsopts := DefaultPublishOptions()
119
+ for _, option := range opts {
120
+ option(&rsopts)
121
+ }
122
+ return rsopts
123
+}