Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
b680f493
提交
b680f493
authored
5月 02, 2017
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix wantlist removal accounting, add tests
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
e43d1317
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
38 行增加
和
17 行删除
+38
-17
bitswap.go
exchange/bitswap/bitswap.go
+3
-0
bitswap_test.go
exchange/bitswap/bitswap_test.go
+5
-1
engine.go
exchange/bitswap/decision/engine.go
+4
-7
wantlist.go
exchange/bitswap/wantlist/wantlist.go
+1
-1
wantlist_test.go
exchange/bitswap/wantlist/wantlist_test.go
+25
-8
没有找到文件。
exchange/bitswap/bitswap.go
浏览文件 @
b680f493
...
...
@@ -285,6 +285,9 @@ func (bs *Bitswap) getNextSessionID() uint64 {
// CancelWant removes a given key from the wantlist
func
(
bs
*
Bitswap
)
CancelWants
(
cids
[]
*
cid
.
Cid
,
ses
uint64
)
{
if
len
(
cids
)
==
0
{
return
}
bs
.
wm
.
CancelWants
(
context
.
Background
(),
cids
,
nil
,
ses
)
}
...
...
exchange/bitswap/bitswap_test.go
浏览文件 @
b680f493
...
...
@@ -318,7 +318,7 @@ func TestBasicBitswap(t *testing.T) {
t
.
Log
(
"Test a one node trying to get one block from another"
)
instances
:=
sg
.
Instances
(
2
)
instances
:=
sg
.
Instances
(
3
)
blocks
:=
bg
.
Blocks
(
1
)
err
:=
instances
[
0
]
.
Exchange
.
HasBlock
(
blocks
[
0
])
if
err
!=
nil
{
...
...
@@ -333,6 +333,10 @@ func TestBasicBitswap(t *testing.T) {
}
time
.
Sleep
(
time
.
Millisecond
*
20
)
wl
:=
instances
[
2
]
.
Exchange
.
WantlistForPeer
(
instances
[
1
]
.
Peer
)
if
len
(
wl
)
!=
0
{
t
.
Fatal
(
"should have no items in other peers wantlist"
)
}
if
len
(
instances
[
1
]
.
Exchange
.
GetWantlist
())
!=
0
{
t
.
Fatal
(
"shouldnt have anything in wantlist"
)
}
...
...
exchange/bitswap/decision/engine.go
浏览文件 @
b680f493
...
...
@@ -105,13 +105,10 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
}
func
(
e
*
Engine
)
WantlistForPeer
(
p
peer
.
ID
)
(
out
[]
*
wl
.
Entry
)
{
e
.
lock
.
Lock
()
partner
,
ok
:=
e
.
ledgerMap
[
p
]
if
ok
{
out
=
partner
.
wantList
.
SortedEntries
()
}
e
.
lock
.
Unlock
()
return
out
partner
:=
e
.
findOrCreate
(
p
)
partner
.
lk
.
Lock
()
defer
partner
.
lk
.
Unlock
()
return
partner
.
wantList
.
SortedEntries
()
}
func
(
e
*
Engine
)
LedgerForPeer
(
p
peer
.
ID
)
*
Receipt
{
...
...
exchange/bitswap/wantlist/wantlist.go
浏览文件 @
b680f493
...
...
@@ -170,7 +170,7 @@ func (w *Wantlist) Remove(c *cid.Cid) bool {
}
delete
(
w
.
set
,
k
)
return
fals
e
return
tru
e
}
func
(
w
*
Wantlist
)
Contains
(
k
*
cid
.
Cid
)
(
*
Entry
,
bool
)
{
...
...
exchange/bitswap/wantlist/wantlist_test.go
浏览文件 @
b680f493
...
...
@@ -48,9 +48,13 @@ func assertNotHasCid(t *testing.T, w wli, c *cid.Cid) {
func
TestBasicWantlist
(
t
*
testing
.
T
)
{
wl
:=
New
()
wl
.
Add
(
testcids
[
0
],
5
)
if
!
wl
.
Add
(
testcids
[
0
],
5
)
{
t
.
Fatal
(
"expected true"
)
}
assertHasCid
(
t
,
wl
,
testcids
[
0
])
wl
.
Add
(
testcids
[
1
],
4
)
if
!
wl
.
Add
(
testcids
[
1
],
4
)
{
t
.
Fatal
(
"expected true"
)
}
assertHasCid
(
t
,
wl
,
testcids
[
0
])
assertHasCid
(
t
,
wl
,
testcids
[
1
])
...
...
@@ -58,7 +62,9 @@ func TestBasicWantlist(t *testing.T) {
t
.
Fatal
(
"should have had two items"
)
}
wl
.
Add
(
testcids
[
1
],
4
)
if
wl
.
Add
(
testcids
[
1
],
4
)
{
t
.
Fatal
(
"add shouldnt report success on second add"
)
}
assertHasCid
(
t
,
wl
,
testcids
[
0
])
assertHasCid
(
t
,
wl
,
testcids
[
1
])
...
...
@@ -66,7 +72,10 @@ func TestBasicWantlist(t *testing.T) {
t
.
Fatal
(
"should have had two items"
)
}
wl
.
Remove
(
testcids
[
0
])
if
!
wl
.
Remove
(
testcids
[
0
])
{
t
.
Fatal
(
"should have gotten true"
)
}
assertHasCid
(
t
,
wl
,
testcids
[
1
])
if
_
,
has
:=
wl
.
Contains
(
testcids
[
0
]);
has
{
t
.
Fatal
(
"shouldnt have this cid"
)
...
...
@@ -76,12 +85,20 @@ func TestBasicWantlist(t *testing.T) {
func
TestSesRefWantlist
(
t
*
testing
.
T
)
{
wl
:=
NewThreadSafe
()
wl
.
Add
(
testcids
[
0
],
5
,
1
)
if
!
wl
.
Add
(
testcids
[
0
],
5
,
1
)
{
t
.
Fatal
(
"should have added"
)
}
assertHasCid
(
t
,
wl
,
testcids
[
0
])
wl
.
Remove
(
testcids
[
0
],
2
)
if
wl
.
Remove
(
testcids
[
0
],
2
)
{
t
.
Fatal
(
"shouldnt have removed"
)
}
assertHasCid
(
t
,
wl
,
testcids
[
0
])
wl
.
Add
(
testcids
[
0
],
5
,
1
)
if
wl
.
Add
(
testcids
[
0
],
5
,
1
)
{
t
.
Fatal
(
"shouldnt have added"
)
}
assertHasCid
(
t
,
wl
,
testcids
[
0
])
wl
.
Remove
(
testcids
[
0
],
1
)
if
!
wl
.
Remove
(
testcids
[
0
],
1
)
{
t
.
Fatal
(
"should have removed"
)
}
assertNotHasCid
(
t
,
wl
,
testcids
[
0
])
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论