Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
7952d95b
提交
7952d95b
authored
12月 18, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added bootstrap logging
上级
4c13b958
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
43 行增加
和
4 行删除
+43
-4
bootstrap.go
core/bootstrap.go
+34
-2
net.go
net/net.go
+4
-2
dht.go
routing/dht/dht.go
+5
-0
没有找到文件。
core/bootstrap.go
浏览文件 @
7952d95b
package
core
import
(
"errors"
"fmt"
"math/rand"
"sync"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
config
"github.com/jbenet/go-ipfs/config"
inet
"github.com/jbenet/go-ipfs/net"
peer
"github.com/jbenet/go-ipfs/peer"
dht
"github.com/jbenet/go-ipfs/routing/dht"
lgbl
"github.com/jbenet/go-ipfs/util/eventlog/loggables"
math2
"github.com/jbenet/go-ipfs/util/math2"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
)
const
(
...
...
@@ -50,14 +54,23 @@ func bootstrap(ctx context.Context,
connectedPeers
:=
n
.
Peers
()
if
len
(
connectedPeers
)
>=
recoveryThreshold
{
log
.
Event
(
ctx
,
"bootstrapSkip"
,
n
.
LocalPeer
())
log
.
Debugf
(
"%s bootstrap skipped -- connected to %d (> %d) nodes"
,
n
.
LocalPeer
(),
len
(
connectedPeers
),
recoveryThreshold
)
return
nil
}
numCxnsToCreate
:=
recoveryThreshold
-
len
(
connectedPeers
)
log
.
Event
(
ctx
,
"bootstrapStart"
,
n
.
LocalPeer
())
log
.
Debugf
(
"%s bootstrapping to %d more nodes"
,
n
.
LocalPeer
(),
numCxnsToCreate
)
var
bootstrapPeers
[]
peer
.
PeerInfo
for
_
,
bootstrap
:=
range
boots
{
p
,
err
:=
toPeer
(
bootstrap
)
if
err
!=
nil
{
log
.
Event
(
ctx
,
"bootstrapError"
,
n
.
LocalPeer
(),
lgbl
.
Error
(
err
))
log
.
Errorf
(
"%s bootstrap error: %s"
,
n
.
LocalPeer
(),
err
)
return
err
}
bootstrapPeers
=
append
(
bootstrapPeers
,
p
)
...
...
@@ -70,14 +83,30 @@ func bootstrap(ctx context.Context,
}
}
if
len
(
notConnected
)
<
1
{
s
:=
"must bootstrap to %d more nodes, but already connected to all candidates"
err
:=
fmt
.
Errorf
(
s
,
numCxnsToCreate
)
log
.
Event
(
ctx
,
"bootstrapError"
,
n
.
LocalPeer
(),
lgbl
.
Error
(
err
))
log
.
Errorf
(
"%s bootstrap error: %s"
,
n
.
LocalPeer
(),
err
)
return
err
}
var
randomSubset
=
randomSubsetOfPeers
(
notConnected
,
numCxnsToCreate
)
log
.
Debugf
(
"%s bootstrapping to %d nodes: %s"
,
n
.
LocalPeer
(),
numCxnsToCreate
,
randomSubset
)
if
err
:=
connect
(
ctx
,
ps
,
r
,
randomSubset
);
err
!=
nil
{
log
.
Event
(
ctx
,
"bootstrapError"
,
n
.
LocalPeer
(),
lgbl
.
Error
(
err
))
log
.
Errorf
(
"%s bootstrap error: %s"
,
n
.
LocalPeer
(),
err
)
return
err
}
return
nil
}
func
connect
(
ctx
context
.
Context
,
ps
peer
.
Peerstore
,
r
*
dht
.
IpfsDHT
,
peers
[]
peer
.
PeerInfo
)
error
{
if
len
(
peers
)
<
1
{
return
errors
.
New
(
"bootstrap set empty"
)
}
var
wg
sync
.
WaitGroup
for
_
,
p
:=
range
peers
{
...
...
@@ -88,6 +117,9 @@ func connect(ctx context.Context, ps peer.Peerstore, r *dht.IpfsDHT, peers []pee
wg
.
Add
(
1
)
go
func
(
p
peer
.
PeerInfo
)
{
defer
wg
.
Done
()
log
.
Event
(
ctx
,
"bootstrapDial"
,
r
.
LocalPeer
(),
p
.
ID
)
log
.
Debugf
(
"%s bootstrapping to %s"
,
r
.
LocalPeer
(),
p
.
ID
)
ps
.
AddAddresses
(
p
.
ID
,
p
.
Addrs
)
err
:=
r
.
Connect
(
ctx
,
p
.
ID
)
if
err
!=
nil
{
...
...
net/net.go
浏览文件 @
7952d95b
...
...
@@ -135,6 +135,7 @@ func (n *network) newConnHandler(c *swarm.Conn) {
// DialPeer attempts to establish a connection to a given peer.
// Respects the context.
func
(
n
*
network
)
DialPeer
(
ctx
context
.
Context
,
p
peer
.
ID
)
error
{
log
.
Debugf
(
"[%s] network dialing peer [%s]"
,
n
.
local
,
p
)
sc
,
err
:=
n
.
swarm
.
Dial
(
ctx
,
p
)
if
err
!=
nil
{
return
err
...
...
@@ -242,8 +243,9 @@ func (n *network) Connectedness(p peer.ID) Connectedness {
// NewStream returns a new stream to given peer p.
// If there is no connection to p, attempts to create one.
// If ProtocolID is "", writes no header.
func
(
c
*
network
)
NewStream
(
pr
ProtocolID
,
p
peer
.
ID
)
(
Stream
,
error
)
{
s
,
err
:=
c
.
swarm
.
NewStreamWithPeer
(
p
)
func
(
n
*
network
)
NewStream
(
pr
ProtocolID
,
p
peer
.
ID
)
(
Stream
,
error
)
{
log
.
Debugf
(
"[%s] network opening stream to peer [%s]: %s"
,
n
.
local
,
p
,
pr
)
s
,
err
:=
n
.
swarm
.
NewStreamWithPeer
(
p
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
routing/dht/dht.go
浏览文件 @
7952d95b
...
...
@@ -77,6 +77,11 @@ func NewDHT(ctx context.Context, p peer.ID, n inet.Network, dstore ds.ThreadSafe
return
dht
}
// LocalPeer returns the peer.Peer of the dht.
func
(
dht
*
IpfsDHT
)
LocalPeer
()
peer
.
ID
{
return
dht
.
self
}
// Connect to a new peer at the given address, ping and add to the routing table
func
(
dht
*
IpfsDHT
)
Connect
(
ctx
context
.
Context
,
npeer
peer
.
ID
)
error
{
if
err
:=
dht
.
network
.
DialPeer
(
ctx
,
npeer
);
err
!=
nil
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论