提交 9bcf072c 作者: Łukasz Magiera

WIP cleanup config handling in core

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 6b72593b
...@@ -84,10 +84,10 @@ func (cfg *BuildCfg) fillDefaults() error { ...@@ -84,10 +84,10 @@ func (cfg *BuildCfg) fillDefaults() error {
} }
// options creates fx option group from this build config // options creates fx option group from this build config
func (cfg *BuildCfg) options(ctx context.Context) fx.Option { func (cfg *BuildCfg) options(ctx context.Context) (fx.Option, *cfg.Config) {
err := cfg.fillDefaults() err := cfg.fillDefaults()
if err != nil { if err != nil {
return fx.Error(err) return fx.Error(err), nil
} }
repoOption := fx.Provide(func(lc fx.Lifecycle) repo.Repo { repoOption := fx.Provide(func(lc fx.Lifecycle) repo.Repo {
...@@ -112,12 +112,17 @@ func (cfg *BuildCfg) options(ctx context.Context) fx.Option { ...@@ -112,12 +112,17 @@ func (cfg *BuildCfg) options(ctx context.Context) fx.Option {
return cfg.Routing return cfg.Routing
}) })
conf, err := cfg.Repo.Config()
if err != nil {
return fx.Error(err), nil
}
return fx.Options( return fx.Options(
repoOption, repoOption,
hostOption, hostOption,
routingOption, routingOption,
metricsCtx, metricsCtx,
) ), conf
} }
func defaultRepo(dstore repo.Datastore) (repo.Repo, error) { func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
offline "github.com/ipfs/go-ipfs-exchange-offline" offline "github.com/ipfs/go-ipfs-exchange-offline"
offroute "github.com/ipfs/go-ipfs-routing/offline" offroute "github.com/ipfs/go-ipfs-routing/offline"
uio "github.com/ipfs/go-unixfs/io"
"github.com/ipfs/go-path/resolver" "github.com/ipfs/go-path/resolver"
"go.uber.org/fx" "go.uber.org/fx"
) )
...@@ -122,21 +123,33 @@ func Networked(cfg *BuildCfg) fx.Option { ...@@ -122,21 +123,33 @@ func Networked(cfg *BuildCfg) fx.Option {
} }
// IPFS builds a group of fx Options based on the passed BuildCfg // IPFS builds a group of fx Options based on the passed BuildCfg
func IPFS(ctx context.Context, cfg *BuildCfg) fx.Option { func IPFS(ctx context.Context, bcfg *BuildCfg) fx.Option {
if bcfg == nil {
bcfg = new(BuildCfg)
}
bcfgOpts, cfg := bcfg.options(ctx)
if cfg == nil { if cfg == nil {
cfg = new(BuildCfg) return bcfgOpts // error
} }
// TEMP: setting global sharding switch here
uio.UseHAMTSharding = cfg.Experimental.ShardingEnabled
return fx.Options( return fx.Options(
cfg.options(ctx), bcfgOpts,
fx.Provide(baseProcess), fx.Provide(baseProcess),
fx.Invoke(setupSharding),
Storage(cfg), Storage(bcfg),
Identity, Identity,
IPNS, IPNS,
Networked(cfg), Networked(bcfg),
Core, Core,
) )
......
...@@ -3,8 +3,6 @@ package node ...@@ -3,8 +3,6 @@ package node
import ( import (
"context" "context"
config "github.com/ipfs/go-ipfs-config"
uio "github.com/ipfs/go-unixfs/io"
"github.com/jbenet/goprocess" "github.com/jbenet/goprocess"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/fx" "go.uber.org/fx"
...@@ -45,11 +43,6 @@ func maybeProvide(opt interface{}, enable bool) fx.Option { ...@@ -45,11 +43,6 @@ func maybeProvide(opt interface{}, enable bool) fx.Option {
return fx.Options() return fx.Options()
} }
func setupSharding(cfg *config.Config) {
// TEMP: setting global sharding switch here
uio.UseHAMTSharding = cfg.Experimental.ShardingEnabled
}
// baseProcess creates a goprocess which is closed when the lifecycle signals it to stop // baseProcess creates a goprocess which is closed when the lifecycle signals it to stop
func baseProcess(lc fx.Lifecycle) goprocess.Process { func baseProcess(lc fx.Lifecycle) goprocess.Process {
p := goprocess.WithParent(goprocess.Background()) p := goprocess.WithParent(goprocess.Background())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论