randomize rebroadcast target
Jeromy committed
Nov 20, 2014 at 06:16 UTC
297ff3d4b24f553865e61b6788085dc33e3127b1
3 files changed
+7
-7
exchange/bitswap/bitswap.go
+7
-2
@@ -3,6 +3,7 @@
3
package bitswap
4
5
import (
6
+ "math/rand"
7
"time"
8
9
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
97
log.Event(ctx, "GetBlockRequestBegin", &k)
98
defer log.Event(ctx, "GetBlockRequestEnd", &k)
99
99
- bs.wantlist.Add(k)
100
promise := bs.notifications.Subscribe(ctx, k)
101
102
select {
@@ -171,17 +171,22 @@ func (bs *bitswap) run(ctx context.Context) {
171
if len(wantlist) == 0 {
172
continue
173
}
174
- providers := bs.routing.FindProvidersAsync(ctx, wantlist[0], maxProvidersPerRequest)
174
+ n := rand.Intn(len(wantlist))
175
+ providers := bs.routing.FindProvidersAsync(ctx, wantlist[n], maxProvidersPerRequest)
176
177
err := bs.sendWantListTo(ctx, providers)
178
if err != nil {
179
log.Errorf("error sending wantlist: %s", err)
180
}
181
case ks := <-bs.batchRequests:
182
+ // TODO: implement batching on len(ks) > X for some X
183
if len(ks) == 0 {
184
log.Warning("Received batch request for zero blocks")
185
continue
186
}
187
+ for _, k := range ks {
188
+ bs.wantlist.Add(k)
189
+ }
190
providers := bs.routing.FindProvidersAsync(ctx, ks[0], maxProvidersPerRequest)
191
192
err := bs.sendWantListTo(ctx, providers)
exchange/bitswap/strategy/interface.go
-1
@@ -34,6 +34,5 @@ type Strategy interface {
34
35
// Values determining bitswap behavioural patterns
36
GetBatchSize() int
37
- GetBatchDelay() time.Duration
37
GetRebroadcastDelay() time.Duration
38
}
exchange/bitswap/strategy/strategy.go
-4
@@ -145,10 +145,6 @@ func (s *strategist) GetBatchSize() int {
145
return 10
146
}
147
148
-func (s *strategist) GetBatchDelay() time.Duration {
149
- return time.Millisecond * 3
150
-}
151
-
148
func (s *strategist) GetRebroadcastDelay() time.Duration {
149
return time.Second * 2
150
}