mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 22:49:13 +08:00
fix(bitswap/engine): get priority from wantlist
This commit is contained in:
@ -187,13 +187,12 @@ func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, block := range m.Blocks() {
|
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))
|
log.Debug("got block %s %d bytes", block.Key(), len(block.Data))
|
||||||
l.ReceivedBytes(len(block.Data))
|
l.ReceivedBytes(len(block.Data))
|
||||||
for _, l := range e.ledgerMap {
|
for _, l := range e.ledgerMap {
|
||||||
if l.WantListContains(block.Key()) {
|
if entry, ok := l.WantListContains(block.Key()); ok {
|
||||||
newWorkExists = true
|
newWorkExists = true
|
||||||
e.peerRequestQueue.Push(wl.Entry{block.Key(), 1}, l.Partner)
|
e.peerRequestQueue.Push(entry, l.Partner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func (l *ledger) CancelWant(k u.Key) {
|
|||||||
l.wantList.Remove(k)
|
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)
|
return l.wantList.Contains(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func (w *ThreadSafe) Remove(k u.Key) {
|
|||||||
w.Wantlist.Remove(k)
|
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
|
// TODO rm defer for perf
|
||||||
w.lk.RLock()
|
w.lk.RLock()
|
||||||
defer w.lk.RUnlock()
|
defer w.lk.RUnlock()
|
||||||
@ -88,9 +88,9 @@ func (w *Wantlist) Remove(k u.Key) {
|
|||||||
delete(w.set, k)
|
delete(w.set, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wantlist) Contains(k u.Key) bool {
|
func (w *Wantlist) Contains(k u.Key) (Entry, bool) {
|
||||||
_, ok := w.set[k]
|
e, ok := w.set[k]
|
||||||
return ok
|
return e, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wantlist) Entries() []Entry {
|
func (w *Wantlist) Entries() []Entry {
|
||||||
|
Reference in New Issue
Block a user