Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
8450a8d4
提交
8450a8d4
authored
4月 03, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
address comments from CR
上级
76e879c9
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
25 行增加
和
11 行删除
+25
-11
engine.go
exchange/bitswap/decision/engine.go
+7
-0
peer_request_queue.go
exchange/bitswap/decision/peer_request_queue.go
+7
-6
peer_request_queue_test.go
exchange/bitswap/decision/peer_request_queue_test.go
+10
-5
workers.go
exchange/bitswap/workers.go
+1
-0
没有找到文件。
exchange/bitswap/decision/engine.go
浏览文件 @
8450a8d4
...
...
@@ -55,6 +55,9 @@ type Envelope struct {
Peer
peer
.
ID
// Message is the payload
Message
bsmsg
.
BitSwapMessage
// A callback to notify the decision queue that the task is complete
Sent
func
()
}
type
Engine
struct
{
...
...
@@ -132,6 +135,9 @@ func (e *Engine) nextEnvelope(ctx context.Context) (*Envelope, error) {
block
,
err
:=
e
.
bs
.
Get
(
nextTask
.
Entry
.
Key
)
if
err
!=
nil
{
// If we don't have the block, don't hold that against the peer
// make sure to update that the task has been 'completed'
nextTask
.
Done
()
continue
}
...
...
@@ -140,6 +146,7 @@ func (e *Engine) nextEnvelope(ctx context.Context) (*Envelope, error) {
return
&
Envelope
{
Peer
:
nextTask
.
Target
,
Message
:
m
,
Sent
:
nextTask
.
Done
,
},
nil
}
}
...
...
exchange/bitswap/decision/peer_request_queue.go
浏览文件 @
8450a8d4
...
...
@@ -173,11 +173,11 @@ func wrapCmp(f func(a, b *peerRequestTask) bool) func(a, b pq.Elem) bool {
}
type
activePartner
struct
{
lk
sync
.
Mutex
// Active is the number of blocks this peer is currently being sent
// active must be locked around as it will be updated externally
active
int
activelk
sync
.
Mutex
active
int
// requests is the number of blocks this peer is currently requesting
// request need not be locked around as it will only be modified under
...
...
@@ -197,6 +197,7 @@ func partnerCompare(a, b pq.Elem) bool {
pb
:=
b
.
(
*
activePartner
)
// having no blocks in their wantlist means lowest priority
// having both of these checks ensures stability of the sort
if
pa
.
requests
==
0
{
return
false
}
...
...
@@ -208,19 +209,19 @@ func partnerCompare(a, b pq.Elem) bool {
// StartTask signals that a task was started for this partner
func
(
p
*
activePartner
)
StartTask
()
{
p
.
lk
.
Lock
()
p
.
active
lk
.
Lock
()
p
.
active
++
p
.
lk
.
Unlock
()
p
.
active
lk
.
Unlock
()
}
// TaskDone signals that a task was completed for this partner
func
(
p
*
activePartner
)
TaskDone
()
{
p
.
lk
.
Lock
()
p
.
active
lk
.
Lock
()
p
.
active
--
if
p
.
active
<
0
{
panic
(
"more tasks finished than started!"
)
}
p
.
lk
.
Unlock
()
p
.
active
lk
.
Unlock
()
}
// Index implements pq.Elem
...
...
exchange/bitswap/decision/peer_request_queue_test.go
浏览文件 @
8450a8d4
...
...
@@ -105,10 +105,15 @@ func TestPeerRepeats(t *testing.T) {
// Now, if one of the tasks gets finished, the next task off the queue should
// be for the same peer
tasks
[
0
]
.
Done
()
ntask
:=
prq
.
Pop
()
if
ntask
.
Target
!=
tasks
[
0
]
.
Target
{
t
.
Fatal
(
"Expected task from peer with lowest active count"
)
for
blockI
:=
0
;
blockI
<
4
;
blockI
++
{
for
i
:=
0
;
i
<
4
;
i
++
{
// its okay to mark the same task done multiple times here (JUST FOR TESTING)
tasks
[
i
]
.
Done
()
ntask
:=
prq
.
Pop
()
if
ntask
.
Target
!=
tasks
[
i
]
.
Target
{
t
.
Fatal
(
"Expected task from peer with lowest active count"
)
}
}
}
}
exchange/bitswap/workers.go
浏览文件 @
8450a8d4
...
...
@@ -51,6 +51,7 @@ func (bs *Bitswap) taskWorker(ctx context.Context) {
}
log
.
Event
(
ctx
,
"deliverBlocks"
,
envelope
.
Message
,
envelope
.
Peer
)
bs
.
send
(
ctx
,
envelope
.
Peer
,
envelope
.
Message
)
envelope
.
Sent
()
case
<-
ctx
.
Done
()
:
return
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论