Unverified 提交 b8ec598d 作者: Steven Allen 提交者: GitHub

Merge pull request #6750 from ipfs/fix/6749

improve documentation and fix dht put bug
......@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"time"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
......@@ -515,8 +516,8 @@ var putValueDhtCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Write a key/value pair to the routing system.",
ShortDescription: `
Given a key of the form /foo/bar and a value of any form, this will write that
value to the routing system with that key.
Given a key of the form /foo/bar and a valid value for that key, this will write
that value to the routing system with that key.
Keys have two parts: a keytype (foo) and the key name (bar). IPNS uses the
/ipns keytype, and expects the key name to be a Peer ID. IPNS entries are
......@@ -527,15 +528,15 @@ this is only /ipns. Unless you have a relatively deep understanding of the
go-ipfs routing internals, you likely want to be using 'ipfs name publish' instead
of this.
Value is arbitrary text. Standard input can be used to provide value.
NOTE: A value may not exceed 2048 bytes.
The value must be a valid value for the given key type. For example, if the key
is /ipns/QmFoo, the value must be IPNS record (protobuf) signed with the key
identified by QmFoo.
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("key", true, false, "The key to store the value at."),
cmds.StringArg("value", true, false, "The value to store.").EnableStdin(),
cmds.FileArg("value", true, false, "The value to store.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption(dhtVerboseOptionName, "v", "Print extra information."),
......@@ -546,12 +547,6 @@ NOTE: A value may not exceed 2048 bytes.
return err
}
// Needed to parse stdin args.
err = req.ParseBodyArgs()
if err != nil {
return err
}
if !nd.IsOnline {
return ErrNotOnline
}
......@@ -561,7 +556,16 @@ NOTE: A value may not exceed 2048 bytes.
return err
}
data := req.Arguments[1]
file, err := cmdenv.GetFileArg(req.Files.Entries())
if err != nil {
return err
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
return err
}
ctx, cancel := context.WithCancel(req.Context)
ctx, events := routing.RegisterForQueryEvents(ctx)
......
......@@ -4,9 +4,6 @@ test_description="Test dht command"
. lib/test-lib.sh
TEST_DHT_VALUE="foobar"
TEST_DHT_PATH="/pk/QmbWTwYGcmdyK9CYfNBcfs9nhZs17a6FQ4Y8oea278xx41"
test_dht() {
NUM_NODES=5
......@@ -29,38 +26,35 @@ test_dht() {
test_cmp actual expected
'
# ipfs dht put <key> <value>
test_expect_failure 'put with good keys (#3124)' '
ipfsi 0 dht put "$TEST_DHT_PATH" "$TEST_DHT_VALUE" | sort >putted &&
[ -s putted ] ||
test_fsh cat putted
'
test_expect_failure 'put round trips (#3124)' '
echo -n "$TEST_DHT_VALUE" >expected &&
ipfsi 0 dht get "$TEST_DHT_PATH" >actual &&
test_cmp actual expected
'
# ipfs dht get <key>
test_expect_success 'get with good keys' '
test_expect_success 'get with good keys works' '
HASH="$(echo "hello world" | ipfsi 2 add -q)" &&
ipfsi 2 name publish "/ipfs/$HASH" &&
ipfsi 1 dht get "/ipns/$PEERID_2" | grep -aq "/ipfs/$HASH"
ipfsi 1 dht get "/ipns/$PEERID_2" >get_result
'
test_expect_success 'get with good keys contains the right value' '
cat get_result | grep -aq "/ipfs/$HASH"
'
test_expect_success 'put round trips (#3124)' '
ipfsi 0 dht put "/ipns/$PEERID_2" get_result | sort >putted &&
[ -s putted ] ||
test_fsh cat putted
'
test_expect_success 'put with bad keys fails (issue #5113)' '
ipfsi 0 dht put "foo" "bar" >putted
ipfsi 0 dht put "/pk/foo" "bar" >>putted
ipfsi 0 dht put "/ipns/foo" "bar" >>putted
ipfsi 0 dht put "foo" <<<bar >putted
ipfsi 0 dht put "/pk/foo" <<<bar >>putted
ipfsi 0 dht put "/ipns/foo" <<<bar >>putted
[ ! -s putted ] ||
test_fsh cat putted
'
test_expect_success 'put with bad keys returns error (issue #4611)' '
test_must_fail ipfsi 0 dht put "foo" "bar" &&
test_must_fail ipfsi 0 dht put "/pk/foo" "bar" &&
test_must_fail ipfsi 0 dht put "/ipns/foo" "bar"
test_must_fail ipfsi 0 dht put "foo" <<<bar &&
test_must_fail ipfsi 0 dht put "/pk/foo" <<<bar &&
test_must_fail ipfsi 0 dht put "/ipns/foo" <<<bar
'
test_expect_success 'get with bad keys (issue #4611)' '
......@@ -101,7 +95,7 @@ test_dht() {
test_expect_success "dht commands fail when offline" '
test_must_fail ipfsi 0 dht findprovs "$HASH" 2>err_findprovs &&
test_must_fail ipfsi 0 dht findpeer "$HASH" 2>err_findpeer &&
test_must_fail ipfsi 0 dht put "$TEST_DHT_PATH" "$TEST_DHT_VALUE" 2>err_put &&
test_must_fail ipfsi 0 dht put "/ipns/$PEERID_2" "get_result" 2>err_put &&
test_should_contain "this command must be run in online mode" err_findprovs &&
test_should_contain "this command must be run in online mode" err_findpeer &&
test_should_contain "this command must be run in online mode" err_put
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论