Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
8443b99c
提交
8443b99c
authored
5月 12, 2015
作者:
Jeromy
提交者:
Juan Batiz-Benet
5月 21, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update comments and reintroduce test
上级
a159e682
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
40 行增加
和
13 行删除
+40
-13
bitswap_test.go
exchange/bitswap/bitswap_test.go
+23
-0
peermanager.go
exchange/bitswap/peermanager.go
+17
-13
没有找到文件。
exchange/bitswap/bitswap_test.go
浏览文件 @
8443b99c
...
...
@@ -13,6 +13,7 @@ import (
blocks
"github.com/ipfs/go-ipfs/blocks"
blocksutil
"github.com/ipfs/go-ipfs/blocks/blocksutil"
tn
"github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
p2ptestutil
"github.com/ipfs/go-ipfs/p2p/test/util"
mockrouting
"github.com/ipfs/go-ipfs/routing/mock"
delay
"github.com/ipfs/go-ipfs/thirdparty/delay"
u
"github.com/ipfs/go-ipfs/util"
...
...
@@ -35,6 +36,28 @@ func TestClose(t *testing.T) {
bitswap
.
Exchange
.
GetBlock
(
context
.
Background
(),
block
.
Key
())
}
func
TestProviderForKeyButNetworkCannotFind
(
t
*
testing
.
T
)
{
// TODO revisit this
rs
:=
mockrouting
.
NewServer
()
net
:=
tn
.
VirtualNetwork
(
rs
,
delay
.
Fixed
(
kNetworkDelay
))
g
:=
NewTestSessionGenerator
(
net
)
defer
g
.
Close
()
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
))
pinfo
:=
p2ptestutil
.
RandTestBogusIdentityOrFatal
(
t
)
rs
.
Client
(
pinfo
)
.
Provide
(
context
.
Background
(),
block
.
Key
())
// but not on network
solo
:=
g
.
Next
()
defer
solo
.
Exchange
.
Close
()
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Nanosecond
)
_
,
err
:=
solo
.
Exchange
.
GetBlock
(
ctx
,
block
.
Key
())
if
err
!=
context
.
DeadlineExceeded
{
t
.
Fatal
(
"Expected DeadlineExceeded error"
)
}
}
func
TestGetBlockFromPeerAfterPeerAnnounces
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
kNetworkDelay
))
...
...
exchange/bitswap/peermanager.go
浏览文件 @
8443b99c
...
...
@@ -46,8 +46,8 @@ type cancellation struct {
type
msgQueue
struct
{
p
peer
.
ID
lk
sync
.
Mutex
wlmsg
bsmsg
.
BitSwapMessage
outlk
sync
.
Mutex
out
bsmsg
.
BitSwapMessage
work
chan
struct
{}
done
chan
struct
{}
...
...
@@ -106,11 +106,11 @@ func (pm *PeerManager) runQueue(mq *msgQueue) {
// TODO: cant connect, what now?
}
// grab
messages from queu
e
mq
.
lk
.
Lock
()
wlm
:=
mq
.
wlmsg
mq
.
wlmsg
=
nil
mq
.
lk
.
Unlock
()
// grab
outgoin messag
e
mq
.
out
lk
.
Lock
()
wlm
:=
mq
.
out
mq
.
out
=
nil
mq
.
out
lk
.
Unlock
()
if
wlm
!=
nil
&&
!
wlm
.
Empty
()
{
// send wantlist updates
...
...
@@ -178,26 +178,30 @@ func (pm *PeerManager) Run(ctx context.Context) {
}
func
(
mq
*
msgQueue
)
addMessage
(
msg
bsmsg
.
BitSwapMessage
)
{
mq
.
lk
.
Lock
()
mq
.
out
lk
.
Lock
()
defer
func
()
{
mq
.
lk
.
Unlock
()
mq
.
out
lk
.
Unlock
()
select
{
case
mq
.
work
<-
struct
{}{}
:
default
:
}
}()
if
mq
.
wlmsg
==
nil
||
msg
.
Full
()
{
mq
.
wlmsg
=
msg
// if we have no message held, or the one we are given is full
// overwrite the one we are holding
if
mq
.
out
==
nil
||
msg
.
Full
()
{
mq
.
out
=
msg
return
}
// TODO: add a msg.Combine(...) method
// otherwise, combine the one we are holding with the
// one passed in
for
_
,
e
:=
range
msg
.
Wantlist
()
{
if
e
.
Cancel
{
mq
.
wlmsg
.
Cancel
(
e
.
Key
)
mq
.
out
.
Cancel
(
e
.
Key
)
}
else
{
mq
.
wlmsg
.
AddEntry
(
e
.
Key
,
e
.
Priority
)
mq
.
out
.
AddEntry
(
e
.
Key
,
e
.
Priority
)
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论