Commit 297ff3d4 authored by Jeromy's avatar Jeromy

randomize rebroadcast target

parent 19da0570
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
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"
...@@ -96,7 +97,6 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err ...@@ -96,7 +97,6 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
log.Event(ctx, "GetBlockRequestBegin", &k) log.Event(ctx, "GetBlockRequestBegin", &k)
defer log.Event(ctx, "GetBlockRequestEnd", &k) defer log.Event(ctx, "GetBlockRequestEnd", &k)
bs.wantlist.Add(k)
promise := bs.notifications.Subscribe(ctx, k) promise := bs.notifications.Subscribe(ctx, k)
select { select {
...@@ -171,17 +171,22 @@ func (bs *bitswap) run(ctx context.Context) { ...@@ -171,17 +171,22 @@ func (bs *bitswap) run(ctx context.Context) {
if len(wantlist) == 0 { if len(wantlist) == 0 {
continue 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) err := bs.sendWantListTo(ctx, providers)
if err != nil { if err != nil {
log.Errorf("error sending wantlist: %s", err) 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
if len(ks) == 0 { if len(ks) == 0 {
log.Warning("Received batch request for zero blocks") log.Warning("Received batch request for zero blocks")
continue continue
} }
for _, k := range ks {
bs.wantlist.Add(k)
}
providers := bs.routing.FindProvidersAsync(ctx, ks[0], maxProvidersPerRequest) providers := bs.routing.FindProvidersAsync(ctx, ks[0], maxProvidersPerRequest)
err := bs.sendWantListTo(ctx, providers) err := bs.sendWantListTo(ctx, providers)
......
...@@ -34,6 +34,5 @@ type Strategy interface { ...@@ -34,6 +34,5 @@ type Strategy interface {
// Values determining bitswap behavioural patterns // Values determining bitswap behavioural patterns
GetBatchSize() int GetBatchSize() int
GetBatchDelay() time.Duration
GetRebroadcastDelay() time.Duration GetRebroadcastDelay() time.Duration
} }
...@@ -145,10 +145,6 @@ func (s *strategist) GetBatchSize() int { ...@@ -145,10 +145,6 @@ func (s *strategist) GetBatchSize() int {
return 10 return 10
} }
func (s *strategist) GetBatchDelay() time.Duration {
return time.Millisecond * 3
}
func (s *strategist) GetRebroadcastDelay() time.Duration { func (s *strategist) GetRebroadcastDelay() time.Duration {
return time.Second * 2 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