Commit 36ebde35 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Jeromy

feat(bitswap) find providers for all keys on wantlist

@jbenet @whyrusleeping

this addresses a failure case where

1) bitswap wants blocks A and B
2) partner 1 has A and partner 2 has B
3) We choose a key at random, drawing A.
4) Then, we request A, neglecting to find a provider for B.

Sending the full wantlist is meant to be used as a helpful additional
piece of data, but...

unless our hunch is support by statistical inference at runtime,
it's not safe to assume that a peer will have blocks for related keys.
Routing must be the source of truth.

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 6af9f417
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
package bitswap package bitswap
import ( import (
"math/rand"
"time" "time"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...@@ -175,16 +174,12 @@ func (bs *bitswap) run(ctx context.Context) { ...@@ -175,16 +174,12 @@ func (bs *bitswap) run(ctx context.Context) {
for { for {
select { select {
case <-broadcastSignal.C: case <-broadcastSignal.C:
wantlist := bs.wantlist.Keys() for _, k := range bs.wantlist.Keys() {
if len(wantlist) == 0 { providers := bs.routing.FindProvidersAsync(ctx, k, maxProvidersPerRequest)
continue err := bs.sendWantListTo(ctx, providers)
} if err != nil {
n := rand.Intn(len(wantlist)) log.Errorf("error sending wantlist: %s", err)
providers := bs.routing.FindProvidersAsync(ctx, wantlist[n], maxProvidersPerRequest) }
err := bs.sendWantListTo(ctx, providers)
if err != nil {
log.Errorf("error sending wantlist: %s", err)
} }
case ks := <-bs.batchRequests: case ks := <-bs.batchRequests:
// TODO: implement batching on len(ks) > X for some X // TODO: implement batching on len(ks) > X for some X
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment