@cryptotaxi247 / kubo / commits / 7fdbae130

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: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Dec 16, 2014 at 22:12 UTC 7fdbae1306652b375a16cc58ba5fd1be4a8112f6
1 file changed +5 -5
exchange/bitswap/strategy/taskqueue.go
+5 -5
@@ -23,6 +23,7 @@ func newTaskQueue() *taskQueue {
23 type task struct {
24 Entry wantlist.Entry
25 Target peer.Peer
26 + Trash bool
27 }
28
29 // Push currently adds a new task to the end of the list
@@ -55,12 +56,11 @@ func (tl *taskQueue) Pop() *task {
56 out = tl.tasks[0]
57 tl.tasks = tl.tasks[1:]
58 delete(tl.taskmap, taskKey(out.Target, out.Entry.Key))
58 - // Filter out blocks that have been cancelled
59 - if out.Entry.Priority >= 0 { // FIXME separate the "cancel" signal from priority
60 - break
59 + if out.Trash {
60 + continue // discarding tasks that have been removed
61 }
62 + break // and return |out|
63 }
63 -
64 return out
65 }
66
@@ -68,7 +68,7 @@ func (tl *taskQueue) Pop() *task {
68 func (tl *taskQueue) Remove(k u.Key, p peer.Peer) {
69 t, ok := tl.taskmap[taskKey(p, k)]
70 if ok {
71 - t.Entry.Priority = -1
71 + t.Trash = true
72 }
73 }
74