Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
b8ec598d
Unverified
提交
b8ec598d
authored
11月 19, 2019
作者:
Steven Allen
提交者:
GitHub
11月 19, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6750 from ipfs/fix/6749
improve documentation and fix dht put bug
上级
7c01c2cf
5fbf0d35
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
36 行增加
和
38 行删除
+36
-38
dht.go
core/commands/dht.go
+17
-13
t0170-dht.sh
test/sharness/t0170-dht.sh
+19
-25
没有找到文件。
core/commands/dht.go
浏览文件 @
b8ec598d
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"time"
"time"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
...
@@ -515,8 +516,8 @@ var putValueDhtCmd = &cmds.Command{
...
@@ -515,8 +516,8 @@ var putValueDhtCmd = &cmds.Command{
Helptext
:
cmds
.
HelpText
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Write a key/value pair to the routing system."
,
Tagline
:
"Write a key/value pair to the routing system."
,
ShortDescription
:
`
ShortDescription
:
`
Given a key of the form /foo/bar and a val
ue of any form, this will write that
Given a key of the form /foo/bar and a val
id value for that key, this will write
value to the routing system with that key.
that
value to the routing system with that key.
Keys have two parts: a keytype (foo) and the key name (bar). IPNS uses the
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
/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
...
@@ -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
go-ipfs routing internals, you likely want to be using 'ipfs name publish' instead
of this.
of this.
Value is arbitrary text. Standard input can be used to provide value.
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
NOTE: A value may not exceed 2048 bytes
.
identified by QmFoo
.
`
,
`
,
},
},
Arguments
:
[]
cmds
.
Argument
{
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"key"
,
true
,
false
,
"The key to store the value at."
),
cmds
.
StringArg
(
"key"
,
true
,
false
,
"The key to store the value at."
),
cmds
.
String
Arg
(
"value"
,
true
,
false
,
"The value to store."
)
.
EnableStdin
(),
cmds
.
File
Arg
(
"value"
,
true
,
false
,
"The value to store."
)
.
EnableStdin
(),
},
},
Options
:
[]
cmds
.
Option
{
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
dhtVerboseOptionName
,
"v"
,
"Print extra information."
),
cmds
.
BoolOption
(
dhtVerboseOptionName
,
"v"
,
"Print extra information."
),
...
@@ -546,12 +547,6 @@ NOTE: A value may not exceed 2048 bytes.
...
@@ -546,12 +547,6 @@ NOTE: A value may not exceed 2048 bytes.
return
err
return
err
}
}
// Needed to parse stdin args.
err
=
req
.
ParseBodyArgs
()
if
err
!=
nil
{
return
err
}
if
!
nd
.
IsOnline
{
if
!
nd
.
IsOnline
{
return
ErrNotOnline
return
ErrNotOnline
}
}
...
@@ -561,7 +556,16 @@ NOTE: A value may not exceed 2048 bytes.
...
@@ -561,7 +556,16 @@ NOTE: A value may not exceed 2048 bytes.
return
err
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
,
cancel
:=
context
.
WithCancel
(
req
.
Context
)
ctx
,
events
:=
routing
.
RegisterForQueryEvents
(
ctx
)
ctx
,
events
:=
routing
.
RegisterForQueryEvents
(
ctx
)
...
...
test/sharness/t0170-dht.sh
浏览文件 @
b8ec598d
...
@@ -4,9 +4,6 @@ test_description="Test dht command"
...
@@ -4,9 +4,6 @@ test_description="Test dht command"
.
lib/test-lib.sh
.
lib/test-lib.sh
TEST_DHT_VALUE
=
"foobar"
TEST_DHT_PATH
=
"/pk/QmbWTwYGcmdyK9CYfNBcfs9nhZs17a6FQ4Y8oea278xx41"
test_dht
()
{
test_dht
()
{
NUM_NODES
=
5
NUM_NODES
=
5
...
@@ -29,38 +26,35 @@ test_dht() {
...
@@ -29,38 +26,35 @@ test_dht() {
test_cmp actual expected
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>
# 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)" &&
HASH="$(echo "hello world" | ipfsi 2 add -q)" &&
ipfsi 2 name publish "/ipfs/$HASH" &&
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)'
'
test_expect_success
'put with bad keys fails (issue #5113)'
'
ipfsi 0 dht put "foo"
"bar"
>putted
ipfsi 0 dht put "foo"
<<<bar
>putted
ipfsi 0 dht put "/pk/foo"
"bar"
>>putted
ipfsi 0 dht put "/pk/foo"
<<<bar
>>putted
ipfsi 0 dht put "/ipns/foo"
"bar"
>>putted
ipfsi 0 dht put "/ipns/foo"
<<<bar
>>putted
[ ! -s putted ] ||
[ ! -s putted ] ||
test_fsh cat putted
test_fsh cat putted
'
'
test_expect_success
'put with bad keys returns error (issue #4611)'
'
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 "foo"
<<<bar
&&
test_must_fail ipfsi 0 dht put "/pk/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 "/ipns/foo"
<<<bar
'
'
test_expect_success
'get with bad keys (issue #4611)'
'
test_expect_success
'get with bad keys (issue #4611)'
'
...
@@ -101,7 +95,7 @@ test_dht() {
...
@@ -101,7 +95,7 @@ test_dht() {
test_expect_success
"dht commands fail when offline"
'
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 findprovs "$HASH" 2>err_findprovs &&
test_must_fail ipfsi 0 dht findpeer "$HASH" 2>err_findpeer &&
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_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_findpeer &&
test_should_contain "this command must be run in online mode" err_put
test_should_contain "this command must be run in online mode" err_put
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论