Skip to content

Commit

Permalink
Include BootstrapOnce
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Jan 23, 2019
1 parent c6e2fde commit 9055bd6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 9 additions & 0 deletions dht_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9055bd6

Please sign in to comment.