Commit 79b69919 authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #44 from vyzo/vyzo-fix-ticker-leak

fix ticker leak in BootstrapWithConfig
parents 68238335 7a4eb0f0
......@@ -73,9 +73,14 @@ func (dht *IpfsDHT) Bootstrap(ctx context.Context) error {
// These parameters are configurable.
//
// BootstrapWithConfig returns a process, so the user can stop it.
func (dht *IpfsDHT) BootstrapWithConfig(config BootstrapConfig) (goprocess.Process, error) {
sig := time.Tick(config.Period)
return dht.BootstrapOnSignal(config, sig)
func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process, error) {
if cfg.Queries <= 0 {
return nil, fmt.Errorf("invalid number of queries: %d", cfg.Queries)
}
proc := periodicproc.Tick(cfg.Period, dht.bootstrapWorker(cfg))
return proc, nil
}
// SignalBootstrap ensures the dht routing table remains healthy as peers come and go.
......@@ -93,7 +98,13 @@ func (dht *IpfsDHT) BootstrapOnSignal(cfg BootstrapConfig, signal <-chan time.Ti
return nil, fmt.Errorf("invalid signal: %v", signal)
}
proc := periodicproc.Ticker(signal, func(worker goprocess.Process) {
proc := periodicproc.Ticker(signal, dht.bootstrapWorker(cfg))
return proc, nil
}
func (dht *IpfsDHT) bootstrapWorker(cfg BootstrapConfig) func(worker goprocess.Process) {
return func(worker goprocess.Process) {
// it would be useful to be able to send out signals of when we bootstrap, too...
// maybe this is a good case for whole module event pub/sub?
......@@ -102,9 +113,7 @@ func (dht *IpfsDHT) BootstrapOnSignal(cfg BootstrapConfig, signal <-chan time.Ti
log.Warning(err)
// A bootstrapping error is important to notice but not fatal.
}
})
return proc, nil
}
}
// runBootstrap builds up list of peers by requesting random peer IDs
......
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