@cryptotaxi247 / kubo / commits / 4cae9ccf3

feat: print error on bootstrap failure

This will print ERROR to log if daemon running in online mode has no peers after one minute since start. (cherry picked from commit 039e12a2da77af7f0dfbdbc4602c2b5ba75c9b32)

Marcin Rataj committed May 31, 2021 at 15:33 UTC 4cae9ccf32b693e42cb9c653d8c9c057d195779d
1 file changed +19
cmd/ipfs/daemon.go
+19
@@ -12,6 +12,7 @@ import (
12 "runtime"
13 "sort"
14 "sync"
15 + "time"
16
17 multierror "github.com/hashicorp/go-multierror"
18
@@ -22,6 +23,7 @@ import (
23 oldcmds "github.com/ipfs/go-ipfs/commands"
24 "github.com/ipfs/go-ipfs/core"
25 commands "github.com/ipfs/go-ipfs/core/commands"
26 + "github.com/ipfs/go-ipfs/core/coreapi"
27 corehttp "github.com/ipfs/go-ipfs/core/corehttp"
28 corerepo "github.com/ipfs/go-ipfs/core/corerepo"
29 libp2p "github.com/ipfs/go-ipfs/core/node/libp2p"
@@ -510,6 +512,23 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
512 fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
513 }()
514
515 + // Give the user heads up if daemon running in online mode has no peers after 1 minute
516 + if !offline {
517 + time.AfterFunc(1*time.Minute, func() {
518 + ipfs, err := coreapi.NewCoreAPI(node)
519 + if err != nil {
520 + log.Errorf("failed to access CoreAPI: %v", err)
521 + }
522 + peers, err := ipfs.Swarm().Peers(cctx.Context())
523 + if err != nil {
524 + log.Errorf("failed to read swarm peers: %v", err)
525 + }
526 + if len(peers) == 0 {
527 + log.Error("failed to bootstrap (no peers found): consider updating Bootstrap or Peering section of your config")
528 + }
529 + })
530 + }
531 +
532 // collect long-running errors and block for shutdown
533 // TODO(cryptix): our fuse currently doesn't follow this pattern for graceful shutdown
534 var errs error