@@ -13,6 +13,15 @@ const (
13
13
// trust resolution to eventually complete and can't put an upper
14
14
// limit on how many steps it will take.
15
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
16
25
)
17
26
18
27
// ResolveOpts specifies options for resolving an IPNS path
@@ -72,3 +81,43 @@ func ProcessOpts(opts []ResolveOpt) ResolveOpts {
72
81
}
73
82
return rsopts
74
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
+ }
0 commit comments