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
func (lm *LedgerManager) taskWorker() {
for {
nextTask := lm.tasklist.GetNext()
nextTask := lm.tasklist.Pop()
if nextTask == nil {
// No tasks in the list?
// Wait until there are!
......@@ -107,7 +107,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
lm.tasklist.Cancel(e.Key, p)
} else {
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!)
select {
......@@ -122,7 +122,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
l.ReceivedBytes(len(block.Data))
for _, l := range lm.ledgerMap {
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!)
select {
......
......@@ -25,9 +25,9 @@ type Task struct {
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
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 {
// TODO: when priority queue is implemented,
// rearrange this Task
......@@ -43,9 +43,9 @@ func (tl *TaskList) Add(block u.Key, priority int, to peer.Peer) {
tl.taskmap[to.Key()+block] = task
}
// GetNext returns the next task to be performed by bitswap
// the task is then removed from the list
func (tl *TaskList) GetNext() *Task {
// Pop returns the next task to be performed by bitswap the task is then
// removed from the list
func (tl *TaskList) Pop() *Task {
var out *Task
for len(tl.tasks) > 0 {
// 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