Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
400a1aec
提交
400a1aec
authored
2月 09, 2016
作者:
Jeromy Johnson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2316 from ipfs/fix/random-bstest-hangs
wait for peers in wantmanager to all appear
上级
eaa4ff0c
c73da848
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
2 行删除
+29
-2
bitswap_test.go
exchange/bitswap/bitswap_test.go
+13
-0
wantmanager.go
exchange/bitswap/wantmanager.go
+16
-2
没有找到文件。
exchange/bitswap/bitswap_test.go
浏览文件 @
400a1aec
...
...
@@ -158,6 +158,19 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
t
.
Log
(
"Give the blocks to the first instance"
)
nump
:=
len
(
instances
)
-
1
// assert we're properly connected
for
_
,
inst
:=
range
instances
{
peers
:=
inst
.
Exchange
.
wm
.
ConnectedPeers
()
for
i
:=
0
;
i
<
10
&&
len
(
peers
)
!=
nump
;
i
++
{
time
.
Sleep
(
time
.
Millisecond
*
50
)
peers
=
inst
.
Exchange
.
wm
.
ConnectedPeers
()
}
if
len
(
peers
)
!=
nump
{
t
.
Fatal
(
"not enough peers connected to instance"
)
}
}
var
blkeys
[]
key
.
Key
first
:=
instances
[
0
]
for
_
,
b
:=
range
blocks
{
...
...
exchange/bitswap/wantmanager.go
浏览文件 @
400a1aec
...
...
@@ -16,8 +16,9 @@ import (
type
WantManager
struct
{
// sync channels for Run loop
incoming
chan
[]
*
bsmsg
.
Entry
connect
chan
peer
.
ID
// notification channel for new peers connecting
disconnect
chan
peer
.
ID
// notification channel for peers disconnecting
connect
chan
peer
.
ID
// notification channel for new peers connecting
disconnect
chan
peer
.
ID
// notification channel for peers disconnecting
peerReqs
chan
chan
[]
peer
.
ID
// channel to request connected peers on
// synchronized by Run loop, only touch inside there
peers
map
[
peer
.
ID
]
*
msgQueue
...
...
@@ -32,6 +33,7 @@ func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantMana
incoming
:
make
(
chan
[]
*
bsmsg
.
Entry
,
10
),
connect
:
make
(
chan
peer
.
ID
,
10
),
disconnect
:
make
(
chan
peer
.
ID
,
10
),
peerReqs
:
make
(
chan
chan
[]
peer
.
ID
),
peers
:
make
(
map
[
peer
.
ID
]
*
msgQueue
),
wl
:
wantlist
.
NewThreadSafe
(),
network
:
network
,
...
...
@@ -88,6 +90,12 @@ func (pm *WantManager) addEntries(ks []key.Key, cancel bool) {
}
}
func
(
pm
*
WantManager
)
ConnectedPeers
()
[]
peer
.
ID
{
resp
:=
make
(
chan
[]
peer
.
ID
)
pm
.
peerReqs
<-
resp
return
<-
resp
}
func
(
pm
*
WantManager
)
SendBlock
(
ctx
context
.
Context
,
env
*
engine
.
Envelope
)
{
// Blocks need to be sent synchronously to maintain proper backpressure
// throughout the network stack
...
...
@@ -242,6 +250,12 @@ func (pm *WantManager) Run() {
pm
.
startPeerHandler
(
p
)
case
p
:=
<-
pm
.
disconnect
:
pm
.
stopPeerHandler
(
p
)
case
req
:=
<-
pm
.
peerReqs
:
var
peers
[]
peer
.
ID
for
p
:=
range
pm
.
peers
{
peers
=
append
(
peers
,
p
)
}
req
<-
peers
case
<-
pm
.
ctx
.
Done
()
:
return
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论