Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
61d2e946
提交
61d2e946
authored
12月 05, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
providers: ProvideRecursive
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
25ceb80f
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
54 行增加
和
9 行删除
+54
-9
builder.go
core/builder.go
+3
-0
add.go
core/commands/add.go
+7
-1
providers.go
providers/providers.go
+35
-6
workers.go
providers/workers.go
+9
-2
没有找到文件。
core/builder.go
浏览文件 @
61d2e946
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
dag
"github.com/ipfs/go-ipfs/merkledag"
dag
"github.com/ipfs/go-ipfs/merkledag"
resolver
"github.com/ipfs/go-ipfs/path/resolver"
resolver
"github.com/ipfs/go-ipfs/path/resolver"
pin
"github.com/ipfs/go-ipfs/pin"
pin
"github.com/ipfs/go-ipfs/pin"
providers
"github.com/ipfs/go-ipfs/providers"
repo
"github.com/ipfs/go-ipfs/repo"
repo
"github.com/ipfs/go-ipfs/repo"
cfg
"github.com/ipfs/go-ipfs/repo/config"
cfg
"github.com/ipfs/go-ipfs/repo/config"
"github.com/ipfs/go-ipfs/thirdparty/verifbs"
"github.com/ipfs/go-ipfs/thirdparty/verifbs"
...
@@ -237,7 +238,9 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
...
@@ -237,7 +238,9 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
return
err
return
err
}
}
}
else
{
}
else
{
n
.
SetupOfflineRouting
()
n
.
Exchange
=
offline
.
Exchange
(
n
.
Blockstore
)
n
.
Exchange
=
offline
.
Exchange
(
n
.
Blockstore
)
n
.
Providers
=
providers
.
NewProviders
(
n
.
ctx
,
n
.
Routing
,
nil
)
}
}
n
.
Blocks
=
bserv
.
New
(
n
.
Blockstore
,
n
.
Exchange
)
n
.
Blocks
=
bserv
.
New
(
n
.
Blockstore
,
n
.
Exchange
)
...
...
core/commands/add.go
浏览文件 @
61d2e946
...
@@ -313,7 +313,7 @@ You can now check what blocks have been created by:
...
@@ -313,7 +313,7 @@ You can now check what blocks have been created by:
}
}
// copy intermediary nodes from editor to our actual dagservice
// copy intermediary nodes from editor to our actual dagservice
_
,
err
:=
fileAdder
.
Finalize
()
nd
,
err
:=
fileAdder
.
Finalize
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -322,6 +322,12 @@ You can now check what blocks have been created by:
...
@@ -322,6 +322,12 @@ You can now check what blocks have been created by:
return
nil
return
nil
}
}
if
!
local
{
if
err
:=
n
.
Providers
.
ProvideRecursive
(
req
.
Context
,
nd
,
dserv
);
err
!=
nil
{
return
err
}
}
return
fileAdder
.
PinRoot
()
return
fileAdder
.
PinRoot
()
}
}
...
...
providers/providers.go
浏览文件 @
61d2e946
...
@@ -4,21 +4,22 @@ import (
...
@@ -4,21 +4,22 @@ import (
"context"
"context"
"time"
"time"
host
"gx/ipfs/QmQQGtcp6nVUrQjNsnU53YWV1q8fK1Kd9S7FEkYbRZzxry/go-libp2p-host"
flags
"gx/ipfs/QmRMGdC6HKdLsPDABL9aXPDidrpmEHzJqFWSvshkbn9Hj8/go-ipfs-flags"
flags
"gx/ipfs/QmRMGdC6HKdLsPDABL9aXPDidrpmEHzJqFWSvshkbn9Hj8/go-ipfs-flags"
process
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
process
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
procctx
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
procctx
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
logging
"gx/ipfs/Qmbi1CTJsbnBZjCEgc2otwu8cUFPsGpzWXG7edVCLZ7Gvk/go-log"
routing
"gx/ipfs/QmUV9hDAAyjeGbxbXkJ2sYqZ6dTd1DXJ2REhYEkRm178Tg/go-libp2p-routing"
routing
"gx/ipfs/QmUV9hDAAyjeGbxbXkJ2sYqZ6dTd1DXJ2REhYEkRm178Tg/go-libp2p-routing"
peer
"gx/ipfs/QmVf8hTAsLLFtn4WPCRNdnaF2Eag2qTBS6uR8AiHPZARXy/go-libp2p-peer"
peer
"gx/ipfs/QmVf8hTAsLLFtn4WPCRNdnaF2Eag2qTBS6uR8AiHPZARXy/go-libp2p-peer"
cid
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid
"
ipld
"gx/ipfs/QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb/go-ipld-format
"
pstore
"gx/ipfs/QmZhsmorLpD9kmQ4ynbAu4vbKv2goMUnXazwGA4gnWHDjB/go-libp2p-peerstore"
pstore
"gx/ipfs/QmZhsmorLpD9kmQ4ynbAu4vbKv2goMUnXazwGA4gnWHDjB/go-libp2p-peerstore"
host
"gx/ipfs/QmQQGtcp6nVUrQjNsnU53YWV1q8fK1Kd9S7FEkYbRZzxry/go-libp2p-host"
cid
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
logging
"gx/ipfs/Qmbi1CTJsbnBZjCEgc2otwu8cUFPsGpzWXG7edVCLZ7Gvk/go-log"
)
)
const
(
const
(
provideTimeout
=
time
.
Second
*
15
provideTimeout
=
time
.
Second
*
15
//
m
axProvidersPerRequest specifies the maximum number of providers desired
//
M
axProvidersPerRequest specifies the maximum number of providers desired
// from the network. This value is specified because the network streams
// from the network. This value is specified because the network streams
// results.
// results.
// TODO: if a 'non-nice' strategy is implemented, consider increasing this value
// TODO: if a 'non-nice' strategy is implemented, consider increasing this value
...
@@ -46,8 +47,10 @@ type blockRequest struct {
...
@@ -46,8 +47,10 @@ type blockRequest struct {
// Interface is an definition of providers interface to libp2p routing system
// Interface is an definition of providers interface to libp2p routing system
type
Interface
interface
{
type
Interface
interface
{
Provide
(
*
cid
.
Cid
)
error
Provide
(
k
*
cid
.
Cid
)
error
FindProviders
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
error
ProvideRecursive
(
ctx
context
.
Context
,
n
ipld
.
Node
,
serv
ipld
.
NodeGetter
)
error
FindProviders
(
ctx
context
.
Context
,
k
*
cid
.
Cid
)
error
FindProvidersAsync
(
ctx
context
.
Context
,
k
*
cid
.
Cid
,
max
int
)
<-
chan
peer
.
ID
FindProvidersAsync
(
ctx
context
.
Context
,
k
*
cid
.
Cid
,
max
int
)
<-
chan
peer
.
ID
Stat
()
(
*
Stat
,
error
)
Stat
()
(
*
Stat
,
error
)
...
@@ -119,6 +122,29 @@ func (p *providers) Provide(b *cid.Cid) error {
...
@@ -119,6 +122,29 @@ func (p *providers) Provide(b *cid.Cid) error {
return
nil
return
nil
}
}
func
(
p
*
providers
)
provideRecursive
(
ctx
context
.
Context
,
n
ipld
.
Node
,
serv
ipld
.
NodeGetter
,
done
*
cid
.
Set
)
error
{
p
.
Provide
(
n
.
Cid
())
for
_
,
l
:=
range
n
.
Links
()
{
if
!
done
.
Visit
(
l
.
Cid
)
{
continue
}
sub
,
err
:=
l
.
GetNode
(
ctx
,
serv
)
if
err
!=
nil
{
return
err
}
if
err
:=
p
.
provideRecursive
(
ctx
,
sub
,
serv
,
done
);
err
!=
nil
{
return
err
}
}
return
nil
}
func
(
p
*
providers
)
ProvideRecursive
(
ctx
context
.
Context
,
n
ipld
.
Node
,
serv
ipld
.
NodeGetter
)
error
{
return
p
.
provideRecursive
(
ctx
,
n
,
serv
,
cid
.
NewSet
())
}
func
(
p
*
providers
)
FindProviders
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
error
{
func
(
p
*
providers
)
FindProviders
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
error
{
select
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
...
@@ -130,6 +156,9 @@ func (p *providers) FindProviders(ctx context.Context, c *cid.Cid) error {
...
@@ -130,6 +156,9 @@ func (p *providers) FindProviders(ctx context.Context, c *cid.Cid) error {
// FindProvidersAsync returns a channel of providers for the given key
// FindProvidersAsync returns a channel of providers for the given key
func
(
p
*
providers
)
FindProvidersAsync
(
ctx
context
.
Context
,
k
*
cid
.
Cid
,
max
int
)
<-
chan
peer
.
ID
{
func
(
p
*
providers
)
FindProvidersAsync
(
ctx
context
.
Context
,
k
*
cid
.
Cid
,
max
int
)
<-
chan
peer
.
ID
{
if
p
.
host
==
nil
{
return
nil
}
// Since routing queries are expensive, give bitswap the peers to which we
// Since routing queries are expensive, give bitswap the peers to which we
// have open connections. Note that this may cause issues if bitswap starts
// have open connections. Note that this may cause issues if bitswap starts
...
...
providers/workers.go
浏览文件 @
61d2e946
...
@@ -6,13 +6,20 @@ import (
...
@@ -6,13 +6,20 @@ import (
process
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
process
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
procctx
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
procctx
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
logging
"gx/ipfs/Qmbi1CTJsbnBZjCEgc2otwu8cUFPsGpzWXG7edVCLZ7Gvk/go-log"
peer
"gx/ipfs/QmVf8hTAsLLFtn4WPCRNdnaF2Eag2qTBS6uR8AiHPZARXy/go-libp2p-peer"
peer
"gx/ipfs/QmVf8hTAsLLFtn4WPCRNdnaF2Eag2qTBS6uR8AiHPZARXy/go-libp2p-peer"
cid
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
pstore
"gx/ipfs/QmZhsmorLpD9kmQ4ynbAu4vbKv2goMUnXazwGA4gnWHDjB/go-libp2p-peerstore"
pstore
"gx/ipfs/QmZhsmorLpD9kmQ4ynbAu4vbKv2goMUnXazwGA4gnWHDjB/go-libp2p-peerstore"
cid
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
logging
"gx/ipfs/Qmbi1CTJsbnBZjCEgc2otwu8cUFPsGpzWXG7edVCLZ7Gvk/go-log"
)
)
func
(
p
*
providers
)
startWorkers
(
ctx
context
.
Context
,
px
process
.
Process
)
{
func
(
p
*
providers
)
startWorkers
(
ctx
context
.
Context
,
px
process
.
Process
)
{
if
p
.
host
!=
nil
{
// Start up a worker to handle block requests this node is making
px
.
Go
(
func
(
px
process
.
Process
)
{
p
.
providerQueryManager
(
ctx
)
})
}
// Start up a worker to manage sending out provides messages
// Start up a worker to manage sending out provides messages
px
.
Go
(
func
(
px
process
.
Process
)
{
px
.
Go
(
func
(
px
process
.
Process
)
{
p
.
provideCollector
(
ctx
)
p
.
provideCollector
(
ctx
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论