Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
307d06b4
Unverified
提交
307d06b4
authored
5月 14, 2019
作者:
Steven Allen
提交者:
GitHub
5月 14, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6277 from ipfs/fix/3124
work towards fixing dht commands
上级
96e6dd29
a8fa9dd0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
52 行增加
和
30 行删除
+52
-30
dht.go
core/commands/dht.go
+46
-30
t0170-dht.sh
test/sharness/t0170-dht.sh
+6
-0
没有找到文件。
core/commands/dht.go
浏览文件 @
307d06b4
...
...
@@ -2,6 +2,7 @@ package commands
import
(
"context"
"encoding/base64"
"errors"
"fmt"
"io"
...
...
@@ -103,15 +104,15 @@ var queryDhtCmd = &cmds.Command{
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
notif
.
QueryEvent
)
error
{
pfm
:=
pfuncMap
{
notif
.
PeerResponse
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
{
notif
.
PeerResponse
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
{
for
_
,
p
:=
range
obj
.
Responses
{
fmt
.
Fprintf
(
out
,
"%s
\n
"
,
p
.
ID
.
Pretty
())
}
return
nil
},
}
verbose
,
_
:=
req
.
Options
[
dhtVerboseOptionName
]
.
(
bool
)
printEvent
(
out
,
w
,
verbose
,
pfm
)
return
nil
return
printEvent
(
out
,
w
,
verbose
,
pfm
)
}),
},
Type
:
notif
.
QueryEvent
{},
...
...
@@ -181,12 +182,13 @@ var findProvidersDhtCmd = &cmds.Command{
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
notif
.
QueryEvent
)
error
{
pfm
:=
pfuncMap
{
notif
.
FinalPeer
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
{
notif
.
FinalPeer
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
{
if
verbose
{
fmt
.
Fprintf
(
out
,
"* closest peer %s
\n
"
,
obj
.
ID
)
}
return
nil
},
notif
.
Provider
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
{
notif
.
Provider
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
{
prov
:=
obj
.
Responses
[
0
]
if
verbose
{
fmt
.
Fprintf
(
out
,
"provider: "
)
...
...
@@ -197,13 +199,12 @@ var findProvidersDhtCmd = &cmds.Command{
fmt
.
Fprintf
(
out
,
"
\t
%s
\n
"
,
a
)
}
}
return
nil
},
}
verbose
,
_
:=
req
.
Options
[
dhtVerboseOptionName
]
.
(
bool
)
printEvent
(
out
,
w
,
verbose
,
pfm
)
return
nil
return
printEvent
(
out
,
w
,
verbose
,
pfm
)
}),
},
Type
:
notif
.
QueryEvent
{},
...
...
@@ -239,6 +240,13 @@ var provideRefDhtCmd = &cmds.Command{
return
errors
.
New
(
"cannot provide, no connected peers"
)
}
// Needed to parse stdin args.
// TODO: Lazy Load
err
=
req
.
ParseBodyArgs
()
if
err
!=
nil
{
return
err
}
rec
,
_
:=
req
.
Options
[
recursiveOptionName
]
.
(
bool
)
var
cids
[]
cid
.
Cid
...
...
@@ -290,17 +298,16 @@ var provideRefDhtCmd = &cmds.Command{
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
notif
.
QueryEvent
)
error
{
pfm
:=
pfuncMap
{
notif
.
FinalPeer
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
{
notif
.
FinalPeer
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
{
if
verbose
{
fmt
.
Fprintf
(
out
,
"sending provider record to peer %s
\n
"
,
obj
.
ID
)
}
return
nil
},
}
verbose
,
_
:=
req
.
Options
[
dhtVerboseOptionName
]
.
(
bool
)
printEvent
(
out
,
w
,
verbose
,
pfm
)
return
nil
return
printEvent
(
out
,
w
,
verbose
,
pfm
)
}),
},
Type
:
notif
.
QueryEvent
{},
...
...
@@ -402,17 +409,17 @@ var findPeerDhtCmd = &cmds.Command{
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
notif
.
QueryEvent
)
error
{
pfm
:=
pfuncMap
{
notif
.
FinalPeer
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
{
notif
.
FinalPeer
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
{
pi
:=
obj
.
Responses
[
0
]
for
_
,
a
:=
range
pi
.
Addrs
{
fmt
.
Fprintf
(
out
,
"%s
\n
"
,
a
)
}
return
nil
},
}
verbose
,
_
:=
req
.
Options
[
dhtVerboseOptionName
]
.
(
bool
)
printEvent
(
out
,
w
,
verbose
,
pfm
)
return
nil
return
printEvent
(
out
,
w
,
verbose
,
pfm
)
}),
},
Type
:
notif
.
QueryEvent
{},
...
...
@@ -469,7 +476,7 @@ Different key types can specify other 'best' rules.
}
else
{
notif
.
PublishQueryEvent
(
ctx
,
&
notif
.
QueryEvent
{
Type
:
notif
.
Value
,
Extra
:
s
tring
(
val
),
Extra
:
base64
.
StdEncoding
.
EncodeToS
tring
(
val
),
})
}
}()
...
...
@@ -485,19 +492,22 @@ Different key types can specify other 'best' rules.
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
notif
.
QueryEvent
)
error
{
pfm
:=
pfuncMap
{
notif
.
Value
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
{
notif
.
Value
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
{
if
verbose
{
fmt
.
Fprintf
(
out
,
"got value: '%s'
\n
"
,
obj
.
Extra
)
}
else
{
fmt
.
Fprintln
(
out
,
obj
.
Extra
)
res
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
obj
.
Extra
)
if
err
!=
nil
{
return
err
}
out
.
Write
(
res
)
}
return
nil
},
}
verbose
,
_
:=
req
.
Options
[
dhtVerboseOptionName
]
.
(
bool
)
printEvent
(
out
,
w
,
verbose
,
pfm
)
return
nil
return
printEvent
(
out
,
w
,
verbose
,
pfm
)
}),
},
Type
:
notif
.
QueryEvent
{},
...
...
@@ -538,6 +548,12 @@ 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
}
...
...
@@ -575,38 +591,37 @@ NOTE: A value may not exceed 2048 bytes.
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
notif
.
QueryEvent
)
error
{
pfm
:=
pfuncMap
{
notif
.
FinalPeer
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
{
notif
.
FinalPeer
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
{
if
verbose
{
fmt
.
Fprintf
(
out
,
"* closest peer %s
\n
"
,
obj
.
ID
)
}
return
nil
},
notif
.
Value
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
{
notif
.
Value
:
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
{
fmt
.
Fprintf
(
out
,
"%s
\n
"
,
obj
.
ID
.
Pretty
())
return
nil
},
}
verbose
,
_
:=
req
.
Options
[
dhtVerboseOptionName
]
.
(
bool
)
printEvent
(
out
,
w
,
verbose
,
pfm
)
return
nil
return
printEvent
(
out
,
w
,
verbose
,
pfm
)
}),
},
Type
:
notif
.
QueryEvent
{},
}
type
printFunc
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
type
printFunc
func
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
)
error
type
pfuncMap
map
[
notif
.
QueryEventType
]
printFunc
func
printEvent
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
,
override
pfuncMap
)
{
func
printEvent
(
obj
*
notif
.
QueryEvent
,
out
io
.
Writer
,
verbose
bool
,
override
pfuncMap
)
error
{
if
verbose
{
fmt
.
Fprintf
(
out
,
"%s: "
,
time
.
Now
()
.
Format
(
"15:04:05.000"
))
}
if
override
!=
nil
{
if
pf
,
ok
:=
override
[
obj
.
Type
];
ok
{
pf
(
obj
,
out
,
verbose
)
return
return
pf
(
obj
,
out
,
verbose
)
}
}
...
...
@@ -647,6 +662,7 @@ func printEvent(obj *notif.QueryEvent, out io.Writer, verbose bool, override pfu
fmt
.
Fprintf
(
out
,
"unrecognized event type: %d
\n
"
,
obj
.
Type
)
}
}
return
nil
}
func
escapeDhtKey
(
s
string
)
(
string
,
error
)
{
...
...
test/sharness/t0170-dht.sh
浏览文件 @
307d06b4
...
...
@@ -35,6 +35,12 @@ test_dht() {
[ -s putted ] ||
test_fsh cat putted
'
test_expect_success
'put round trips'
'
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'
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论