Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
3be5c913
提交
3be5c913
authored
7月 07, 2017
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix issue with sessions not receiving locally added blocks
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
124afdba
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
120 行增加
和
25 行删除
+120
-25
bitswap.go
exchange/bitswap/bitswap.go
+9
-1
session.go
exchange/bitswap/session.go
+71
-24
session_test.go
exchange/bitswap/session_test.go
+40
-0
没有找到文件。
exchange/bitswap/bitswap.go
浏览文件 @
3be5c913
...
...
@@ -317,6 +317,10 @@ func (bs *Bitswap) HasBlock(blk blocks.Block) error {
// it now as it requires more thought and isnt causing immediate problems.
bs
.
notifications
.
Publish
(
blk
)
for
_
,
s
:=
range
bs
.
SessionsForBlock
(
blk
.
Cid
())
{
s
.
receiveBlockFrom
(
""
,
blk
)
}
bs
.
engine
.
AddBlock
(
blk
)
select
{
...
...
@@ -370,7 +374,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
wg
:=
sync
.
WaitGroup
{}
for
_
,
block
:=
range
iblocks
{
wg
.
Add
(
1
)
go
func
(
b
blocks
.
Block
)
{
go
func
(
b
blocks
.
Block
)
{
// TODO: this probably doesnt need to be a goroutine...
defer
wg
.
Done
()
bs
.
updateReceiveCounters
(
b
)
...
...
@@ -382,7 +386,11 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
ses
.
receiveBlockFrom
(
p
,
b
)
bs
.
CancelWants
([]
*
cid
.
Cid
{
k
},
ses
.
id
)
}
log
.
Debugf
(
"got block %s from %s"
,
b
,
p
)
// TODO: rework this to not call 'HasBlock'. 'HasBlock' is really
// designed to be called when blocks are coming in from non-bitswap
// places (like the user manually adding data)
if
err
:=
bs
.
HasBlock
(
b
);
err
!=
nil
{
log
.
Warningf
(
"ReceiveMessage HasBlock error: %s"
,
err
)
}
...
...
exchange/bitswap/session.go
浏览文件 @
3be5c913
...
...
@@ -21,7 +21,7 @@ const activeWantsLimit = 16
// info to, and who to request blocks from
type
Session
struct
{
ctx
context
.
Context
tofetch
[]
*
cid
.
Cid
tofetch
*
cidQueue
activePeers
map
[
peer
.
ID
]
struct
{}
activePeersArr
[]
peer
.
ID
...
...
@@ -55,6 +55,7 @@ func (bs *Bitswap) NewSession(ctx context.Context) *Session {
liveWants
:
make
(
map
[
string
]
time
.
Time
),
newReqs
:
make
(
chan
[]
*
cid
.
Cid
),
cancelKeys
:
make
(
chan
[]
*
cid
.
Cid
),
tofetch
:
newCidQueue
(),
interestReqs
:
make
(
chan
interestReq
),
ctx
:
ctx
,
bs
:
bs
,
...
...
@@ -157,7 +158,9 @@ func (s *Session) run(ctx context.Context) {
s
.
wantBlocks
(
ctx
,
now
)
}
s
.
tofetch
=
append
(
s
.
tofetch
,
keys
...
)
for
_
,
k
:=
range
keys
{
s
.
tofetch
.
Push
(
k
)
}
case
keys
:=
<-
s
.
cancelKeys
:
s
.
cancel
(
keys
)
...
...
@@ -188,8 +191,7 @@ func (s *Session) run(ctx context.Context) {
case
p
:=
<-
newpeers
:
s
.
addActivePeer
(
p
)
case
lwchk
:=
<-
s
.
interestReqs
:
_
,
ok
:=
s
.
liveWants
[
lwchk
.
c
.
KeyString
()]
lwchk
.
resp
<-
ok
lwchk
.
resp
<-
s
.
cidIsWanted
(
lwchk
.
c
)
case
<-
ctx
.
Done
()
:
s
.
tick
.
Stop
()
return
...
...
@@ -197,19 +199,31 @@ func (s *Session) run(ctx context.Context) {
}
}
func
(
s
*
Session
)
cidIsWanted
(
c
*
cid
.
Cid
)
bool
{
_
,
ok
:=
s
.
liveWants
[
c
.
KeyString
()]
if
!
ok
{
ok
=
s
.
tofetch
.
Has
(
c
)
}
return
ok
}
func
(
s
*
Session
)
receiveBlock
(
ctx
context
.
Context
,
blk
blocks
.
Block
)
{
ks
:=
blk
.
Cid
()
.
KeyString
()
if
_
,
ok
:=
s
.
liveWants
[
ks
];
ok
{
tval
:=
s
.
liveWants
[
ks
]
s
.
latTotal
+=
time
.
Since
(
tval
)
c
:=
blk
.
Cid
()
if
s
.
cidIsWanted
(
c
)
{
ks
:=
c
.
KeyString
()
tval
,
ok
:=
s
.
liveWants
[
ks
]
if
ok
{
s
.
latTotal
+=
time
.
Since
(
tval
)
delete
(
s
.
liveWants
,
ks
)
}
else
{
s
.
tofetch
.
Remove
(
c
)
}
s
.
fetchcnt
++
delete
(
s
.
liveWants
,
ks
)
s
.
notif
.
Publish
(
blk
)
if
len
(
s
.
tofetch
)
>
0
{
next
:=
s
.
tofetch
[
0
:
1
]
s
.
tofetch
=
s
.
tofetch
[
1
:
]
s
.
wantBlocks
(
ctx
,
next
)
if
next
:=
s
.
tofetch
.
Pop
();
next
!=
nil
{
s
.
wantBlocks
(
ctx
,
[]
*
cid
.
Cid
{
next
})
}
}
}
...
...
@@ -222,19 +236,9 @@ func (s *Session) wantBlocks(ctx context.Context, ks []*cid.Cid) {
}
func
(
s
*
Session
)
cancel
(
keys
[]
*
cid
.
Cid
)
{
sset
:=
cid
.
NewSet
()
for
_
,
c
:=
range
keys
{
s
set
.
Add
(
c
)
s
.
tofetch
.
Remove
(
c
)
}
var
i
,
j
int
for
;
j
<
len
(
s
.
tofetch
);
j
++
{
if
sset
.
Has
(
s
.
tofetch
[
j
])
{
continue
}
s
.
tofetch
[
i
]
=
s
.
tofetch
[
j
]
i
++
}
s
.
tofetch
=
s
.
tofetch
[
:
i
]
}
func
(
s
*
Session
)
cancelWants
(
keys
[]
*
cid
.
Cid
)
{
...
...
@@ -260,3 +264,46 @@ func (s *Session) GetBlocks(ctx context.Context, keys []*cid.Cid) (<-chan blocks
func
(
s
*
Session
)
GetBlock
(
parent
context
.
Context
,
k
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
{
return
getBlock
(
parent
,
k
,
s
.
GetBlocks
)
}
type
cidQueue
struct
{
elems
[]
*
cid
.
Cid
eset
*
cid
.
Set
}
func
newCidQueue
()
*
cidQueue
{
return
&
cidQueue
{
eset
:
cid
.
NewSet
()}
}
func
(
cq
*
cidQueue
)
Pop
()
*
cid
.
Cid
{
for
{
if
len
(
cq
.
elems
)
==
0
{
return
nil
}
out
:=
cq
.
elems
[
0
]
cq
.
elems
=
cq
.
elems
[
1
:
]
if
cq
.
eset
.
Has
(
out
)
{
cq
.
eset
.
Remove
(
out
)
return
out
}
}
}
func
(
cq
*
cidQueue
)
Push
(
c
*
cid
.
Cid
)
{
if
cq
.
eset
.
Visit
(
c
)
{
cq
.
elems
=
append
(
cq
.
elems
,
c
)
}
}
func
(
cq
*
cidQueue
)
Remove
(
c
*
cid
.
Cid
)
{
cq
.
eset
.
Remove
(
c
)
}
func
(
cq
*
cidQueue
)
Has
(
c
*
cid
.
Cid
)
bool
{
return
cq
.
eset
.
Has
(
c
)
}
func
(
cq
*
cidQueue
)
Len
()
int
{
return
cq
.
eset
.
Len
()
}
exchange/bitswap/session_test.go
浏览文件 @
3be5c913
...
...
@@ -202,3 +202,43 @@ func TestInterestCacheOverflow(t *testing.T) {
t
.
Fatal
(
"timed out waiting for block"
)
}
}
func
TestPutAfterSessionCacheEvict
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
vnet
:=
getVirtualNetwork
()
sesgen
:=
NewTestSessionGenerator
(
vnet
)
defer
sesgen
.
Close
()
bgen
:=
blocksutil
.
NewBlockGenerator
()
blks
:=
bgen
.
Blocks
(
2500
)
inst
:=
sesgen
.
Instances
(
1
)
a
:=
inst
[
0
]
ses
:=
a
.
Exchange
.
NewSession
(
ctx
)
var
allcids
[]
*
cid
.
Cid
for
_
,
blk
:=
range
blks
[
1
:
]
{
allcids
=
append
(
allcids
,
blk
.
Cid
())
}
blkch
,
err
:=
ses
.
GetBlocks
(
ctx
,
allcids
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// wait to ensure that all the above cids were added to the sessions cache
time
.
Sleep
(
time
.
Millisecond
*
50
)
if
err
:=
a
.
Exchange
.
HasBlock
(
blks
[
17
]);
err
!=
nil
{
t
.
Fatal
(
err
)
}
select
{
case
<-
blkch
:
case
<-
time
.
After
(
time
.
Millisecond
*
50
)
:
t
.
Fatal
(
"timed out waiting for block"
)
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论