Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
454a1700
Unverified
提交
454a1700
authored
7月 18, 2018
作者:
Whyrusleeping
提交者:
GitHub
7月 18, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5245 from ipfs/fix/5241
add trickle-dag support to the urlstore
上级
d74ec0d9
4d4f343d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
38 行增加
和
17 行删除
+38
-17
root.go
core/commands/root.go
+1
-1
urlstore.go
core/commands/urlstore.go
+22
-16
t0272-urlstore.sh
test/sharness/t0272-urlstore.sh
+15
-0
没有找到文件。
core/commands/root.go
浏览文件 @
454a1700
...
...
@@ -136,7 +136,7 @@ var rootSubcommands = map[string]*cmds.Command{
"tar"
:
lgc
.
NewCommand
(
TarCmd
),
"file"
:
lgc
.
NewCommand
(
unixfs
.
UnixFSCmd
),
"update"
:
lgc
.
NewCommand
(
ExternalBinary
()),
"urlstore"
:
lgc
.
NewCommand
(
urlStoreCmd
)
,
"urlstore"
:
urlStoreCmd
,
"version"
:
lgc
.
NewCommand
(
VersionCmd
),
"shutdown"
:
lgc
.
NewCommand
(
daemonShutdownCmd
),
}
...
...
core/commands/urlstore.go
浏览文件 @
454a1700
...
...
@@ -4,13 +4,13 @@ import (
"fmt"
"io"
"net/http"
"strings"
cmds
"github.com/ipfs/go-ipfs/commands"
filestore
"github.com/ipfs/go-ipfs/filestore"
balanced
"github.com/ipfs/go-ipfs/importer/balanced"
ihelper
"github.com/ipfs/go-ipfs/importer/helpers"
trickle
"github.com/ipfs/go-ipfs/importer/trickle"
cmds
"gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
mh
"gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
chunk
"gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
cid
"gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
...
...
@@ -18,7 +18,6 @@ import (
)
var
urlStoreCmd
=
&
cmds
.
Command
{
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"add"
:
urlAdd
,
},
...
...
@@ -44,14 +43,17 @@ found. It may disappear or the semantics can change at any
time.
`
,
},
Options
:
[]
cmdkit
.
Option
{
cmdkit
.
BoolOption
(
trickleOptionName
,
"t"
,
"Use trickle-dag format for dag generation."
),
},
Arguments
:
[]
cmdkit
.
Argument
{
cmdkit
.
StringArg
(
"url"
,
true
,
false
,
"URL to add to IPFS"
),
},
Type
:
BlockStat
{},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
url
:=
req
.
Arguments
()
[
0
]
n
,
err
:=
req
.
InvocContext
()
.
GetNode
(
)
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
{
url
:=
req
.
Arguments
[
0
]
n
,
err
:=
GetNode
(
env
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
...
...
@@ -73,6 +75,8 @@ time.
return
}
useTrickledag
,
_
:=
req
.
Options
[
trickleOptionName
]
.
(
bool
)
hreq
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
...
...
@@ -100,23 +104,25 @@ time.
URL
:
url
,
}
blc
,
err
:=
balanced
.
Layout
(
dbp
.
New
(
chk
))
layout
:=
balanced
.
Layout
if
useTrickledag
{
layout
=
trickle
.
Layout
}
root
,
err
:=
layout
(
dbp
.
New
(
chk
))
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
res
.
SetOutput
(
BlockStat
{
Key
:
blc
.
Cid
()
.
String
(),
cmds
.
EmitOnce
(
res
,
BlockStat
{
Key
:
root
.
Cid
()
.
String
(),
Size
:
int
(
hres
.
ContentLength
),
})
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
ch
:=
res
.
Output
()
.
(
<-
chan
interface
{})
bs0
:=
<-
ch
bs
:=
bs0
.
(
*
BlockStat
)
return
strings
.
NewReader
(
bs
.
Key
+
"
\n
"
),
nil
},
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
bs
*
BlockStat
)
error
{
_
,
err
:=
fmt
.
Fprintln
(
w
,
bs
.
Key
)
return
err
}),
},
}
test/sharness/t0272-urlstore.sh
浏览文件 @
454a1700
...
...
@@ -124,6 +124,12 @@ test_expect_success "get large file via urlstore" '
test_cmp file3 file3.actual
'
test_expect_success
"check that the trickle option works"
'
HASHat=$(ipfs add -q --cid-version=1 --raw-leaves=true -n --trickle file3) &&
HASHut=$(ipfs urlstore add --trickle http://127.0.0.1:$GWAY_PORT/ipfs/$HASH3a) &&
test $HASHat = $HASHut
'
test_kill_ipfs_daemon
test_expect_success
"files can not be retrieved via the urlstore"
'
...
...
@@ -132,4 +138,13 @@ test_expect_success "files can not be retrieved via the urlstore" '
test_must_fail ipfs cat $HASH3 > /dev/null
'
test_expect_success
"check that the hashes were correct"
'
HASH1e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file1) &&
HASH2e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file2) &&
HASH3e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file3) &&
test $HASH1e = $HASH1 &&
test $HASH2e = $HASH2 &&
test $HASH3e = $HASH3
'
test_done
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论