Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First round bootstrap #5953

Closed
cpacia opened this issue Jan 28, 2019 · 2 comments
Closed

First round bootstrap #5953

cpacia opened this issue Jan 28, 2019 · 2 comments

Comments

@cpacia
Copy link

cpacia commented Jan 28, 2019

In the course of debugging it seems to me that the dht bootstrap is starting before the host has connected to the bootstrap peers. Does anyone else see this? In the code below bootstrapRound and n.Routing.Bootstrap() seem to be running at the same time and the dht bootstap logs so failure to bootstrap.

Seems like moving the code block below to right before the dht bootstrap would fix.

doneWithRound <- struct{}{}
close(doneWithRound) // it no longer blocks periodic
func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {

	// make a signal to wait for one bootstrap round to complete.
	doneWithRound := make(chan struct{})

	// the periodic bootstrap function -- the connection supervisor
	periodic := func(worker goprocess.Process) {
		ctx := procctx.OnClosingContext(worker)
		defer log.EventBegin(ctx, "periodicBootstrap", n.Identity).Done()

		if err := bootstrapRound(ctx, n.PeerHost, cfg); err != nil {
			log.Event(ctx, "bootstrapError", n.Identity, lgbl.Error(err))
			log.Debugf("%s bootstrap error: %s", n.Identity, err)
		}

		<-doneWithRound
	}

	// kick off the node's periodic bootstrapping
	proc := periodicproc.Tick(cfg.Period, periodic)
	proc.Go(periodic) // run one right now.

	// kick off Routing.Bootstrap
	go func() {
		if n.Routing != nil {
			ctx := procctx.OnClosingContext(proc)
			if err := n.Routing.Bootstrap(ctx); err != nil {
				proc.Close()
				log.Error(err)
			}
		}
	}()
        doneWithRound <- struct{}{}
	close(doneWithRound) // it no longer blocks periodic
	return proc, nil
}
@anacrolix
Copy link
Contributor

It's very likely. Currently connection to the bootstrap nodes should occur synchronously before the first bootstrap attempt (which is also not used synchronous at the moment). See the activity in the DHT repo around BootstrapOnce.

@Stebalien
Copy link
Member

This has been fixed. The DHT now:

  1. Handles connecting to bootstrap peers internally.
  2. Re-bootstrap when it receives a new connection and has an empty routing table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants