diff --git a/dht_bootstrap.go b/dht_bootstrap.go index 9e4e60e8b..97f5e3387 100644 --- a/dht_bootstrap.go +++ b/dht_bootstrap.go @@ -65,6 +65,15 @@ func (dht *IpfsDHT) BootstrapWithConfig(ctx context.Context, cfg BootstrapConfig return nil } +// This is a synchronous bootstrap. cfg.Queries queries will run each with a +// timeout of cfg.Timeout. cfg.Period is not used. +func (dht *IpfsDHT) BootstrapOnce(ctx context.Context, cfg BootstrapConfig) error { + if cfg.Queries <= 0 { + return fmt.Errorf("invalid number of queries: %d", cfg.Queries) + } + return dht.runBootstrap(ctx, cfg) +} + func newRandomPeerId() peer.ID { id := make([]byte, 32) // SHA256 is the default. TODO: Use a more canonical way to generate random IDs. rand.Read(id) diff --git a/dht_test.go b/dht_test.go index d83c08675..7899fbcec 100644 --- a/dht_test.go +++ b/dht_test.go @@ -709,10 +709,7 @@ func TestPeriodicBootstrap(t *testing.T) { t.Logf("bootstrapping them so they find each other. %d", nDHTs) for _, dht := range dhts { - err := dht.BootstrapWithConfig(ctx, cfg) - if err != nil { - t.Fatalf("error bootstrapping a dht: %s", err) - } + go dht.BootstrapOnce(ctx, cfg) } // this is async, and we dont know when it's finished with one cycle, so keep checking