mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +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() {
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user