Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
738db201
提交
738db201
authored
4月 03, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some code cleanup and commenting
上级
d765c14e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
19 行增加
和
11 行删除
+19
-11
engine.go
exchange/bitswap/decision/engine.go
+0
-4
peer_request_queue.go
exchange/bitswap/decision/peer_request_queue.go
+19
-7
没有找到文件。
exchange/bitswap/decision/engine.go
浏览文件 @
738db201
...
...
@@ -55,9 +55,6 @@ 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
{
...
...
@@ -143,7 +140,6 @@ 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
浏览文件 @
738db201
...
...
@@ -27,6 +27,7 @@ func newPRQ() peerRequestQueue {
}
}
// verify interface implementation
var
_
peerRequestQueue
=
&
prq
{}
// TODO: at some point, the strategy needs to plug in here
...
...
@@ -81,12 +82,7 @@ func (tl *prq) Pop() *peerRequestTask {
if
tl
.
pQueue
.
Len
()
==
0
{
return
nil
}
pElem
:=
tl
.
pQueue
.
Pop
()
if
pElem
==
nil
{
return
nil
}
partner
:=
pElem
.
(
*
activePartner
)
partner
:=
tl
.
pQueue
.
Pop
()
.
(
*
activePartner
)
var
out
*
peerRequestTask
for
partner
.
taskQueue
.
Len
()
>
0
{
...
...
@@ -97,6 +93,8 @@ func (tl *prq) Pop() *peerRequestTask {
}
break
// and return |out|
}
// start the new task, and push the partner back onto the queue
partner
.
StartTask
()
partner
.
requests
--
tl
.
pQueue
.
Push
(
partner
)
...
...
@@ -112,6 +110,8 @@ func (tl *prq) Remove(k u.Key, p peer.ID) {
// simply mark it as trash, so it'll be dropped when popped off the
// queue.
t
.
trash
=
true
// having canceled a block, we now account for that in the given partner
tl
.
partners
[
p
]
.
requests
--
}
tl
.
lock
.
Unlock
()
...
...
@@ -121,6 +121,7 @@ type peerRequestTask struct {
Entry
wantlist
.
Entry
Target
peer
.
ID
// A callback to signal that this task has been completed
Done
func
()
// trash in a book-keeping field
...
...
@@ -135,10 +136,12 @@ func (t *peerRequestTask) Key() string {
return
taskKey
(
t
.
Target
,
t
.
Entry
.
Key
)
}
// Index implements pq.Elem
func
(
t
*
peerRequestTask
)
Index
()
int
{
return
t
.
index
}
// SetIndex implements pq.Elem
func
(
t
*
peerRequestTask
)
SetIndex
(
i
int
)
{
t
.
index
=
i
}
...
...
@@ -172,17 +175,22 @@ 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
// requests is the number of blocks this peer is currently requesting
// request need not be locked around as it will only be modified under
// the peerRequestQueue's locks
requests
int
// for the PQ interface
index
int
// priority queue of
// priority queue of
tasks belonging to this peer
taskQueue
pq
.
PQ
}
// partnerCompare implements pq.ElemComparator
func
partnerCompare
(
a
,
b
pq
.
Elem
)
bool
{
pa
:=
a
.
(
*
activePartner
)
pb
:=
b
.
(
*
activePartner
)
...
...
@@ -197,12 +205,14 @@ func partnerCompare(a, b pq.Elem) bool {
return
pa
.
active
<
pb
.
active
}
// StartTask signals that a task was started for this partner
func
(
p
*
activePartner
)
StartTask
()
{
p
.
lk
.
Lock
()
p
.
active
++
p
.
lk
.
Unlock
()
}
// TaskDone signals that a task was completed for this partner
func
(
p
*
activePartner
)
TaskDone
()
{
p
.
lk
.
Lock
()
p
.
active
--
...
...
@@ -212,10 +222,12 @@ func (p *activePartner) TaskDone() {
p
.
lk
.
Unlock
()
}
// Index implements pq.Elem
func
(
p
*
activePartner
)
Index
()
int
{
return
p
.
index
}
// SetIndex implements pq.Elem
func
(
p
*
activePartner
)
SetIndex
(
i
int
)
{
p
.
index
=
i
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论