@cryptotaxi247 / kubo / commits / d61ce4151

fix(bitswap/engine): get priority from wantlist

Brian Tiger Chow committed Jan 4, 2015 at 17:58 UTC d61ce415160f4fe3b81d66ffb8a9af4cdf5482c0
3 files changed +7 -8
exchange/bitswap/decision/engine.go
+2 -3
@@ -187,13 +187,12 @@ func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error {
187 }
188
189 for _, block := range m.Blocks() {
190 - // FIXME extract blocks.NumBytes(block) or block.NumBytes() method
190 log.Debug("got block %s %d bytes", block.Key(), len(block.Data))
191 l.ReceivedBytes(len(block.Data))
192 for _, l := range e.ledgerMap {
194 - if l.WantListContains(block.Key()) {
193 + if entry, ok := l.WantListContains(block.Key()); ok {
194 newWorkExists = true
196 - e.peerRequestQueue.Push(wl.Entry{block.Key(), 1}, l.Partner)
195 + e.peerRequestQueue.Push(entry, l.Partner)
196 }
197 }
198 }
exchange/bitswap/decision/ledger.go
+1 -1
@@ -77,7 +77,7 @@ func (l *ledger) CancelWant(k u.Key) {
77 l.wantList.Remove(k)
78 }
79
80 -func (l *ledger) WantListContains(k u.Key) bool {
80 +func (l *ledger) WantListContains(k u.Key) (wl.Entry, bool) {
81 return l.wantList.Contains(k)
82 }
83
exchange/bitswap/wantlist/wantlist.go
+4 -4
@@ -55,7 +55,7 @@ func (w *ThreadSafe) Remove(k u.Key) {
55 w.Wantlist.Remove(k)
56 }
57
58 -func (w *ThreadSafe) Contains(k u.Key) bool {
58 +func (w *ThreadSafe) Contains(k u.Key) (Entry, bool) {
59 // TODO rm defer for perf
60 w.lk.RLock()
61 defer w.lk.RUnlock()
@@ -88,9 +88,9 @@ func (w *Wantlist) Remove(k u.Key) {
88 delete(w.set, k)
89 }
90
91 -func (w *Wantlist) Contains(k u.Key) bool {
92 - _, ok := w.set[k]
93 - return ok
91 +func (w *Wantlist) Contains(k u.Key) (Entry, bool) {
92 + e, ok := w.set[k]
93 + return e, ok
94 }
95
96 func (w *Wantlist) Entries() []Entry {