Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
1e31aba7
提交
1e31aba7
authored
9月 18, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve cmd: port to new cmd lib
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
ec96a21d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
22 行增加
和
32 行删除
+22
-32
resolve.go
core/commands/resolve.go
+20
-30
root.go
core/commands/root.go
+2
-2
没有找到文件。
core/commands/resolve.go
浏览文件 @
1e31aba7
...
...
@@ -2,12 +2,13 @@ package commands
import
(
"errors"
"fmt"
"io"
"strings"
"time"
cmds
"github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/core"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
e
"github.com/ipfs/go-ipfs/core/commands/e"
ncmd
"github.com/ipfs/go-ipfs/core/commands/name"
ns
"github.com/ipfs/go-ipfs/namesys"
...
...
@@ -15,6 +16,7 @@ import (
path
"gx/ipfs/QmX7uSbkNz76yNwBhuwYwRbhihLnJqM73VTCjS3UMJud9A/go-path"
uio
"gx/ipfs/QmPL8bYtbACcSFFiSr4s2du7Na382NxRADR8hC7D9FkEA2/go-unixfs/io"
"gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
resolver
"gx/ipfs/QmX7uSbkNz76yNwBhuwYwRbhihLnJqM73VTCjS3UMJud9A/go-path/resolver"
)
...
...
@@ -67,29 +69,20 @@ Resolve the value of an IPFS DAG path:
cmdkit
.
UintOption
(
"dht-record-count"
,
"dhtrc"
,
"Number of records to request for DHT resolution."
),
cmdkit
.
StringOption
(
"dht-timeout"
,
"dhtt"
,
"Max time to collect values during DHT resolution eg
\"
30s
\"
. Pass 0 for no timeout."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
{
n
,
err
:=
cmdenv
.
GetNode
(
env
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
if
!
n
.
OnlineMode
()
{
err
:=
n
.
SetupOfflineRouting
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
}
name
:=
req
.
Arguments
()[
0
]
recursive
,
_
,
_
:=
req
.
Option
(
"recursive"
)
.
Bool
()
name
:=
req
.
Arguments
[
0
]
recursive
,
_
:=
req
.
Options
[
"recursive"
]
.
(
bool
)
// the case when ipns is resolved step by step
if
strings
.
HasPrefix
(
name
,
"/ipns/"
)
&&
!
recursive
{
rc
,
rcok
,
_
:=
req
.
Option
(
"dht-record-count"
)
.
Int
(
)
dhtt
,
dhttok
,
_
:=
req
.
Option
(
"dht-timeout"
)
.
String
(
)
rc
,
rcok
:=
req
.
Options
[
"dht-record-count"
]
.
(
int
)
dhtt
,
dhttok
:=
req
.
Options
[
"dht-timeout"
]
.
(
string
)
ropts
:=
[]
nsopts
.
ResolveOpt
{
nsopts
.
Depth
(
1
)}
if
rcok
{
ropts
=
append
(
ropts
,
nsopts
.
DhtRecordCount
(
uint
(
rc
)))
...
...
@@ -106,13 +99,13 @@ Resolve the value of an IPFS DAG path:
}
ropts
=
append
(
ropts
,
nsopts
.
DhtTimeout
(
d
))
}
p
,
err
:=
n
.
Namesys
.
Resolve
(
req
.
Context
()
,
name
,
ropts
...
)
p
,
err
:=
n
.
Namesys
.
Resolve
(
req
.
Context
,
name
,
ropts
...
)
// ErrResolveRecursion is fine
if
err
!=
nil
&&
err
!=
ns
.
ErrResolveRecursion
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
res
.
SetOutput
(
&
ncmd
.
ResolvedPath
{
Path
:
p
})
cmds
.
EmitOnce
(
res
,
&
ncmd
.
ResolvedPath
{
Path
:
p
})
return
}
...
...
@@ -128,7 +121,7 @@ Resolve the value of an IPFS DAG path:
ResolveOnce
:
uio
.
ResolveUnixfsOnce
,
}
node
,
err
:=
core
.
Resolve
(
req
.
Context
()
,
n
.
Namesys
,
r
,
p
)
node
,
err
:=
core
.
Resolve
(
req
.
Context
,
n
.
Namesys
,
r
,
p
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
...
...
@@ -136,21 +129,18 @@ Resolve the value of an IPFS DAG path:
c
:=
node
.
Cid
()
res
.
SetOutput
(
&
ncmd
.
ResolvedPath
{
Path
:
path
.
FromCid
(
c
)})
cmds
.
EmitOnce
(
res
,
&
ncmd
.
ResolvedPath
{
Path
:
path
.
FromCid
(
c
)})
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
v
,
err
:=
unwrapOutput
(
res
.
Output
())
if
err
!=
nil
{
return
nil
,
err
}
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
v
interface
{})
error
{
output
,
ok
:=
v
.
(
*
ncmd
.
ResolvedPath
)
if
!
ok
{
return
nil
,
e
.
TypeErr
(
output
,
v
)
return
e
.
TypeErr
(
output
,
v
)
}
return
strings
.
NewReader
(
output
.
Path
.
String
()
+
"
\n
"
),
nil
},
fmt
.
Fprintln
(
w
,
output
.
Path
.
String
())
return
nil
}),
},
Type
:
ncmd
.
ResolvedPath
{},
}
core/commands/root.go
浏览文件 @
1e31aba7
...
...
@@ -135,7 +135,7 @@ var rootSubcommands = map[string]*cmds.Command{
"ping"
:
lgc
.
NewCommand
(
PingCmd
),
"p2p"
:
lgc
.
NewCommand
(
P2PCmd
),
"refs"
:
lgc
.
NewCommand
(
RefsCmd
),
"resolve"
:
lgc
.
NewCommand
(
ResolveCmd
)
,
"resolve"
:
ResolveCmd
,
"swarm"
:
lgc
.
NewCommand
(
SwarmCmd
),
"tar"
:
lgc
.
NewCommand
(
TarCmd
),
"file"
:
lgc
.
NewCommand
(
unixfs
.
UnixFSCmd
),
...
...
@@ -183,7 +183,7 @@ var rootROSubcommands = map[string]*cmds.Command{
"resolve"
:
dag
.
DagResolveCmd
,
},
}),
"resolve"
:
lgc
.
NewCommand
(
ResolveCmd
)
,
"resolve"
:
ResolveCmd
,
"version"
:
lgc
.
NewCommand
(
VersionCmd
),
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论