@cryptotaxi247 / kubo / commits / faac7c183

feat!: namesys refactor, ipns TTL bubbled up to gateway (#459)

This commit was moved from ipfs/boxo@a50f784985ddfc25ec8d25aced2ca058469a3390

Henrique Dias committed Oct 18, 2023 at 10:12 UTC faac7c183588115aa2acc3c1ab5df408d2477845
2 files changed +3 -134
core/coreiface/options/name.go
+3 -3
@@ -3,7 +3,7 @@ package options
3 import (
4 "time"
5
6 - ropts "github.com/ipfs/boxo/coreiface/options/namesys"
6 + "github.com/ipfs/boxo/namesys"
7 )
8
9 const (
@@ -21,7 +21,7 @@ type NamePublishSettings struct {
21 type NameResolveSettings struct {
22 Cache bool
23
24 - ResolveOpts []ropts.ResolveOpt
24 + ResolveOpts []namesys.ResolveOption
25 }
26
27 type (
@@ -123,7 +123,7 @@ func (nameOpts) Cache(cache bool) NameResolveOption {
123 }
124 }
125
126 -func (nameOpts) ResolveOption(opt ropts.ResolveOpt) NameResolveOption {
126 +func (nameOpts) ResolveOption(opt namesys.ResolveOption) NameResolveOption {
127 return func(settings *NameResolveSettings) error {
128 settings.ResolveOpts = append(settings.ResolveOpts, opt)
129 return nil
core/coreiface/options/namesys/opts.go deleted
-131
@@ -1,131 +0,0 @@
1 -package nsopts
2 -
3 -import (
4 - "time"
5 -)
6 -
7 -const (
8 - // DefaultDepthLimit is the default depth limit used by Resolve.
9 - DefaultDepthLimit = 32
10 -
11 - // UnlimitedDepth allows infinite recursion in Resolve. You
12 - // probably don't want to use this, but it's here if you absolutely
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
28 -type ResolveOpts struct {
29 - // Recursion depth limit
30 - Depth uint
31 - // The number of IPNS records to retrieve from the DHT
32 - // (the best record is selected from this set)
33 - DhtRecordCount uint
34 - // The amount of time to wait for DHT records to be fetched
35 - // and verified. A zero value indicates that there is no explicit
36 - // timeout (although there is an implicit timeout due to dial
37 - // timeouts within the DHT)
38 - DhtTimeout time.Duration
39 -}
40 -
41 -// DefaultResolveOpts returns the default options for resolving
42 -// an IPNS path
43 -func DefaultResolveOpts() ResolveOpts {
44 - return ResolveOpts{
45 - Depth: DefaultDepthLimit,
46 - DhtRecordCount: 16,
47 - DhtTimeout: time.Minute,
48 - }
49 -}
50 -
51 -// ResolveOpt is used to set an option
52 -type ResolveOpt func(*ResolveOpts)
53 -
54 -// Depth is the recursion depth limit
55 -func Depth(depth uint) ResolveOpt {
56 - return func(o *ResolveOpts) {
57 - o.Depth = depth
58 - }
59 -}
60 -
61 -// DhtRecordCount is the number of IPNS records to retrieve from the DHT
62 -func DhtRecordCount(count uint) ResolveOpt {
63 - return func(o *ResolveOpts) {
64 - o.DhtRecordCount = count
65 - }
66 -}
67 -
68 -// DhtTimeout is the amount of time to wait for DHT records to be fetched
69 -// and verified. A zero value indicates that there is no explicit timeout
70 -func DhtTimeout(timeout time.Duration) ResolveOpt {
71 - return func(o *ResolveOpts) {
72 - o.DhtTimeout = timeout
73 - }
74 -}
75 -
76 -// ProcessOpts converts an array of ResolveOpt into a ResolveOpts object
77 -func ProcessOpts(opts []ResolveOpt) ResolveOpts {
78 - rsopts := DefaultResolveOpts()
79 - for _, option := range opts {
80 - option(&rsopts)
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 - CompatibleWithV1 bool
90 -}
91 -
92 -// DefaultPublishOptions returns the default options for publishing an IPNS record.
93 -func DefaultPublishOptions() PublishOptions {
94 - return PublishOptions{
95 - EOL: time.Now().Add(DefaultIPNSRecordEOL),
96 - TTL: DefaultIPNSRecordTTL,
97 - }
98 -}
99 -
100 -// PublishOption is used to set an option for PublishOpts.
101 -type PublishOption func(*PublishOptions)
102 -
103 -// PublishWithEOL sets an EOL.
104 -func PublishWithEOL(eol time.Time) PublishOption {
105 - return func(o *PublishOptions) {
106 - o.EOL = eol
107 - }
108 -}
109 -
110 -// PublishWithEOL sets a TTL.
111 -func PublishWithTTL(ttl time.Duration) PublishOption {
112 - return func(o *PublishOptions) {
113 - o.TTL = ttl
114 - }
115 -}
116 -
117 -// PublishCompatibleWithV1 sets compatibility with IPNS Records V1.
118 -func PublishCompatibleWithV1(compatible bool) PublishOption {
119 - return func(o *PublishOptions) {
120 - o.CompatibleWithV1 = compatible
121 - }
122 -}
123 -
124 -// ProcessPublishOptions converts an array of PublishOpt into a PublishOpts object.
125 -func ProcessPublishOptions(opts []PublishOption) PublishOptions {
126 - rsopts := DefaultPublishOptions()
127 - for _, option := range opts {
128 - option(&rsopts)
129 - }
130 - return rsopts
131 -}