@cryptotaxi247 / kubo / commits / 1bced710b

queue-like naming

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Dec 15, 2014 at 22:46 UTC 1bced710b15636654c8fcc34975ac743d29f54be
2 files changed +8 -8
exchange/bitswap/strategy/ledgermanager.go
+3 -3
@@ -45,7 +45,7 @@ func NewLedgerManager(bs bstore.Blockstore, ctx context.Context) *LedgerManager
45
46 func (lm *LedgerManager) taskWorker() {
47 for {
48 - nextTask := lm.tasklist.GetNext()
48 + nextTask := lm.tasklist.Pop()
49 if nextTask == nil {
50 // No tasks in the list?
51 // Wait until there are!
@@ -107,7 +107,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
107 lm.tasklist.Cancel(e.Key, p)
108 } else {
109 l.Wants(e.Key, e.Priority)
110 - lm.tasklist.Add(e.Key, e.Priority, p)
110 + lm.tasklist.Push(e.Key, e.Priority, p)
111
112 // Signal task generation to restart (if stopped!)
113 select {
@@ -122,7 +122,7 @@ func (lm *LedgerManager) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) er
122 l.ReceivedBytes(len(block.Data))
123 for _, l := range lm.ledgerMap {
124 if l.WantListContains(block.Key()) {
125 - lm.tasklist.Add(block.Key(), 1, l.Partner)
125 + lm.tasklist.Push(block.Key(), 1, l.Partner)
126
127 // Signal task generation to restart (if stopped!)
128 select {
exchange/bitswap/strategy/tasklist.go
+5 -5
@@ -25,9 +25,9 @@ type Task struct {
25 theirPriority int
26 }
27
28 -// Add currently adds a new task to the end of the list
28 +// Push currently adds a new task to the end of the list
29 // TODO: make this into a priority queue
30 -func (tl *TaskList) Add(block u.Key, priority int, to peer.Peer) {
30 +func (tl *TaskList) Push(block u.Key, priority int, to peer.Peer) {
31 if task, ok := tl.taskmap[to.Key()+block]; ok {
32 // TODO: when priority queue is implemented,
33 // rearrange this Task
@@ -43,9 +43,9 @@ func (tl *TaskList) Add(block u.Key, priority int, to peer.Peer) {
43 tl.taskmap[to.Key()+block] = task
44 }
45
46 -// GetNext returns the next task to be performed by bitswap
47 -// the task is then removed from the list
48 -func (tl *TaskList) GetNext() *Task {
46 +// Pop returns the next task to be performed by bitswap the task is then
47 +// removed from the list
48 +func (tl *TaskList) Pop() *Task {
49 var out *Task
50 for len(tl.tasks) > 0 {
51 // TODO: instead of zero, use exponential distribution