mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
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@468dea4bb4 This commit was moved from ipfs/boxo@bcb9190c2b
This commit is contained in:
parent
587075204d
commit
b3cc938630
@ -13,6 +13,15 @@ const (
|
||||
// trust resolution to eventually complete and can't put an upper
|
||||
// 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.
|
||||
DefaultIPNSRecordEOL = 48 * time.Hour
|
||||
)
|
||||
|
||||
// ResolveOpts specifies options for resolving an IPNS path
|
||||
@ -72,3 +81,43 @@ func ProcessOpts(opts []ResolveOpt) ResolveOpts {
|
||||
}
|
||||
return rsopts
|
||||
}
|
||||
|
||||
// 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(DefaultIPNSRecordEOL),
|
||||
TTL: DefaultIPNSRecordTTL,
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user