unexport task and taskList
the less bitswap has to know about, the easier it'll be for readers. (This now returns Messages.) License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Dec 16, 2014 at 21:06 UTC
286723d8882142dea2fc63bc391038ed4d0d176b
2 files changed
+8
-8
exchange/bitswap/strategy/ledgermanager.go
+2
-2
@@ -28,7 +28,7 @@ type LedgerManager struct {
28
lock sync.RWMutex
29
ledgerMap ledgerMap
30
bs bstore.Blockstore
31
- tasklist *TaskList
31
+ tasklist *taskList
32
outbox chan Envelope
33
workSignal chan struct{}
34
}
@@ -37,7 +37,7 @@ func NewLedgerManager(ctx context.Context, bs bstore.Blockstore) *LedgerManager
37
lm := &LedgerManager{
38
ledgerMap: make(ledgerMap),
39
bs: bs,
40
- tasklist: NewTaskList(),
40
+ tasklist: newTaskList(),
41
outbox: make(chan Envelope, 4), // TODO extract constant
42
workSignal: make(chan struct{}),
43
}
exchange/bitswap/strategy/tasklist.go
+6
-6
@@ -8,13 +8,13 @@ import (
8
// TODO: at some point, the strategy needs to plug in here
9
// to help decide how to sort tasks (on add) and how to select
10
// tasks (on getnext). For now, we are assuming a dumb/nice strategy.
11
-type TaskList struct {
11
+type taskList struct {
12
tasks []*Task
13
taskmap map[string]*Task
14
}
15
16
-func NewTaskList() *TaskList {
17
- return &TaskList{
16
+func newTaskList() *taskList {
17
+ return &taskList{
18
taskmap: make(map[string]*Task),
19
}
20
}
@@ -27,7 +27,7 @@ type Task struct {
27
28
// Push currently adds a new task to the end of the list
29
// TODO: make this into a priority queue
30
-func (tl *TaskList) Push(block u.Key, priority int, to peer.Peer) {
30
+func (tl *taskList) Push(block u.Key, priority int, to peer.Peer) {
31
if task, ok := tl.taskmap[taskKey(to, block)]; ok {
32
// TODO: when priority queue is implemented,
33
// rearrange this Task
@@ -44,7 +44,7 @@ func (tl *TaskList) Push(block u.Key, priority int, to peer.Peer) {
44
}
45
46
// Pop 'pops' the next task to be performed. Returns nil no task exists.
47
-func (tl *TaskList) Pop() *Task {
47
+func (tl *taskList) Pop() *Task {
48
var out *Task
49
for len(tl.tasks) > 0 {
50
// TODO: instead of zero, use exponential distribution
@@ -63,7 +63,7 @@ func (tl *TaskList) Pop() *Task {
63
}
64
65
// Cancel lazily cancels the sending of a block to a given peer
66
-func (tl *TaskList) Cancel(k u.Key, p peer.Peer) {
66
+func (tl *taskList) Cancel(k u.Key, p peer.Peer) {
67
t, ok := tl.taskmap[taskKey(p, k)]
68
if ok {
69
t.theirPriority = -1