coreapi name: accept namesys options
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@ca81d824222df0ed2c1ede6a3e166f7aa420b4f7 This commit was moved from ipfs/boxo@cd88b19ccb6d4ff617ea5e4c329c284315fc8707
Łukasz Magiera committed
Sep 19, 2018 at 11:51 UTC
5411cc043c1656f4d4def511bea861932393b7c8
1 file changed
+6
-30
core/coreiface/options/name.go
+6
-30
@@ -2,6 +2,8 @@ package options
2
3
import (
4
"time"
5
+
6
+ ropts "github.com/ipfs/go-ipfs/namesys/opts"
7
)
8
9
const (
@@ -14,12 +16,10 @@ type NamePublishSettings struct {
16
}
17
18
type NameResolveSettings struct {
17
- Depth int
19
Local bool
20
Cache bool
21
21
- DhtRecordCount int
22
- DhtTimeout time.Duration
22
+ ResolveOpts []ropts.ResolveOpt
23
}
24
25
type NamePublishOption func(*NamePublishSettings) error
@@ -43,12 +43,8 @@ func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error)
43
44
func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error) {
45
options := &NameResolveSettings{
46
- Depth: 1,
46
Local: false,
47
Cache: true,
49
-
50
- DhtRecordCount: 16,
51
- DhtTimeout: time.Minute,
48
}
49
50
for _, opt := range opts {
@@ -86,15 +82,6 @@ func (nameOpts) Key(key string) NamePublishOption {
82
}
83
}
84
89
-// Depth is an option for Name.Resolve which specifies the maximum depth of a
90
-// recursive lookup. Default value is false
91
-func (nameOpts) Depth(depth int) NameResolveOption {
92
- return func(settings *NameResolveSettings) error {
93
- settings.Depth = depth
94
- return nil
95
- }
96
-}
97
-
85
// Local is an option for Name.Resolve which specifies if the lookup should be
86
// offline. Default value is false
87
func (nameOpts) Local(local bool) NameResolveOption {
@@ -113,21 +100,10 @@ func (nameOpts) Cache(cache bool) NameResolveOption {
100
}
101
}
102
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 {
103
+//
104
+func (nameOpts) ResolveOption(opt ropts.ResolveOpt) NameResolveOption {
105
return func(settings *NameResolveSettings) error {
130
- settings.DhtTimeout = timeout
106
+ settings.ResolveOpts = append(settings.ResolveOpts, opt)
107
return nil
108
}
109
}