From 23ed4e6789dcfcdf8c922be6b2674bf7019ca146 Mon Sep 17 00:00:00 2001 From: Cole Brown Date: Fri, 29 Jun 2018 12:32:09 -0400 Subject: [PATCH 1/5] Bootstrap immediately after calls to BootstrapWithConfig --- dht_bootstrap.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/dht_bootstrap.go b/dht_bootstrap.go index 14c4bd6b6..e40ee074a 100644 --- a/dht_bootstrap.go +++ b/dht_bootstrap.go @@ -77,7 +77,25 @@ func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process, return nil, fmt.Errorf("invalid number of queries: %d", cfg.Queries) } - proc := periodicproc.Tick(cfg.Period, dht.bootstrapWorker(cfg)) + tickch := make(chan struct{}, 1) + proc := periodicproc.OnSignal(tickch, dht.bootstrapWorker(cfg)) + go func() { + tickch <- struct{}{} + for { + select { + case <-time.After(cfg.Period): + select { + case tickch <- struct{}{}: + default: + // Don't queue ticks, like Tickers + log.Warning("Previous bootstrapping attempt not completed within bootstrapping period") + continue + } + case <-dht.Context().Done(): + return + } + } + }() return proc, nil } From 52d4e6a955d7d2d3841caac7a73d7f2e87fef295 Mon Sep 17 00:00:00 2001 From: Cole Brown Date: Fri, 29 Jun 2018 12:37:55 -0400 Subject: [PATCH 2/5] Remove redundant continue --- dht_bootstrap.go | 1 - 1 file changed, 1 deletion(-) diff --git a/dht_bootstrap.go b/dht_bootstrap.go index e40ee074a..0585298dd 100644 --- a/dht_bootstrap.go +++ b/dht_bootstrap.go @@ -89,7 +89,6 @@ func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process, default: // Don't queue ticks, like Tickers log.Warning("Previous bootstrapping attempt not completed within bootstrapping period") - continue } case <-dht.Context().Done(): return From a49b5489b9b4b2b2c5dd716d214934a70875489e Mon Sep 17 00:00:00 2001 From: Cole Brown Date: Mon, 2 Jul 2018 11:18:47 -0400 Subject: [PATCH 3/5] Use Process.Go() for bootstrap routine --- dht_bootstrap.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dht_bootstrap.go b/dht_bootstrap.go index 0585298dd..c3be1b450 100644 --- a/dht_bootstrap.go +++ b/dht_bootstrap.go @@ -77,24 +77,30 @@ func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process, return nil, fmt.Errorf("invalid number of queries: %d", cfg.Queries) } - tickch := make(chan struct{}, 1) - proc := periodicproc.OnSignal(tickch, dht.bootstrapWorker(cfg)) - go func() { - tickch <- struct{}{} + proc := dht.Process().Go(func(p goprocess.Process) { + workerch := make(chan (<-chan struct{})) + bootstrap := func() { + proc := p.Go(dht.bootstrapWorker(cfg)) + workerch <- proc.Closed() + } + go bootstrap() for { select { case <-time.After(cfg.Period): + ch := <-workerch select { - case tickch <- struct{}{}: + case <-ch: + go bootstrap() + case <-p.Closing(): + return default: - // Don't queue ticks, like Tickers log.Warning("Previous bootstrapping attempt not completed within bootstrapping period") } - case <-dht.Context().Done(): + case <-p.Closing(): return } } - }() + }) return proc, nil } From e8d32a56bee77f1662438ffbef87af2d11fe7720 Mon Sep 17 00:00:00 2001 From: Cole Brown Date: Mon, 23 Jul 2018 18:32:52 -0400 Subject: [PATCH 4/5] Simplify bootstrap loop --- dht_bootstrap.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/dht_bootstrap.go b/dht_bootstrap.go index c3be1b450..1b0e91ae7 100644 --- a/dht_bootstrap.go +++ b/dht_bootstrap.go @@ -78,24 +78,10 @@ func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process, } proc := dht.Process().Go(func(p goprocess.Process) { - workerch := make(chan (<-chan struct{})) - bootstrap := func() { - proc := p.Go(dht.bootstrapWorker(cfg)) - workerch <- proc.Closed() - } - go bootstrap() for { select { case <-time.After(cfg.Period): - ch := <-workerch - select { - case <-ch: - go bootstrap() - case <-p.Closing(): - return - default: - log.Warning("Previous bootstrapping attempt not completed within bootstrapping period") - } + <-p.Go(dht.bootstrapWorker(cfg)).Closed() case <-p.Closing(): return } From 9d8818b99404abaf9a70f07548cc2f540c26f02f Mon Sep 17 00:00:00 2001 From: Cole Brown Date: Tue, 24 Jul 2018 11:41:59 -0400 Subject: [PATCH 5/5] Remember to bootstrap immediately ;_; --- dht_bootstrap.go | 1 + 1 file changed, 1 insertion(+) diff --git a/dht_bootstrap.go b/dht_bootstrap.go index 1b0e91ae7..d87f1338c 100644 --- a/dht_bootstrap.go +++ b/dht_bootstrap.go @@ -78,6 +78,7 @@ func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process, } proc := dht.Process().Go(func(p goprocess.Process) { + <-p.Go(dht.bootstrapWorker(cfg)).Closed() for { select { case <-time.After(cfg.Period):