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

queue-like naming

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 7071ef57
...@@ -45,7 +45,7 @@ func NewLedgerManager(bs bstore.Blockstore, ctx context.Context) *LedgerManager ...@@ -45,7 +45,7 @@ func NewLedgerManager(bs bstore.Blockstore, ctx context.Context) *LedgerManager
func (lm *LedgerManager) taskWorker() { func (lm *LedgerManager) taskWorker() {
for { for {
nextTask := lm.tasklist.GetNext() nextTask := lm.tasklist.Pop()
if nextTask == nil { if nextTask == nil {
// No tasks in the list? // No tasks in the list?
// Wait until there are! // Wait until there are!
...@@ -107,7 +107,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er ...@@ -107,7 +107,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
lm.tasklist.Cancel(e.Key, p) lm.tasklist.Cancel(e.Key, p)
} else { } else {
l.Wants(e.Key, e.Priority) l.Wants(e.Key, e.Priority)
lm.tasklist.Add(e.Key, e.Priority, p) lm.tasklist.Push(e.Key, e.Priority, p)
// Signal task generation to restart (if stopped!) // Signal task generation to restart (if stopped!)
select { select {
...@@ -122,7 +122,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er ...@@ -122,7 +122,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
l.ReceivedBytes(len(block.Data)) l.ReceivedBytes(len(block.Data))
for _, l := range lm.ledgerMap { for _, l := range lm.ledgerMap {
if l.WantListContains(block.Key()) { if l.WantListContains(block.Key()) {
lm.tasklist.Add(block.Key(), 1, l.Partner) lm.tasklist.Push(block.Key(), 1, l.Partner)
// Signal task generation to restart (if stopped!) // Signal task generation to restart (if stopped!)
select { select {
......
...@@ -25,9 +25,9 @@ type Task struct { ...@@ -25,9 +25,9 @@ type Task struct {
theirPriority int theirPriority int
} }
// Add 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) Add(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[to.Key()+block]; ok { if task, ok := tl.taskmap[to.Key()+block]; ok {
// TODO: when priority queue is implemented, // TODO: when priority queue is implemented,
// rearrange this Task // rearrange this Task
...@@ -43,9 +43,9 @@ func (tl *TaskList) Add(block u.Key, priority int, to peer.Peer) { ...@@ -43,9 +43,9 @@ func (tl *TaskList) Add(block u.Key, priority int, to peer.Peer) {
tl.taskmap[to.Key()+block] = task tl.taskmap[to.Key()+block] = task
} }
// GetNext returns the next task to be performed by bitswap // Pop returns the next task to be performed by bitswap the task is then
// the task is then removed from the list // removed from the list
func (tl *TaskList) GetNext() *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
......
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