-
-
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 2 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,6 +4,7 @@ import ( | |
"errors" | ||
"io" | ||
"strings" | ||
"time" | ||
|
||
cmds "github.com/ipfs/go-ipfs/commands" | ||
e "github.com/ipfs/go-ipfs/core/commands/e" | ||
|
@@ -57,9 +58,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 +109,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() | ||
opts := namesys.DefaultResolveOpts() | ||
if !recursive { | ||
opts.Depth = 1 | ||
} | ||
if rcok { | ||
opts.DhtRecordCount = uint(rc) | ||
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. Can get rid of this cast once ipfs/go-ipfs-cmdkit#14 is approved |
||
} | ||
if dhttok { | ||
opts.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, opts) | ||
if err != nil { | ||
res.SetError(err, cmdkit.ErrNormal) | ||
return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,7 @@ func TestResolverValidation(t *testing.T) { | |
} | ||
|
||
// Resolve entry | ||
resp, err := resolver.resolveOnce(ctx, id.Pretty()) | ||
resp, err := resolver.resolveOnce(ctx, id.Pretty(), DefaultResolveOpts()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -136,9 +136,9 @@ func TestResolverValidation(t *testing.T) { | |
} | ||
|
||
// Record should fail validation because entry is expired | ||
_, err = resolver.resolveOnce(ctx, id.Pretty()) | ||
if err != ErrExpiredRecord { | ||
t.Fatal("ValidateIpnsRecord should have returned ErrExpiredRecord") | ||
_, err = resolver.resolveOnce(ctx, id.Pretty(), DefaultResolveOpts()) | ||
if err == nil { | ||
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. Why arent we checking for a specific error anymore? 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. The 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 looked into whether I can check for 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. Alright, that seems fine. Thanks for the response! |
||
t.Fatal("ValidateIpnsRecord should have returned error") | ||
} | ||
|
||
// Create IPNS record path with a different private key | ||
|
@@ -158,8 +158,8 @@ func TestResolverValidation(t *testing.T) { | |
|
||
// Record should fail validation because public key defined by | ||
// ipns path doesn't match record signature | ||
_, err = resolver.resolveOnce(ctx, id2.Pretty()) | ||
if err != ErrSignature { | ||
_, err = resolver.resolveOnce(ctx, id2.Pretty(), DefaultResolveOpts()) | ||
if err == nil { | ||
t.Fatal("ValidateIpnsRecord should have failed signature verification") | ||
} | ||
|
||
|
@@ -176,7 +176,7 @@ func TestResolverValidation(t *testing.T) { | |
|
||
// Record should fail validation because public key is not available | ||
// in peer store or on network | ||
_, err = resolver.resolveOnce(ctx, id3.Pretty()) | ||
_, err = resolver.resolveOnce(ctx, id3.Pretty(), DefaultResolveOpts()) | ||
if err == nil { | ||
t.Fatal("ValidateIpnsRecord should have failed because public key was not found") | ||
} | ||
|
@@ -191,7 +191,7 @@ func TestResolverValidation(t *testing.T) { | |
// public key is available in the peer store by looking it up in | ||
// the DHT, which causes the DHT to fetch it and cache it in the | ||
// peer store | ||
_, err = resolver.resolveOnce(ctx, id3.Pretty()) | ||
_, err = resolver.resolveOnce(ctx, id3.Pretty(), DefaultResolveOpts()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -263,7 +263,20 @@ func (m *mockValueStore) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey | |
} | ||
|
||
func (m *mockValueStore) GetValues(ctx context.Context, k string, count int) ([]routing.RecvdVal, error) { | ||
return m.r.GetValues(ctx, k, count) | ||
vals, err := m.r.GetValues(ctx, k, count) | ||
if err != nil { | ||
return nil, err | ||
} | ||
valid := make([]routing.RecvdVal, 0, len(vals)) | ||
for _, v := range vals { | ||
rec := new(recordpb.Record) | ||
rec.Key = proto.String(k) | ||
rec.Value = v.Val | ||
if err = m.Validator.VerifyRecord(rec); err == nil { | ||
valid = append(valid, v) | ||
} | ||
} | ||
return valid, nil | ||
} | ||
|
||
func (m *mockValueStore) PutValue(ctx context.Context, k string, d []byte) error { | ||
|
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