Commit 297ff3d4 authored by Jeromy's avatar Jeromy

randomize rebroadcast target

parent 19da0570
......@@ -3,6 +3,7 @@
package bitswap
import (
"math/rand"
"time"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
......@@ -96,7 +97,6 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
log.Event(ctx, "GetBlockRequestBegin", &k)
defer log.Event(ctx, "GetBlockRequestEnd", &k)
bs.wantlist.Add(k)
promise := bs.notifications.Subscribe(ctx, k)
select {
......@@ -171,17 +171,22 @@ func (bs *bitswap) run(ctx context.Context) {
if len(wantlist) == 0 {
continue
}
providers := bs.routing.FindProvidersAsync(ctx, wantlist[0], maxProvidersPerRequest)
n := rand.Intn(len(wantlist))
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:
// TODO: implement batching on len(ks) > X for some X
if len(ks) == 0 {
log.Warning("Received batch request for zero blocks")
continue
}
for _, k := range ks {
bs.wantlist.Add(k)
}
providers := bs.routing.FindProvidersAsync(ctx, ks[0], maxProvidersPerRequest)
err := bs.sendWantListTo(ctx, providers)
......
......@@ -34,6 +34,5 @@ type Strategy interface {
// Values determining bitswap behavioural patterns
GetBatchSize() int
GetBatchDelay() time.Duration
GetRebroadcastDelay() time.Duration
}
......@@ -145,10 +145,6 @@ func (s *strategist) GetBatchSize() int {
return 10
}
func (s *strategist) GetBatchDelay() time.Duration {
return time.Millisecond * 3
}
func (s *strategist) GetRebroadcastDelay() time.Duration {
return time.Second * 2
}
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