From 4a5f5e2e2b1da51c56beebfdadc8e8669f6ff951 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Fri, 23 Jan 2015 04:36:32 -0800 Subject: [PATCH] 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 --- exchange/reprovide/reprovide.go | 5 ++++- pin/indirect.go | 2 +- routing/dht/dht_test.go | 12 ++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/exchange/reprovide/reprovide.go b/exchange/reprovide/reprovide.go index 4895e8ccb..1534b4ec4 100644 --- a/exchange/reprovide/reprovide.go +++ b/exchange/reprovide/reprovide.go @@ -30,7 +30,10 @@ func NewReprovider(rsys routing.IpfsRouting, bstore blocks.Blockstore) *Reprovid } func (rp *Reprovider) ProvideEvery(ctx context.Context, tick time.Duration) { - after := time.After(0) + // dont reprovide immediately. + // may have just started the daemon and shutting it down immediately. + // probability( up another minute | uptime ) increases with uptime. + after := time.After(time.Minute) for { select { case <-ctx.Done(): diff --git a/pin/indirect.go b/pin/indirect.go index 9e67bc2c9..09decbb25 100644 --- a/pin/indirect.go +++ b/pin/indirect.go @@ -32,7 +32,7 @@ func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) { keys = append(keys, k) refcnt[k] = v } - log.Debugf("indirPin keys: %#v", keys) + // log.Debugf("indirPin keys: %#v", keys) return &indirectPin{blockset: set.SimpleSetFromKeys(keys), refCounts: refcnt}, nil } diff --git a/routing/dht/dht_test.go b/routing/dht/dht_test.go index 2e1e1129f..b7b9faf71 100644 --- a/routing/dht/dht_test.go +++ b/routing/dht/dht_test.go @@ -82,10 +82,14 @@ func bootstrap(t *testing.T, ctx context.Context, dhts []*IpfsDHT) { // 100 sync https://gist.github.com/jbenet/6c59e7c15426e48aaedd // probably because results compound + var cfg BootstrapConfig + cfg = DefaultBootstrapConfig + cfg.Queries = 3 + start := rand.Intn(len(dhts)) // randomize to decrease bias. for i := range dhts { dht := dhts[(start+i)%len(dhts)] - dht.runBootstrap(ctx, 3) + dht.runBootstrap(ctx, cfg) } cancel() } @@ -356,11 +360,15 @@ func TestPeriodicBootstrap(t *testing.T) { signal := make(chan time.Time) allSignals := []chan time.Time{} + var cfg BootstrapConfig + cfg = DefaultBootstrapConfig + cfg.Queries = 5 + // kick off periodic bootstrappers with instrumented signals. for _, dht := range dhts { s := make(chan time.Time) allSignals = append(allSignals, s) - dht.BootstrapOnSignal(5, s) + dht.BootstrapOnSignal(cfg, s) } go amplify(signal, allSignals)