1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 09:52:20 +08:00

fix(bitswap/engine): get priority from wantlist

This commit is contained in:
Brian Tiger Chow
2015-01-04 17:58:01 -05:00
parent 6a580e50d3
commit d61ce41516
3 changed files with 7 additions and 8 deletions

View File

@ -187,13 +187,12 @@ func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error {
}
for _, block := range m.Blocks() {
// FIXME extract blocks.NumBytes(block) or block.NumBytes() method
log.Debug("got block %s %d bytes", block.Key(), len(block.Data))
l.ReceivedBytes(len(block.Data))
for _, l := range e.ledgerMap {
if l.WantListContains(block.Key()) {
if entry, ok := l.WantListContains(block.Key()); ok {
newWorkExists = true
e.peerRequestQueue.Push(wl.Entry{block.Key(), 1}, l.Partner)
e.peerRequestQueue.Push(entry, l.Partner)
}
}
}

View File

@ -77,7 +77,7 @@ func (l *ledger) CancelWant(k u.Key) {
l.wantList.Remove(k)
}
func (l *ledger) WantListContains(k u.Key) bool {
func (l *ledger) WantListContains(k u.Key) (wl.Entry, bool) {
return l.wantList.Contains(k)
}

View File

@ -55,7 +55,7 @@ func (w *ThreadSafe) Remove(k u.Key) {
w.Wantlist.Remove(k)
}
func (w *ThreadSafe) Contains(k u.Key) bool {
func (w *ThreadSafe) Contains(k u.Key) (Entry, bool) {
// TODO rm defer for perf
w.lk.RLock()
defer w.lk.RUnlock()
@ -88,9 +88,9 @@ func (w *Wantlist) Remove(k u.Key) {
delete(w.set, k)
}
func (w *Wantlist) Contains(k u.Key) bool {
_, ok := w.set[k]
return ok
func (w *Wantlist) Contains(k u.Key) (Entry, bool) {
e, ok := w.set[k]
return e, ok
}
func (w *Wantlist) Entries() []Entry {