-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
resolve: use unixfs ResolveOnce #5484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,12 @@ type NamePublishSettings struct { | |
| } | ||
|
|
||
| type NameResolveSettings struct { | ||
| Recursive bool | ||
| Local bool | ||
| Cache bool | ||
| Depth int | ||
| Local bool | ||
| Cache bool | ||
|
|
||
| DhtRecordCount int | ||
| DhtTimeout time.Duration | ||
| } | ||
|
|
||
| type NamePublishOption func(*NamePublishSettings) error | ||
|
|
@@ -40,9 +43,12 @@ func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error) | |
|
|
||
| func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error) { | ||
| options := &NameResolveSettings{ | ||
| Recursive: false, | ||
| Local: false, | ||
| Cache: true, | ||
| Depth: 1, | ||
| Local: false, | ||
| Cache: true, | ||
|
|
||
| DhtRecordCount: 16, | ||
| DhtTimeout: time.Minute, | ||
| } | ||
|
|
||
| for _, opt := range opts { | ||
|
|
@@ -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 | ||
| func (nameOpts) Recursive(recursive bool) NameResolveOption { | ||
| func (nameOpts) Depth(depth int) NameResolveOption { | ||
| return func(settings *NameResolveSettings) error { | ||
| settings.Recursive = recursive | ||
| settings.Depth = depth | ||
| return nil | ||
| } | ||
| } | ||
|
|
@@ -106,3 +112,22 @@ func (nameOpts) Cache(cache bool) NameResolveOption { | |
| 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 | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should hard-code this. Can we use the value from the DHT (unless we go with the "resolve options" solution in which case this point is moot).