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

refactor(bs/decision.Engine): pass in Entry

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent fa030d66
......@@ -129,7 +129,7 @@ func (e *Engine) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) error {
l.Wants(entry.Key, entry.Priority)
if exists, err := e.bs.Has(entry.Key); err == nil && exists {
newWorkExists = true
e.peerRequestQueue.Push(entry.Key, entry.Priority, p)
e.peerRequestQueue.Push(entry.Entry, p)
}
}
}
......@@ -140,7 +140,7 @@ func (e *Engine) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) error {
for _, l := range e.ledgerMap {
if l.WantListContains(block.Key()) {
newWorkExists = true
e.peerRequestQueue.Push(block.Key(), 1, l.Partner)
e.peerRequestQueue.Push(wl.Entry{block.Key(), 1}, l.Partner)
}
}
}
......
......@@ -28,22 +28,19 @@ type task struct {
}
// Push currently adds a new task to the end of the list
func (tl *taskQueue) Push(block u.Key, priority int, to peer.Peer) {
if task, ok := tl.taskmap[taskKey(to, block)]; ok {
func (tl *taskQueue) Push(entry wantlist.Entry, to peer.Peer) {
if task, ok := tl.taskmap[taskKey(to, entry.Key)]; ok {
// TODO: when priority queue is implemented,
// rearrange this task
task.Entry.Priority = priority
task.Entry.Priority = entry.Priority
return
}
task := &task{
Entry: wantlist.Entry{
Key: block,
Priority: priority,
},
Entry: entry,
Target: to,
}
tl.tasks = append(tl.tasks, task)
tl.taskmap[taskKey(to, block)] = task
tl.taskmap[taskKey(to, entry.Key)] = task
}
// Pop 'pops' the next task to be performed. Returns nil no task exists.
......
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