Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
198aa195
提交
198aa195
authored
12月 16, 2014
作者:
Brian Tiger Chow
提交者:
Juan Batiz-Benet
12月 17, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
it's not a queue yet but it's okay to name it as such
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
上级
7280aac8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
15 行删除
+15
-15
ledgermanager.go
exchange/bitswap/strategy/ledgermanager.go
+9
-9
taskqueue.go
exchange/bitswap/strategy/taskqueue.go
+6
-6
没有找到文件。
exchange/bitswap/strategy/ledgermanager.go
浏览文件 @
198aa195
...
...
@@ -26,9 +26,9 @@ type LedgerManager struct {
lock
sync
.
RWMutex
ledgerMap
ledgerMap
bs
bstore
.
Blockstore
// FIXME task
list
isn't threadsafe nor is it protected by a mutex. consider
// a way to avoid sharing the task
list
between the worker and the receiver
task
list
*
taskList
// FIXME task
queue
isn't threadsafe nor is it protected by a mutex. consider
// a way to avoid sharing the task
queue
between the worker and the receiver
task
queue
*
taskQueue
outbox
chan
Envelope
workSignal
chan
struct
{}
}
...
...
@@ -37,7 +37,7 @@ func NewLedgerManager(ctx context.Context, bs bstore.Blockstore) *LedgerManager
lm
:=
&
LedgerManager
{
ledgerMap
:
make
(
ledgerMap
),
bs
:
bs
,
task
list
:
newTaskList
(),
task
queue
:
newTaskQueue
(),
outbox
:
make
(
chan
Envelope
,
4
),
// TODO extract constant
workSignal
:
make
(
chan
struct
{}),
}
...
...
@@ -47,7 +47,7 @@ func NewLedgerManager(ctx context.Context, bs bstore.Blockstore) *LedgerManager
func
(
lm
*
LedgerManager
)
taskWorker
(
ctx
context
.
Context
)
{
for
{
nextTask
:=
lm
.
task
list
.
Pop
()
nextTask
:=
lm
.
task
queue
.
Pop
()
if
nextTask
==
nil
{
// No tasks in the list?
// Wait until there are!
...
...
@@ -124,11 +124,11 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
for
_
,
e
:=
range
m
.
Wantlist
()
{
if
e
.
Cancel
{
l
.
CancelWant
(
e
.
Key
)
lm
.
task
list
.
Cancel
(
e
.
Key
,
p
)
lm
.
task
queue
.
Cancel
(
e
.
Key
,
p
)
}
else
{
l
.
Wants
(
e
.
Key
,
e
.
Priority
)
newWorkExists
=
true
lm
.
task
list
.
Push
(
e
.
Key
,
e
.
Priority
,
p
)
lm
.
task
queue
.
Push
(
e
.
Key
,
e
.
Priority
,
p
)
}
}
...
...
@@ -138,7 +138,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
for
_
,
l
:=
range
lm
.
ledgerMap
{
if
l
.
WantListContains
(
block
.
Key
())
{
newWorkExists
=
true
lm
.
task
list
.
Push
(
block
.
Key
(),
1
,
l
.
Partner
)
lm
.
task
queue
.
Push
(
block
.
Key
(),
1
,
l
.
Partner
)
}
}
}
...
...
@@ -159,7 +159,7 @@ func (lm *LedgerManager) MessageSent(p peer.Peer, m bsmsg.BitSwapMessage) error
for
_
,
block
:=
range
m
.
Blocks
()
{
l
.
SentBytes
(
len
(
block
.
Data
))
l
.
wantList
.
Remove
(
block
.
Key
())
lm
.
task
list
.
Cancel
(
block
.
Key
(),
p
)
lm
.
task
queue
.
Cancel
(
block
.
Key
(),
p
)
}
return
nil
...
...
exchange/bitswap/strategy/task
list
.go
→
exchange/bitswap/strategy/task
queue
.go
浏览文件 @
198aa195
...
...
@@ -8,13 +8,13 @@ import (
// TODO: at some point, the strategy needs to plug in here
// to help decide how to sort tasks (on add) and how to select
// tasks (on getnext). For now, we are assuming a dumb/nice strategy.
type
task
List
struct
{
type
task
Queue
struct
{
tasks
[]
*
Task
taskmap
map
[
string
]
*
Task
}
func
newTask
List
()
*
taskList
{
return
&
task
List
{
func
newTask
Queue
()
*
taskQueue
{
return
&
task
Queue
{
taskmap
:
make
(
map
[
string
]
*
Task
),
}
}
...
...
@@ -27,7 +27,7 @@ type Task struct {
// Push currently adds a new task to the end of the list
// TODO: make this into a priority queue
func
(
tl
*
task
List
)
Push
(
block
u
.
Key
,
priority
int
,
to
peer
.
Peer
)
{
func
(
tl
*
task
Queue
)
Push
(
block
u
.
Key
,
priority
int
,
to
peer
.
Peer
)
{
if
task
,
ok
:=
tl
.
taskmap
[
taskKey
(
to
,
block
)];
ok
{
// TODO: when priority queue is implemented,
// rearrange this Task
...
...
@@ -44,7 +44,7 @@ func (tl *taskList) Push(block u.Key, priority int, to peer.Peer) {
}
// Pop 'pops' the next task to be performed. Returns nil no task exists.
func
(
tl
*
task
List
)
Pop
()
*
Task
{
func
(
tl
*
task
Queue
)
Pop
()
*
Task
{
var
out
*
Task
for
len
(
tl
.
tasks
)
>
0
{
// TODO: instead of zero, use exponential distribution
...
...
@@ -63,7 +63,7 @@ func (tl *taskList) Pop() *Task {
}
// Cancel lazily cancels the sending of a block to a given peer
func
(
tl
*
task
List
)
Cancel
(
k
u
.
Key
,
p
peer
.
Peer
)
{
func
(
tl
*
task
Queue
)
Cancel
(
k
u
.
Key
,
p
peer
.
Peer
)
{
t
,
ok
:=
tl
.
taskmap
[
taskKey
(
p
,
k
)]
if
ok
{
t
.
theirPriority
=
-
1
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论