diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 08441285b..c9b736c72 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -4,6 +4,7 @@ package main import ( "context" + "github.com/filecoin-project/lotus/peermgr" "io/ioutil" "github.com/multiformats/go-multiaddr" @@ -95,8 +96,9 @@ var DaemonCmd = &cli.Command{ return lr.SetAPIEndpoint(apima) }), - node.ApplyIf(func(s *node.Settings) bool { return cctx.Bool("bootstrap") }, - node.Override(node.BootstrapKey, modules.Bootstrap), + node.ApplyIf(func(s *node.Settings) bool { return !cctx.Bool("bootstrap") }, + node.Unset(node.RunPeerMgrKey), + node.Unset(new(*peermgr.PeerMgr)), ), ) if err != nil { diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index 7834ff423..e7cffe186 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -15,6 +15,7 @@ import ( func main() { logging.SetLogLevel("*", "INFO") + logging.SetLogLevel("dht", "ERROR") local := []*cli.Command{ DaemonCmd, } diff --git a/node/modules/core.go b/node/modules/core.go index bde386d67..afc1b682a 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -3,24 +3,19 @@ package modules import ( "context" "crypto/rand" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/addrutil" - "github.com/filecoin-project/lotus/node/modules/helpers" + "github.com/filecoin-project/lotus/node/modules/dtypes" + "github.com/filecoin-project/lotus/node/repo" "github.com/gbrlsnchs/jwt/v3" logging "github.com/ipfs/go-log" - "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/peerstore" record "github.com/libp2p/go-libp2p-record" - "go.uber.org/fx" "golang.org/x/xerrors" "io" "io/ioutil" - "time" - - "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lotus/node/repo" ) var log = logging.Logger("modules") @@ -86,40 +81,3 @@ func ConfigBootstrap(peers []string) func() (dtypes.BootstrapPeers, error) { func BuiltinBootstrap() (dtypes.BootstrapPeers, error) { return build.BuiltinBootstrap() } - -func Bootstrap(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, pinfos dtypes.BootstrapPeers) { - ctx, cancel := context.WithCancel(mctx) - - lc.Append(fx.Hook{ - OnStart: func(_ context.Context) error { - go func() { - for { - sctx, cancel := context.WithTimeout(ctx, 2*time.Second) - <-sctx.Done() - cancel() - - if ctx.Err() != nil { - return - } - - if len(host.Network().Conns()) > 0 { - continue - } - - log.Warn("No peers connected, performing automatic bootstrap") - - for _, pi := range pinfos { - if err := host.Connect(ctx, pi); err != nil { - log.Warn("bootstrap connect failed: ", err) - } - } - } - }() - return nil - }, - OnStop: func(_ context.Context) error { - cancel() - return nil - }, - }) -} diff --git a/peermgr/peermgr.go b/peermgr/peermgr.go index 8ddc3a40e..d8a0bea77 100644 --- a/peermgr/peermgr.go +++ b/peermgr/peermgr.go @@ -2,6 +2,7 @@ package peermgr import ( "context" + "github.com/filecoin-project/lotus/node/modules/dtypes" "sync" "time" @@ -41,12 +42,16 @@ type PeerMgr struct { notifee *net.NotifyBundle } -func NewPeerMgr(h host.Host, dht *dht.IpfsDHT) *PeerMgr { +func NewPeerMgr(h host.Host, dht *dht.IpfsDHT, bootstrap dtypes.BootstrapPeers) *PeerMgr { pm := &PeerMgr{ - peers: make(map[peer.ID]struct{}), + h: h, + dht: dht, + bootstrappers: bootstrap, + + peers: make(map[peer.ID]struct{}), + maxFilPeers: MaxFilPeers, minFilPeers: MinFilPeers, - h: h, } pm.notifee = &net.NotifyBundle{