Merge pull request #334 from filecoin-project/feat/bootstrap-config
config: Allow overriding bootstrap peers
This commit is contained in:
commit
379f0116a2
@ -203,6 +203,8 @@ func Online() Option {
|
||||
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeFull },
|
||||
// TODO: Fix offline mode
|
||||
|
||||
Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap),
|
||||
|
||||
Override(HandleIncomingMessagesKey, modules.HandleIncomingMessages),
|
||||
|
||||
Override(new(*store.ChainStore), modules.ChainStore),
|
||||
@ -294,6 +296,10 @@ func Config(cfg *config.Root) Option {
|
||||
ApplyIf(func(s *Settings) bool { return s.Online },
|
||||
Override(StartListeningKey, lp2p.StartListening(cfg.Libp2p.ListenAddresses)),
|
||||
|
||||
ApplyIf(func(s *Settings) bool { return len(cfg.Libp2p.BootstrapPeers) > 0 },
|
||||
Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)),
|
||||
),
|
||||
|
||||
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeFull },
|
||||
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
|
||||
),
|
||||
|
@ -19,6 +19,7 @@ type API struct {
|
||||
// Libp2p contains configs for libp2p
|
||||
type Libp2p struct {
|
||||
ListenAddresses []string
|
||||
BootstrapPeers []string
|
||||
}
|
||||
|
||||
type Metrics struct {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"github.com/filecoin-project/go-lotus/build"
|
||||
"github.com/filecoin-project/go-lotus/lib/addrutil"
|
||||
"github.com/filecoin-project/go-lotus/node/modules/helpers"
|
||||
"github.com/gbrlsnchs/jwt/v3"
|
||||
logging "github.com/ipfs/go-log"
|
||||
@ -76,7 +77,17 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, err
|
||||
return (*dtypes.APIAlg)(jwt.NewHS256(key.PrivateKey)), nil
|
||||
}
|
||||
|
||||
func Bootstrap(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) {
|
||||
func ConfigBootstrap(peers []string) func() (dtypes.BootstrapPeers, error) {
|
||||
return func() (dtypes.BootstrapPeers, error) {
|
||||
return addrutil.ParseAddresses(context.TODO(), peers)
|
||||
}
|
||||
}
|
||||
|
||||
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{
|
||||
@ -97,13 +108,7 @@ func Bootstrap(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) {
|
||||
|
||||
log.Warn("No peers connected, performing automatic bootstrap")
|
||||
|
||||
pis, err := build.BuiltinBootstrap()
|
||||
if err != nil {
|
||||
log.Error("Getting bootstrap addrs: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, pi := range pis {
|
||||
for _, pi := range pinfos {
|
||||
if err := host.Connect(ctx, pi); err != nil {
|
||||
log.Warn("bootstrap connect failed: ", err)
|
||||
}
|
||||
|
5
node/modules/dtypes/bootstrap.go
Normal file
5
node/modules/dtypes/bootstrap.go
Normal file
@ -0,0 +1,5 @@
|
||||
package dtypes
|
||||
|
||||
import "github.com/libp2p/go-libp2p-core/peer"
|
||||
|
||||
type BootstrapPeers []peer.AddrInfo
|
Loading…
Reference in New Issue
Block a user