coreapi: move namesys options to coreapi
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@263199d56ec6e7f2dab7c8619b75e2a6fbcf5f15 This commit was moved from ipfs/boxo@a2f6e434b94663fc953c37e74156ee27b8ab73fe
Łukasz Magiera committed
Feb 8, 2019 at 19:23 UTC
97c433323baad09ba2dbcea901cd3acc5bbdc9d8
2 files changed
+75
-1
core/coreiface/options/name.go
+1
-1
@@ -3,7 +3,7 @@ package options
3
import (
4
"time"
5
6
- ropts "github.com/ipfs/go-ipfs/namesys/opts"
6
+ ropts "github.com/ipfs/go-ipfs/core/coreapi/interface/options/namesys"
7
)
8
9
const (
core/coreiface/options/namesys/opts.go
new
+74
@@ -0,0 +1,74 @@
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
+
18
+// ResolveOpts specifies options for resolving an IPNS path
19
+type ResolveOpts struct {
20
+ // Recursion depth limit
21
+ Depth uint
22
+ // The number of IPNS records to retrieve from the DHT
23
+ // (the best record is selected from this set)
24
+ DhtRecordCount uint
25
+ // The amount of time to wait for DHT records to be fetched
26
+ // and verified. A zero value indicates that there is no explicit
27
+ // timeout (although there is an implicit timeout due to dial
28
+ // timeouts within the DHT)
29
+ DhtTimeout time.Duration
30
+}
31
+
32
+// DefaultResolveOpts returns the default options for resolving
33
+// an IPNS path
34
+func DefaultResolveOpts() ResolveOpts {
35
+ return ResolveOpts{
36
+ Depth: DefaultDepthLimit,
37
+ DhtRecordCount: 16,
38
+ DhtTimeout: time.Minute,
39
+ }
40
+}
41
+
42
+// ResolveOpt is used to set an option
43
+type ResolveOpt func(*ResolveOpts)
44
+
45
+// Depth is the recursion depth limit
46
+func Depth(depth uint) ResolveOpt {
47
+ return func(o *ResolveOpts) {
48
+ o.Depth = depth
49
+ }
50
+}
51
+
52
+// DhtRecordCount is the number of IPNS records to retrieve from the DHT
53
+func DhtRecordCount(count uint) ResolveOpt {
54
+ return func(o *ResolveOpts) {
55
+ o.DhtRecordCount = count
56
+ }
57
+}
58
+
59
+// DhtTimeout is the amount of time to wait for DHT records to be fetched
60
+// and verified. A zero value indicates that there is no explicit timeout
61
+func DhtTimeout(timeout time.Duration) ResolveOpt {
62
+ return func(o *ResolveOpts) {
63
+ o.DhtTimeout = timeout
64
+ }
65
+}
66
+
67
+// ProcessOpts converts an array of ResolveOpt into a ResolveOpts object
68
+func ProcessOpts(opts []ResolveOpt) ResolveOpts {
69
+ rsopts := DefaultResolveOpts()
70
+ for _, option := range opts {
71
+ option(&rsopts)
72
+ }
73
+ return rsopts
74
+}