@cryptotaxi247 / kubo / commits / acc714823

rename to peerRequestQueue

this opens up the possibility of having multiple queues. And for all outgoing messages to be managed by the decision engine License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Dec 16, 2014 at 23:07 UTC acc714823b300cfc3e08fcbcb2e69bbc8fb06714
1 file changed +14 -13
exchange/bitswap/decision/engine.go
+14 -13
@@ -22,9 +22,10 @@ type Envelope struct {
22 }
23
24 type Engine struct {
25 - // FIXME taskqueue isn't threadsafe nor is it protected by a mutex. consider
26 - // a way to avoid sharing the taskqueue between the worker and the receiver
27 - taskqueue *taskQueue
25 + // FIXME peerRequestQueue isn't threadsafe nor is it protected by a mutex.
26 + // consider a way to avoid sharing the peerRequestQueue between the worker
27 + // and the receiver
28 + peerRequestQueue *taskQueue
29
30 workSignal chan struct{}
31
@@ -39,11 +40,11 @@ type Engine struct {
40
41 func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
42 e := &Engine{
42 - ledgerMap: make(map[u.Key]*ledger),
43 - bs: bs,
44 - taskqueue: newTaskQueue(),
45 - outbox: make(chan Envelope, 4), // TODO extract constant
46 - workSignal: make(chan struct{}),
43 + ledgerMap: make(map[u.Key]*ledger),
44 + bs: bs,
45 + peerRequestQueue: newTaskQueue(),
46 + outbox: make(chan Envelope, 4), // TODO extract constant
47 + workSignal: make(chan struct{}),
48 }
49 go e.taskWorker(ctx)
50 return e
@@ -51,7 +52,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
52
53 func (e *Engine) taskWorker(ctx context.Context) {
54 for {
54 - nextTask := e.taskqueue.Pop()
55 + nextTask := e.peerRequestQueue.Pop()
56 if nextTask == nil {
57 // No tasks in the list?
58 // Wait until there are!
@@ -128,11 +129,11 @@ func (e *Engine) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) error {
129 for _, entry := range m.Wantlist() {
130 if entry.Cancel {
131 l.CancelWant(entry.Key)
131 - e.taskqueue.Remove(entry.Key, p)
132 + e.peerRequestQueue.Remove(entry.Key, p)
133 } else {
134 l.Wants(entry.Key, entry.Priority)
135 newWorkExists = true
135 - e.taskqueue.Push(entry.Key, entry.Priority, p)
136 + e.peerRequestQueue.Push(entry.Key, entry.Priority, p)
137 }
138 }
139
@@ -142,7 +143,7 @@ func (e *Engine) MessageReceived(p peer.Peer, m bsmsg.BitSwapMessage) error {
143 for _, l := range e.ledgerMap {
144 if l.WantListContains(block.Key()) {
145 newWorkExists = true
145 - e.taskqueue.Push(block.Key(), 1, l.Partner)
146 + e.peerRequestQueue.Push(block.Key(), 1, l.Partner)
147 }
148 }
149 }
@@ -163,7 +164,7 @@ func (e *Engine) MessageSent(p peer.Peer, m bsmsg.BitSwapMessage) error {
164 for _, block := range m.Blocks() {
165 l.SentBytes(len(block.Data))
166 l.wantList.Remove(block.Key())
166 - e.taskqueue.Remove(block.Key(), p)
167 + e.peerRequestQueue.Remove(block.Key(), p)
168 }
169
170 return nil