remove ApplyIfEnableLibP2P
This commit is contained in:
parent
566a9d5541
commit
42ae876711
@ -3,6 +3,7 @@ package node
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -216,14 +217,42 @@ func Base(r repo.Repo) Option {
|
|||||||
ApplyIf(func(s *Settings) bool { return s.Config },
|
ApplyIf(func(s *Settings) bool { return s.Config },
|
||||||
Error(errors.New("the Base() option must be set before Config option")),
|
Error(errors.New("the Base() option must be set before Config option")),
|
||||||
),
|
),
|
||||||
|
ApplyIf(func(s *Settings) bool { result, _ := enableLibp2pNode(s, r); return result },
|
||||||
ApplyIfEnableLibP2P(r, LibP2P),
|
LibP2P,
|
||||||
|
),
|
||||||
ApplyIf(isFullOrLiteNode, ChainNode),
|
ApplyIf(isFullOrLiteNode, ChainNode),
|
||||||
ApplyIf(IsType(repo.StorageMiner), MinerNode),
|
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
|
// Config sets up constructors based on the provided Config
|
||||||
func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option {
|
func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option {
|
||||||
return Options(
|
return Options(
|
||||||
|
@ -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...)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user