-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add options for record count and timeout for resolving DHT paths #4733
Changes from 5 commits
1abf836
5096025
e8f79c8
d47ff79
350362c
5202f76
32ef57c
494f242
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 |
---|---|---|
|
@@ -4,10 +4,12 @@ import ( | |
"errors" | ||
"io" | ||
"strings" | ||
"time" | ||
|
||
cmds "github.com/ipfs/go-ipfs/commands" | ||
e "github.com/ipfs/go-ipfs/core/commands/e" | ||
namesys "github.com/ipfs/go-ipfs/namesys" | ||
nsopts "github.com/ipfs/go-ipfs/namesys/opts" | ||
|
||
offline "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/offline" | ||
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit" | ||
|
@@ -57,9 +59,10 @@ Resolve the value of a dnslink: | |
Options: []cmdkit.Option{ | ||
cmdkit.BoolOption("recursive", "r", "Resolve until the result is not an IPNS name."), | ||
cmdkit.BoolOption("nocache", "n", "Do not use cached entries."), | ||
cmdkit.UintOption("dht-record-count", "dhtrc", "Number of records to request for DHT resolution."), | ||
cmdkit.UintOption("dht-timeout", "dhtt", "Timeout in seconds for DHT resolution. Pass 0 for no timeout."), | ||
}, | ||
Run: func(req cmds.Request, res cmds.Response) { | ||
|
||
n, err := req.InvocContext().GetNode() | ||
if err != nil { | ||
res.SetError(err, cmdkit.ErrNormal) | ||
|
@@ -107,16 +110,24 @@ Resolve the value of a dnslink: | |
} | ||
|
||
recursive, _, _ := req.Option("recursive").Bool() | ||
depth := 1 | ||
if recursive { | ||
depth = namesys.DefaultDepthLimit | ||
rc, rcok, _ := req.Option("dht-record-count").Int() | ||
dhtt, dhttok, _ := req.Option("dht-timeout").Int() | ||
ropts := []nsopts.ResolveOpt{} | ||
if !recursive { | ||
ropts = append(ropts, nsopts.Depth(1)) | ||
} | ||
if rcok { | ||
ropts = append(ropts, nsopts.DhtRecordCount(uint(rc))) | ||
} | ||
if dhttok { | ||
ropts = append(ropts, nsopts.DhtTimeout(time.Duration(dhtt)*time.Second)) | ||
} | ||
|
||
if !strings.HasPrefix(name, "/ipns/") { | ||
name = "/ipns/" + name | ||
} | ||
|
||
output, err := resolver.ResolveN(req.Context(), name, depth) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where did the depth arg go? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh nvm, i found it |
||
output, err := resolver.Resolve(req.Context(), name, ropts...) | ||
if err != nil { | ||
res.SetError(err, cmdkit.ErrNormal) | ||
return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options" | ||
keystore "github.com/ipfs/go-ipfs/keystore" | ||
namesys "github.com/ipfs/go-ipfs/namesys" | ||
nsopts "github.com/ipfs/go-ipfs/namesys/opts" | ||
ipath "github.com/ipfs/go-ipfs/path" | ||
|
||
offline "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/offline" | ||
|
@@ -117,16 +118,16 @@ func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.Nam | |
resolver = namesys.NewNameSystem(n.Routing, n.Repo.Datastore(), 0) | ||
} | ||
|
||
depth := 1 | ||
if options.Recursive { | ||
depth = namesys.DefaultDepthLimit | ||
} | ||
|
||
if !strings.HasPrefix(name, "/ipns/") { | ||
name = "/ipns/" + name | ||
} | ||
|
||
output, err := resolver.ResolveN(ctx, name, depth) | ||
ropts := []nsopts.ResolveOpt{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i prefer writing this as: |
||
if !options.Recursive { | ||
ropts = append(ropts, nsopts.Depth(1)) | ||
} | ||
|
||
output, err := resolver.Resolve(ctx, name, ropts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
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.
So, I might be missing something but IPFS commands have a timeout flag (e.g.,
ipfs --timeout=30s
). And we can always set a DHT resolution timeout by setting a timeout on the context. What's the usecase for the additional timeout?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.
The use case is that with --dht-timeout the DHT collects as many values as it can within the timeout, and then returns the best value it has found. The global IPFS command --timeout will simply kill the command:
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.
Maybe it would be better for the
--dht-timeout
parameter to take a string though, eg--dht-timeout=5s
instead of assuming seconds eg--dht-timeout=5
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.
I see. It would be nice to explain that in the help but I can't think of a succinct way of putting it...
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.
@dirkmc it will be better for it to parse the time.
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.
I added a commit to parse the time, and changed the parameter description to
Max time to collect values during DHT resolution eg \"30s\". Pass 0 for no timeout
That's the most succinct way I can think of to say it