Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
734615ac
提交
734615ac
authored
10月 16, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
namesys: avoid defer in loop
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
462c8026
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
4 行删除
+15
-4
base.go
namesys/base.go
+13
-2
namesys.go
namesys/namesys.go
+2
-2
没有找到文件。
namesys/base.go
浏览文件 @
734615ac
...
@@ -60,6 +60,9 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
...
@@ -60,6 +60,9 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
if
res
.
err
!=
nil
{
if
res
.
err
!=
nil
{
outCh
<-
Result
{
Err
:
res
.
err
}
outCh
<-
Result
{
Err
:
res
.
err
}
if
cancelSub
!=
nil
{
cancelSub
()
}
return
return
}
}
log
.
Debugf
(
"resolved %s to %s"
,
name
,
res
.
value
.
String
())
log
.
Debugf
(
"resolved %s to %s"
,
name
,
res
.
value
.
String
())
...
@@ -79,12 +82,11 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
...
@@ -79,12 +82,11 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
}
}
var
subCtx
context
.
Context
var
subCtx
context
.
Context
if
subCh
!=
nil
{
if
cancelSub
!=
nil
{
// Cancel previous recursive resolve since it won't be used anyways
// Cancel previous recursive resolve since it won't be used anyways
cancelSub
()
cancelSub
()
}
}
subCtx
,
cancelSub
=
context
.
WithCancel
(
ctx
)
subCtx
,
cancelSub
=
context
.
WithCancel
(
ctx
)
defer
cancelSub
()
p
:=
strings
.
TrimPrefix
(
res
.
value
.
String
(),
ipnsPrefix
)
p
:=
strings
.
TrimPrefix
(
res
.
value
.
String
(),
ipnsPrefix
)
subCh
=
resolveAsync
(
subCtx
,
r
,
p
,
subopts
)
subCh
=
resolveAsync
(
subCtx
,
r
,
p
,
subopts
)
...
@@ -97,12 +99,21 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
...
@@ -97,12 +99,21 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
select
{
select
{
case
outCh
<-
res
:
case
outCh
<-
res
:
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
if
cancelSub
!=
nil
{
cancelSub
()
}
return
return
}
}
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
if
cancelSub
!=
nil
{
cancelSub
()
}
return
return
}
}
if
resCh
==
nil
&&
subCh
==
nil
{
if
resCh
==
nil
&&
subCh
==
nil
{
if
cancelSub
!=
nil
{
cancelSub
()
}
return
return
}
}
}
}
...
...
namesys/namesys.go
浏览文件 @
734615ac
...
@@ -86,8 +86,8 @@ func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.R
...
@@ -86,8 +86,8 @@ func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.R
func
(
ns
*
mpns
)
resolveOnceAsync
(
ctx
context
.
Context
,
name
string
,
options
opts
.
ResolveOpts
)
<-
chan
onceResult
{
func
(
ns
*
mpns
)
resolveOnceAsync
(
ctx
context
.
Context
,
name
string
,
options
opts
.
ResolveOpts
)
<-
chan
onceResult
{
out
:=
make
(
chan
onceResult
,
1
)
out
:=
make
(
chan
onceResult
,
1
)
if
!
strings
.
HasPrefix
(
name
,
"/ipns/"
)
{
if
!
strings
.
HasPrefix
(
name
,
ipnsPrefix
)
{
name
=
"/ipns/"
+
name
name
=
ipnsPrefix
+
name
}
}
segments
:=
strings
.
SplitN
(
name
,
"/"
,
4
)
segments
:=
strings
.
SplitN
(
name
,
"/"
,
4
)
if
len
(
segments
)
<
3
||
segments
[
0
]
!=
""
{
if
len
(
segments
)
<
3
||
segments
[
0
]
!=
""
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论