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

refactor: separate responsibilties

Before, priority carried two pieces of information.

One: priority as defined by remote peer
Two: whether task is trashed

This assumes the protocol is defined for natural numbers instead of
integers. That may not always be the case. Better to leave that
assumption outside so this package isn't coupled to the whims of the
protocol.

The protocol may be changed to allow any integer value to be used.
Hopefully by that time, new responsibilties weren't added to the
Priority variable.

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 02fca42a
......@@ -23,6 +23,7 @@ func newTaskQueue() *taskQueue {
type task struct {
Entry wantlist.Entry
Target peer.Peer
Trash bool
}
// Push currently adds a new task to the end of the list
......@@ -55,12 +56,11 @@ func (tl *taskQueue) Pop() *task {
out = tl.tasks[0]
tl.tasks = tl.tasks[1:]
delete(tl.taskmap, taskKey(out.Target, out.Entry.Key))
// Filter out blocks that have been cancelled
if out.Entry.Priority >= 0 { // FIXME separate the "cancel" signal from priority
break
if out.Trash {
continue // discarding tasks that have been removed
}
break // and return |out|
}
return out
}
......@@ -68,7 +68,7 @@ func (tl *taskQueue) Pop() *task {
func (tl *taskQueue) Remove(k u.Key, p peer.Peer) {
t, ok := tl.taskmap[taskKey(p, k)]
if ok {
t.Entry.Priority = -1
t.Trash = true
}
}
......
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