reprovide: wait a minute before reproviding
Many times, a node will start up only to shut down immediately. In these cases, reproviding is costly to both the node, and the rest of the network. Also note: the probability of a node being up another minute increases with uptime. TODO: maybe this should be 5 * time.Minute
Juan Batiz-Benet committed
Jan 23, 2015 at 04:36 UTC
4a5f5e2e2b1da51c56beebfdadc8e8669f6ff951
3 files changed
+15
-4
exchange/reprovide/reprovide.go
+4
-1
@@ -30,7 +30,10 @@ func NewReprovider(rsys routing.IpfsRouting, bstore blocks.Blockstore) *Reprovid
30
}
31
32
func (rp *Reprovider) ProvideEvery(ctx context.Context, tick time.Duration) {
33
- after := time.After(0)
33
+ // dont reprovide immediately.
34
+ // may have just started the daemon and shutting it down immediately.
35
+ // probability( up another minute | uptime ) increases with uptime.
36
+ after := time.After(time.Minute)
37
for {
38
select {
39
case <-ctx.Done():
pin/indirect.go
+1
-1
@@ -32,7 +32,7 @@ func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) {
32
keys = append(keys, k)
33
refcnt[k] = v
34
}
35
- log.Debugf("indirPin keys: %#v", keys)
35
+ // log.Debugf("indirPin keys: %#v", keys)
36
37
return &indirectPin{blockset: set.SimpleSetFromKeys(keys), refCounts: refcnt}, nil
38
}
routing/dht/dht_test.go
+10
-2
@@ -82,10 +82,14 @@ func bootstrap(t *testing.T, ctx context.Context, dhts []*IpfsDHT) {
82
// 100 sync https://gist.github.com/jbenet/6c59e7c15426e48aaedd
83
// probably because results compound
84
85
+ var cfg BootstrapConfig
86
+ cfg = DefaultBootstrapConfig
87
+ cfg.Queries = 3
88
+
89
start := rand.Intn(len(dhts)) // randomize to decrease bias.
90
for i := range dhts {
91
dht := dhts[(start+i)%len(dhts)]
88
- dht.runBootstrap(ctx, 3)
92
+ dht.runBootstrap(ctx, cfg)
93
}
94
cancel()
95
}
@@ -356,11 +360,15 @@ func TestPeriodicBootstrap(t *testing.T) {
360
signal := make(chan time.Time)
361
allSignals := []chan time.Time{}
362
363
+ var cfg BootstrapConfig
364
+ cfg = DefaultBootstrapConfig
365
+ cfg.Queries = 5
366
+
367
// kick off periodic bootstrappers with instrumented signals.
368
for _, dht := range dhts {
369
s := make(chan time.Time)
370
allSignals = append(allSignals, s)
363
- dht.BootstrapOnSignal(5, s)
371
+ dht.BootstrapOnSignal(cfg, s)
372
}
373
go amplify(signal, allSignals)
374