bootstrap: check for presence of bootstrap nodes earlier
Rather than checking for the presence of bootstrap nodes on each iteration of the deferred function, do the check at initialization time and report an error immediately. License: MIT Signed-off-by: Daniel Mack <daniel@zonque.org>
Daniel Mack committed
Nov 12, 2018 at 17:54 UTC
45b34e2bcb0d5b9193ba6d804cdc5e5f089bcd38
1 file changed
+6
-5
core/bootstrap.go
+6
-5
@@ -77,6 +77,12 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
77
// make a signal to wait for one bootstrap round to complete.
78
doneWithRound := make(chan struct{})
79
80
+ if len(cfg.BootstrapPeers()) == 0 {
81
+ // We *need* to bootstrap but we have no bootstrap peers
82
+ // configured *at all*, inform the user.
83
+ log.Error("no bootstrap nodes configured: go-ipfs may have difficulty connecting to the network")
84
+ }
85
+
86
// the periodic bootstrap function -- the connection supervisor
87
periodic := func(worker goprocess.Process) {
88
ctx := procctx.OnClosingContext(worker)
@@ -138,11 +144,6 @@ func bootstrapRound(ctx context.Context, host host.Host, cfg BootstrapConfig) er
144
// if connected to all bootstrap peer candidates, exit
145
if len(notConnected) < 1 {
146
log.Debugf("%s no more bootstrap peers to create %d connections", id, numToDial)
141
- if len(peers) == 0 {
142
- // We *need* to bootstrap but we have no bootstrap peers
143
- // configured *at all*, inform the user.
144
- log.Error("no bootstrap nodes configured: go-ipfs may have difficulty connecting to the network")
145
- }
147
return ErrNotEnoughBootstrapPeers
148
}
149