Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
d6ce837d
提交
d6ce837d
authored
1月 20, 2015
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core/bootstrap: cleaned up bootstrapping
Moved it to its own package to isolate scope.
上级
c43f97d6
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
179 行增加
和
112 行删除
+179
-112
bootstrap.go
core/bootstrap.go
+148
-55
core.go
core/core.go
+2
-20
dht_bootstrap.go
routing/dht/dht_bootstrap.go
+29
-37
没有找到文件。
core/bootstrap.go
浏览文件 @
d6ce837d
差异被折叠。
点击展开。
core/core.go
浏览文件 @
d6ce837d
...
@@ -297,30 +297,12 @@ func (n *IpfsNode) Resolve(path string) (*merkledag.Node, error) {
...
@@ -297,30 +297,12 @@ func (n *IpfsNode) Resolve(path string) (*merkledag.Node, error) {
func
(
n
*
IpfsNode
)
Bootstrap
(
ctx
context
.
Context
,
peers
[]
peer
.
PeerInfo
)
error
{
func
(
n
*
IpfsNode
)
Bootstrap
(
ctx
context
.
Context
,
peers
[]
peer
.
PeerInfo
)
error
{
// TODO what should return value be when in offlineMode?
// TODO what should return value be when in offlineMode?
if
n
.
Routing
==
nil
{
if
n
.
Routing
==
nil
{
return
nil
return
nil
}
}
// TODO what bootstrapping should happen if there is no DHT? i.e. we could
nb
:=
nodeBootstrapper
{
n
}
// continue connecting to our bootstrap peers, but for what purpose?
return
nb
.
TryToBootstrap
(
ctx
,
peers
)
dhtRouting
,
ok
:=
n
.
Routing
.
(
*
dht
.
IpfsDHT
)
if
!
ok
{
return
nil
}
// TODO consider moving connection supervision into the Network. We've
// discussed improvements to this Node constructor. One improvement
// would be to make the node configurable, allowing clients to inject
// an Exchange, Network, or Routing component and have the constructor
// manage the wiring. In that scenario, this dangling function is a bit
// awkward.
// spin off the node's connection supervisor.
// TODO, clean up how this thing works. Make the superviseConnections thing
// work like the DHT.Bootstrap.
go
superviseConnections
(
ctx
,
n
.
PeerHost
,
dhtRouting
,
n
.
Peerstore
,
peers
)
return
nil
}
}
func
(
n
*
IpfsNode
)
loadID
()
error
{
func
(
n
*
IpfsNode
)
loadID
()
error
{
...
...
routing/dht/dht_bootstrap.go
浏览文件 @
d6ce837d
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
goprocess
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
goprocess
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
periodicproc
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/periodic"
)
)
// DefaultBootstrapQueries specifies how many queries to run,
// DefaultBootstrapQueries specifies how many queries to run,
...
@@ -54,9 +55,9 @@ const DefaultBootstrapTimeout = time.Duration(10 * time.Second)
...
@@ -54,9 +55,9 @@ const DefaultBootstrapTimeout = time.Duration(10 * time.Second)
// and connected to at least a few nodes.
// and connected to at least a few nodes.
//
//
// Like PeriodicBootstrap, Bootstrap returns a process, so the user can stop it.
// Like PeriodicBootstrap, Bootstrap returns a process, so the user can stop it.
func
(
dht
*
IpfsDHT
)
Bootstrap
()
(
goprocess
.
Process
,
error
)
{
func
(
dht
*
IpfsDHT
)
Bootstrap
(
ctx
context
.
Context
)
(
goprocess
.
Process
,
error
)
{
if
err
:=
dht
.
runBootstrap
(
dht
.
Context
()
,
DefaultBootstrapQueries
);
err
!=
nil
{
if
err
:=
dht
.
runBootstrap
(
ctx
,
DefaultBootstrapQueries
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -79,41 +80,32 @@ func (dht *IpfsDHT) BootstrapOnSignal(queries int, signal <-chan time.Time) (gop
...
@@ -79,41 +80,32 @@ func (dht *IpfsDHT) BootstrapOnSignal(queries int, signal <-chan time.Time) (gop
return
nil
,
fmt
.
Errorf
(
"invalid signal: %v"
,
signal
)
return
nil
,
fmt
.
Errorf
(
"invalid signal: %v"
,
signal
)
}
}
proc
:=
goprocess
.
Go
(
func
(
worker
goprocess
.
Process
)
{
proc
:=
periodicproc
.
Ticker
(
signal
,
func
(
worker
goprocess
.
Process
)
{
defer
log
.
Debug
(
"dht bootstrapper shutting down"
)
// it would be useful to be able to send out signals of when we bootstrap, too...
for
{
// maybe this is a good case for whole module event pub/sub?
select
{
case
<-
worker
.
Closing
()
:
ctx
:=
dht
.
Context
()
return
if
err
:=
dht
.
runBootstrap
(
ctx
,
queries
);
err
!=
nil
{
log
.
Error
(
err
)
case
<-
signal
:
// A bootstrapping error is important to notice but not fatal.
// it would be useful to be able to send out signals of when we bootstrap, too...
// maybe the client should be able to consume these errors,
// maybe this is a good case for whole module event pub/sub?
// though I dont have a clear use case in mind-- what **could**
// the client do if one of the bootstrap calls fails?
ctx
:=
dht
.
Context
()
//
if
err
:=
dht
.
runBootstrap
(
ctx
,
queries
);
err
!=
nil
{
// This is also related to the core's bootstrap failures.
log
.
Error
(
err
)
// superviseConnections should perhaps allow clients to detect
// A bootstrapping error is important to notice but not fatal.
// bootstrapping problems.
// maybe the client should be able to consume these errors,
//
// though I dont have a clear use case in mind-- what **could**
// Anyway, passing errors could be done with a bootstrapper object.
// the client do if one of the bootstrap calls fails?
// this would imply the client should be able to consume a lot of
//
// other non-fatal dht errors too. providing this functionality
// This is also related to the core's bootstrap failures.
// should be done correctly DHT-wide.
// superviseConnections should perhaps allow clients to detect
// NB: whatever the design, clients must ensure they drain errors!
// bootstrapping problems.
// This pattern is common to many things, perhaps long-running services
//
// should have something like an ErrStream that allows clients to consume
// Anyway, passing errors could be done with a bootstrapper object.
// periodic errors and take action. It should allow the user to also
// this would imply the client should be able to consume a lot of
// ignore all errors with something like an ErrStreamDiscard. We should
// other non-fatal dht errors too. providing this functionality
// study what other systems do for ideas.
// should be done correctly DHT-wide.
// NB: whatever the design, clients must ensure they drain errors!
// This pattern is common to many things, perhaps long-running services
// should have something like an ErrStream that allows clients to consume
// periodic errors and take action. It should allow the user to also
// ignore all errors with something like an ErrStreamDiscard. We should
// study what other systems do for ideas.
}
}
}
}
})
})
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论