Commit c3053e81 authored by Łukasz Magiera's avatar Łukasz Magiera

resolve cmd: use coreapi

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent dec563d9
...@@ -14,9 +14,12 @@ type NamePublishSettings struct { ...@@ -14,9 +14,12 @@ type NamePublishSettings struct {
} }
type NameResolveSettings struct { type NameResolveSettings struct {
Recursive bool Depth int
Local bool Local bool
Cache bool Cache bool
DhtRecordCount int
DhtTimeout time.Duration
} }
type NamePublishOption func(*NamePublishSettings) error type NamePublishOption func(*NamePublishSettings) error
...@@ -40,9 +43,12 @@ func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error) ...@@ -40,9 +43,12 @@ func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error)
func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error) { func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error) {
options := &NameResolveSettings{ options := &NameResolveSettings{
Recursive: false, Depth: 1,
Local: false, Local: false,
Cache: true, Cache: true,
DhtRecordCount: 16,
DhtTimeout: time.Minute,
} }
for _, opt := range opts { for _, opt := range opts {
...@@ -80,11 +86,11 @@ func (nameOpts) Key(key string) NamePublishOption { ...@@ -80,11 +86,11 @@ func (nameOpts) Key(key string) NamePublishOption {
} }
} }
// Recursive is an option for Name.Resolve which specifies whether to perform a // Depth is an option for Name.Resolve which specifies the maximum depth of a
// recursive lookup. Default value is false // recursive lookup. Default value is false
func (nameOpts) Recursive(recursive bool) NameResolveOption { func (nameOpts) Depth(depth int) NameResolveOption {
return func(settings *NameResolveSettings) error { return func(settings *NameResolveSettings) error {
settings.Recursive = recursive settings.Depth = depth
return nil return nil
} }
} }
...@@ -106,3 +112,22 @@ func (nameOpts) Cache(cache bool) NameResolveOption { ...@@ -106,3 +112,22 @@ func (nameOpts) Cache(cache bool) NameResolveOption {
return nil return nil
} }
} }
// DhtRecordCount is an option for Name.Resolve which specifies how many records
// we want to validate before selecting the best one (newest). Note that setting
// this value too low will have security implications
func (nameOpts) DhtRecordCount(rc int) NameResolveOption {
return func(settings *NameResolveSettings) error {
settings.DhtRecordCount = rc
return nil
}
}
// DhtTimeout is an option for Name.Resolve which specifies timeout for
// DHT lookup
func (nameOpts) DhtTimeout(timeout time.Duration) NameResolveOption {
return func(settings *NameResolveSettings) error {
settings.DhtTimeout = timeout
return nil
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment