Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
9b925e0e
提交
9b925e0e
authored
8月 13, 2018
作者:
Łukasz Magiera
提交者:
Steven Allen
8月 27, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: block: don't allow creation of invalid cidv0s
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
c3e69073
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
27 行增加
和
9 行删除
+27
-9
block.go
core/commands/block.go
+9
-7
block.go
core/coreapi/block.go
+16
-0
block_test.go
core/coreapi/block_test.go
+1
-1
block.go
core/coreapi/interface/options/block.go
+1
-1
没有找到文件。
core/commands/block.go
浏览文件 @
9b925e0e
...
...
@@ -186,10 +186,10 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
format
,
formatSet
:=
req
.
Options
[
"format"
]
.
(
string
)
if
!
formatSet
{
if
mhtval
==
mh
.
SHA2_256
{
format
=
"v0"
}
else
{
if
mhtval
!=
mh
.
SHA2_256
||
(
mhlen
!=
-
1
&&
mhlen
!=
32
)
{
format
=
"protobuf"
}
else
{
format
=
"v0"
}
}
...
...
@@ -260,16 +260,18 @@ It takes a list of base58 encoded multihashes to remove.
}
err
=
api
.
Block
()
.
Rm
(
req
.
Context
,
rp
,
options
.
Block
.
Force
(
force
))
if
err
!=
nil
&&
!
quiet
{
if
err
!=
nil
{
res
.
Emit
(
&
util
.
RemovedBlock
{
Hash
:
rp
.
Cid
()
.
String
(),
Error
:
err
.
Error
(),
})
}
res
.
Emit
(
&
util
.
RemovedBlock
{
Hash
:
rp
.
Cid
()
.
String
(),
})
if
!
quiet
{
res
.
Emit
(
&
util
.
RemovedBlock
{
Hash
:
rp
.
Cid
()
.
String
(),
})
}
}
},
PostRun
:
cmds
.
PostRunMap
{
...
...
core/coreapi/block.go
浏览文件 @
9b925e0e
...
...
@@ -38,13 +38,29 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc
var
pref
cid
.
Prefix
pref
.
Version
=
1
if
settings
.
Codec
==
""
{
if
settings
.
MhType
!=
mh
.
SHA2_256
||
(
settings
.
MhLength
!=
-
1
&&
settings
.
MhLength
!=
32
)
{
settings
.
Codec
=
"protobuf"
}
else
{
settings
.
Codec
=
"v0"
}
}
formatval
,
ok
:=
cid
.
Codecs
[
settings
.
Codec
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unrecognized format: %s"
,
settings
.
Codec
)
}
if
settings
.
Codec
==
"v0"
&&
settings
.
MhType
==
mh
.
SHA2_256
{
pref
.
Version
=
0
}
if
settings
.
Codec
==
"v0"
{
if
settings
.
MhType
!=
mh
.
SHA2_256
||
(
settings
.
MhLength
!=
-
1
&&
settings
.
MhLength
!=
32
)
{
return
nil
,
fmt
.
Errorf
(
"only sha2-255-32 is allowed with CIDv0"
)
}
}
pref
.
Codec
=
formatval
pref
.
MhType
=
settings
.
MhType
...
...
core/coreapi/block_test.go
浏览文件 @
9b925e0e
...
...
@@ -55,7 +55,7 @@ func TestBlockPutHash(t *testing.T) {
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
opt
.
Block
.
Hash
(
mh
.
KECCAK_512
,
-
1
))
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Fatal
(
err
)
}
if
res
.
Path
()
.
Cid
()
.
String
()
!=
"zBurKB9YZkcDf6xa53WBE8CFX4ydVqAyf9KPXBFZt5stJzEstaS8Hukkhu4gwpMtc1xHNDbzP7sPtQKyWsP3C8fbhkmrZ"
{
...
...
core/coreapi/interface/options/block.go
浏览文件 @
9b925e0e
...
...
@@ -19,7 +19,7 @@ type BlockRmOption func(*BlockRmSettings) error
func
BlockPutOptions
(
opts
...
BlockPutOption
)
(
*
BlockPutSettings
,
error
)
{
options
:=
&
BlockPutSettings
{
Codec
:
"
v0
"
,
Codec
:
""
,
MhType
:
multihash
.
SHA2_256
,
MhLength
:
-
1
,
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论