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

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: default avatarBrian Tiger Chow <brian@perfmode.com>
parent e84b37a7
...@@ -28,7 +28,7 @@ type LedgerManager struct { ...@@ -28,7 +28,7 @@ type LedgerManager struct {
lock sync.RWMutex lock sync.RWMutex
ledgerMap ledgerMap ledgerMap ledgerMap
bs bstore.Blockstore bs bstore.Blockstore
tasklist *TaskList tasklist *taskList
outbox chan Envelope outbox chan Envelope
workSignal chan struct{} workSignal chan struct{}
} }
...@@ -37,7 +37,7 @@ func NewLedgerManager(ctx context.Context, bs bstore.Blockstore) *LedgerManager ...@@ -37,7 +37,7 @@ func NewLedgerManager(ctx context.Context, bs bstore.Blockstore) *LedgerManager
lm := &LedgerManager{ lm := &LedgerManager{
ledgerMap: make(ledgerMap), ledgerMap: make(ledgerMap),
bs: bs, bs: bs,
tasklist: NewTaskList(), tasklist: newTaskList(),
outbox: make(chan Envelope, 4), // TODO extract constant outbox: make(chan Envelope, 4), // TODO extract constant
workSignal: make(chan struct{}), workSignal: make(chan struct{}),
} }
......
...@@ -8,13 +8,13 @@ import ( ...@@ -8,13 +8,13 @@ import (
// TODO: at some point, the strategy needs to plug in here // TODO: at some point, the strategy needs to plug in here
// 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 TaskList struct { type taskList struct {
tasks []*Task tasks []*Task
taskmap map[string]*Task taskmap map[string]*Task
} }
func NewTaskList() *TaskList { func newTaskList() *taskList {
return &TaskList{ return &taskList{
taskmap: make(map[string]*Task), taskmap: make(map[string]*Task),
} }
} }
...@@ -27,7 +27,7 @@ type Task struct { ...@@ -27,7 +27,7 @@ type Task struct {
// Push currently adds a new task to the end of the list // Push currently adds a new task to the end of the list
// TODO: make this into a priority queue // TODO: make this into a priority queue
func (tl *TaskList) Push(block u.Key, priority int, to peer.Peer) { func (tl *taskList) 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
...@@ -44,7 +44,7 @@ func (tl *TaskList) Push(block u.Key, priority int, to peer.Peer) { ...@@ -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. // Pop 'pops' the next task to be performed. Returns nil no task exists.
func (tl *TaskList) Pop() *Task { func (tl *taskList) 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
...@@ -63,7 +63,7 @@ func (tl *TaskList) Pop() *Task { ...@@ -63,7 +63,7 @@ func (tl *TaskList) Pop() *Task {
} }
// Cancel lazily cancels the sending of a block to a given peer // Cancel lazily cancels the sending of a block to a given peer
func (tl *TaskList) Cancel(k u.Key, p peer.Peer) { func (tl *taskList) Cancel(k u.Key, p peer.Peer) {
t, ok := tl.taskmap[taskKey(p, k)] t, ok := tl.taskmap[taskKey(p, k)]
if ok { if ok {
t.theirPriority = -1 t.theirPriority = -1
......
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