privatize Task
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Dec 16, 2014 at 21:43 UTC
e11f099c4230e165471a1369b0d132e7bc56f94c
1 file changed
+8
-8
exchange/bitswap/strategy/taskqueue.go
+8
-8
@@ -9,17 +9,17 @@ import (
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 taskQueue struct {
12
- tasks []*Task
13
- taskmap map[string]*Task
12
+ tasks []*task
13
+ taskmap map[string]*task
14
}
15
16
func newTaskQueue() *taskQueue {
17
return &taskQueue{
18
- taskmap: make(map[string]*Task),
18
+ taskmap: make(map[string]*task),
19
}
20
}
21
22
-type Task struct {
22
+type task struct {
23
Key u.Key
24
Target peer.Peer
25
theirPriority int
@@ -30,11 +30,11 @@ type Task struct {
30
func (tl *taskQueue) 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
33
+ // rearrange this task
34
task.theirPriority = priority
35
return
36
}
37
- task := &Task{
37
+ task := &task{
38
Key: block,
39
Target: to,
40
theirPriority: priority,
@@ -44,8 +44,8 @@ func (tl *taskQueue) 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 *taskQueue) Pop() *Task {
48
- var out *Task
47
+func (tl *taskQueue) Pop() *task {
48
+ var out *task
49
for len(tl.tasks) > 0 {
50
// TODO: instead of zero, use exponential distribution
51
// it will help reduce the chance of receiving