remove ApplyIfEnableLibP2P

This commit is contained in:
Anton Evangelatov 2021-07-07 13:31:56 +02:00
parent 566a9d5541
commit 42ae876711
2 changed files with 32 additions and 43 deletions

View File

@ -3,6 +3,7 @@ package node
import (
"context"
"errors"
"fmt"
"os"
"time"
@ -216,14 +217,42 @@ func Base(r repo.Repo) Option {
ApplyIf(func(s *Settings) bool { return s.Config },
Error(errors.New("the Base() option must be set before Config option")),
),
ApplyIfEnableLibP2P(r, LibP2P),
ApplyIf(func(s *Settings) bool { result, _ := enableLibp2pNode(s, r); return result },
LibP2P,
),
ApplyIf(isFullOrLiteNode, ChainNode),
ApplyIf(IsType(repo.StorageMiner), MinerNode),
)
}
func enableLibp2pNode(s *Settings, r repo.Repo) (bool, error) {
lr, err := r.Lock(s.nodeType)
if err != nil {
return false, err
}
c, err := lr.Config()
if err != nil {
return false, err
}
defer lr.Close() //nolint:errcheck
switch s.nodeType {
case repo.FullNode:
return true, nil
case repo.StorageMiner:
cfg, ok := c.(*config.StorageMiner)
if !ok {
return false, fmt.Errorf("invalid config for repo, got: %T", c)
}
enableLibP2P := cfg.Subsystems.EnableStorageMarket
return enableLibP2P, nil
default:
// TODO: log error
return false, errors.New("unknown repo type")
}
}
// Config sets up constructors based on the provided Config
func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option {
return Options(

View File

@ -1,40 +0,0 @@
package node
import (
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/node/repo"
)
func ApplyIfEnableLibP2P(r repo.Repo, opts ...Option) Option {
return ApplyIf(func(settings *Settings) bool {
lr, err := r.Lock(settings.nodeType)
if err != nil {
// TODO: log error
return false
}
c, err := lr.Config()
if err != nil {
// TODO: log error
return false
}
defer lr.Close() //nolint:errcheck
switch settings.nodeType {
case repo.FullNode:
return true
case repo.StorageMiner:
cfg, ok := c.(*config.StorageMiner)
if !ok {
// TODO: log error
return false
}
enableLibP2P := cfg.Subsystems.EnableStorageMarket
return enableLibP2P
default:
// TODO: log error
return false
}
}, opts...)
}