resolve cmd: use coreapi
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@c3053e816481188f8b20f1d56c3cfa648d4f39c8 This commit was moved from ipfs/boxo@28fe139695b6494eb257aca0d7e21741497a640a
Łukasz Magiera committed
Sep 18, 2018 at 04:30 UTC
7455bd65c0698e9a7975fd9fb072de6beb126e89
1 file changed
+34
-9
core/coreiface/options/name.go
+34
-9
@@ -14,9 +14,12 @@ type NamePublishSettings struct {
14
}
15
16
type NameResolveSettings struct {
17
- Recursive bool
18
- Local bool
19
- Cache bool
17
+ Depth int
18
+ Local bool
19
+ Cache bool
20
+
21
+ DhtRecordCount int
22
+ DhtTimeout time.Duration
23
}
24
25
type NamePublishOption func(*NamePublishSettings) error
@@ -40,9 +43,12 @@ func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error)
43
44
func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error) {
45
options := &NameResolveSettings{
43
- Recursive: false,
44
- Local: false,
45
- Cache: true,
46
+ Depth: 1,
47
+ Local: false,
48
+ Cache: true,
49
+
50
+ DhtRecordCount: 16,
51
+ DhtTimeout: time.Minute,
52
}
53
54
for _, opt := range opts {
@@ -80,11 +86,11 @@ func (nameOpts) Key(key string) NamePublishOption {
86
}
87
}
88
83
-// Recursive is an option for Name.Resolve which specifies whether to perform a
89
+// Depth is an option for Name.Resolve which specifies the maximum depth of a
90
// recursive lookup. Default value is false
85
-func (nameOpts) Recursive(recursive bool) NameResolveOption {
91
+func (nameOpts) Depth(depth int) NameResolveOption {
92
return func(settings *NameResolveSettings) error {
87
- settings.Recursive = recursive
93
+ settings.Depth = depth
94
return nil
95
}
96
}
@@ -106,3 +112,22 @@ func (nameOpts) Cache(cache bool) NameResolveOption {
112
return nil
113
}
114
}
115
+
116
+// DhtRecordCount is an option for Name.Resolve which specifies how many records
117
+// we want to validate before selecting the best one (newest). Note that setting
118
+// this value too low will have security implications
119
+func (nameOpts) DhtRecordCount(rc int) NameResolveOption {
120
+ return func(settings *NameResolveSettings) error {
121
+ settings.DhtRecordCount = rc
122
+ return nil
123
+ }
124
+}
125
+
126
+// DhtTimeout is an option for Name.Resolve which specifies timeout for
127
+// DHT lookup
128
+func (nameOpts) DhtTimeout(timeout time.Duration) NameResolveOption {
129
+ return func(settings *NameResolveSettings) error {
130
+ settings.DhtTimeout = timeout
131
+ return nil
132
+ }
133
+}