Commit cc677a40 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

privatize Task

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 404ac1d2
...@@ -9,17 +9,17 @@ import ( ...@@ -9,17 +9,17 @@ import (
// to help decide how to sort tasks (on add) and how to select // 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. // tasks (on getnext). For now, we are assuming a dumb/nice strategy.
type taskQueue struct { type taskQueue struct {
tasks []*Task tasks []*task
taskmap map[string]*Task taskmap map[string]*task
} }
func newTaskQueue() *taskQueue { func newTaskQueue() *taskQueue {
return &taskQueue{ return &taskQueue{
taskmap: make(map[string]*Task), taskmap: make(map[string]*task),
} }
} }
type Task struct { type task struct {
Key u.Key Key u.Key
Target peer.Peer Target peer.Peer
theirPriority int theirPriority int
...@@ -30,11 +30,11 @@ type Task struct { ...@@ -30,11 +30,11 @@ type Task struct {
func (tl *taskQueue) Push(block u.Key, priority int, to peer.Peer) { func (tl *taskQueue) Push(block u.Key, priority int, to peer.Peer) {
if task, ok := tl.taskmap[taskKey(to, block)]; ok { if task, ok := tl.taskmap[taskKey(to, block)]; ok {
// TODO: when priority queue is implemented, // TODO: when priority queue is implemented,
// rearrange this Task // rearrange this task
task.theirPriority = priority task.theirPriority = priority
return return
} }
task := &Task{ task := &task{
Key: block, Key: block,
Target: to, Target: to,
theirPriority: priority, theirPriority: priority,
...@@ -44,8 +44,8 @@ func (tl *taskQueue) Push(block u.Key, priority int, to peer.Peer) { ...@@ -44,8 +44,8 @@ func (tl *taskQueue) Push(block u.Key, priority int, to peer.Peer) {
} }
// Pop 'pops' the next task to be performed. Returns nil no task exists. // Pop 'pops' the next task to be performed. Returns nil no task exists.
func (tl *taskQueue) Pop() *Task { func (tl *taskQueue) Pop() *task {
var out *Task var out *task
for len(tl.tasks) > 0 { for len(tl.tasks) > 0 {
// TODO: instead of zero, use exponential distribution // TODO: instead of zero, use exponential distribution
// it will help reduce the chance of receiving // it will help reduce the chance of receiving
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment