Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
325e1c08
提交
325e1c08
authored
3月 29, 2017
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"pin verify": basic implementation
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
4cf046c4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
107 行增加
和
0 行删除
+107
-0
pin.go
core/commands/pin.go
+107
-0
没有找到文件。
core/commands/pin.go
浏览文件 @
325e1c08
...
...
@@ -27,6 +27,7 @@ var PinCmd = &cmds.Command{
"add"
:
addPinCmd
,
"rm"
:
rmPinCmd
,
"ls"
:
listPinCmd
,
"verify"
:
verifyPinCmd
,
"update"
:
updatePinCmd
,
},
}
...
...
@@ -410,6 +411,27 @@ new pin and removing the old one.
},
}
var
verifyPinCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Verify that recursive pins are complete."
,
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
_
:=
req
.
InvocContext
()
.
GetNode
()
rdr
,
wtr
:=
io
.
Pipe
()
out
:=
pinVerify
(
req
.
Context
(),
n
)
go
func
()
{
defer
wtr
.
Close
()
for
r
:=
range
out
{
r
.
Format
(
wtr
)
}
}()
res
.
SetOutput
(
rdr
)
},
}
type
RefKeyObject
struct
{
Type
string
}
...
...
@@ -492,6 +514,91 @@ func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string
return
keys
,
nil
}
type
pinStatus
struct
{
// use pointer to array slice to reduce memory usage
// the value should not be nil unless uninitialized
badNodes
*
[]
badNode
}
type
badNode
struct
{
cid
*
cid
.
Cid
err
error
}
type
pinVerifyRes
struct
{
cid
*
cid
.
Cid
pinStatus
}
func
pinVerify
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
)
<-
chan
pinVerifyRes
{
visited
:=
make
(
map
[
string
]
pinStatus
)
getLinks
:=
n
.
DAG
.
GetOfflineLinkService
()
.
GetLinks
emptySlice
:=
&
[]
badNode
{}
recPins
:=
n
.
Pinning
.
RecursiveKeys
()
var
checkPin
func
(
root
*
cid
.
Cid
)
pinStatus
checkPin
=
func
(
root
*
cid
.
Cid
)
pinStatus
{
key
:=
root
.
String
()
if
status
,
ok
:=
visited
[
key
];
ok
{
if
status
.
badNodes
==
nil
{
return
pinStatus
{
&
[]
badNode
{
badNode
{
cid
:
root
,
err
:
fmt
.
Errorf
(
"Cycle Detected."
)}}}
}
return
status
}
links
,
err
:=
getLinks
(
ctx
,
root
)
if
err
!=
nil
{
status
:=
pinStatus
{
&
[]
badNode
{
badNode
{
cid
:
root
,
err
:
err
}}}
visited
[
key
]
=
status
return
status
}
status
:=
pinStatus
{}
visited
[
key
]
=
status
// paranoid mode cycle detection
for
_
,
lnk
:=
range
links
{
res
:=
checkPin
(
lnk
.
Cid
)
if
len
(
*
res
.
badNodes
)
>
0
{
if
status
.
badNodes
==
nil
{
status
.
badNodes
=
res
.
badNodes
}
else
{
slice
:=
append
(
*
status
.
badNodes
,
*
res
.
badNodes
...
)
status
.
badNodes
=
&
slice
}
}
}
if
status
.
badNodes
==
nil
{
status
.
badNodes
=
emptySlice
// prevent special cases
}
visited
[
key
]
=
status
return
status
}
out
:=
make
(
chan
pinVerifyRes
)
go
func
()
{
defer
close
(
out
)
for
_
,
cid
:=
range
recPins
{
pinStatus
:=
checkPin
(
cid
)
out
<-
pinVerifyRes
{
cid
,
pinStatus
}
}
}()
return
out
}
func
(
r
pinVerifyRes
)
Format
(
out
io
.
Writer
)
{
if
len
(
*
r
.
badNodes
)
==
0
{
fmt
.
Fprintf
(
out
,
"%s ok
\n
"
,
r
.
cid
)
}
else
{
fmt
.
Fprintf
(
out
,
"%s broken
\n
"
,
r
.
cid
)
for
_
,
e
:=
range
*
r
.
badNodes
{
fmt
.
Fprintf
(
out
,
" %s: %s
\n
"
,
e
.
cid
,
e
.
err
)
}
}
}
func
cidsToStrings
(
cs
[]
*
cid
.
Cid
)
[]
string
{
out
:=
make
([]
string
,
0
,
len
(
cs
))
for
_
,
c
:=
range
cs
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论