@cryptotaxi247 / kubo / commits / 9bcf072cc

WIP cleanup config handling in core

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Apr 26, 2019 at 17:03 UTC 9bcf072ccb07ff2981487a5144dab2691079ec06
3 files changed +27 -16
core/node/builder.go
+8 -3
@@ -84,10 +84,10 @@ func (cfg *BuildCfg) fillDefaults() error {
84 }
85
86 // options creates fx option group from this build config
87 -func (cfg *BuildCfg) options(ctx context.Context) fx.Option {
87 +func (cfg *BuildCfg) options(ctx context.Context) (fx.Option, *cfg.Config) {
88 err := cfg.fillDefaults()
89 if err != nil {
90 - return fx.Error(err)
90 + return fx.Error(err), nil
91 }
92
93 repoOption := fx.Provide(func(lc fx.Lifecycle) repo.Repo {
@@ -112,12 +112,17 @@ func (cfg *BuildCfg) options(ctx context.Context) fx.Option {
112 return cfg.Routing
113 })
114
115 + conf, err := cfg.Repo.Config()
116 + if err != nil {
117 + return fx.Error(err), nil
118 + }
119 +
120 return fx.Options(
121 repoOption,
122 hostOption,
123 routingOption,
124 metricsCtx,
120 - )
125 + ), conf
126 }
127
128 func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
core/node/groups.go
+19 -6
@@ -9,6 +9,7 @@ import (
9
10 offline "github.com/ipfs/go-ipfs-exchange-offline"
11 offroute "github.com/ipfs/go-ipfs-routing/offline"
12 + uio "github.com/ipfs/go-unixfs/io"
13 "github.com/ipfs/go-path/resolver"
14 "go.uber.org/fx"
15 )
@@ -122,21 +123,33 @@ func Networked(cfg *BuildCfg) fx.Option {
123 }
124
125 // IPFS builds a group of fx Options based on the passed BuildCfg
125 -func IPFS(ctx context.Context, cfg *BuildCfg) fx.Option {
126 +func IPFS(ctx context.Context, bcfg *BuildCfg) fx.Option {
127 + if bcfg == nil {
128 + bcfg = new(BuildCfg)
129 + }
130 +
131 + bcfgOpts, cfg := bcfg.options(ctx)
132 if cfg == nil {
127 - cfg = new(BuildCfg)
133 + return bcfgOpts // error
134 }
135
136 + // TEMP: setting global sharding switch here
137 + uio.UseHAMTSharding = cfg.Experimental.ShardingEnabled
138 +
139 +
140 +
141 +
142 +
143 +
144 return fx.Options(
131 - cfg.options(ctx),
145 + bcfgOpts,
146
147 fx.Provide(baseProcess),
134 - fx.Invoke(setupSharding),
148
136 - Storage(cfg),
149 + Storage(bcfg),
150 Identity,
151 IPNS,
139 - Networked(cfg),
152 + Networked(bcfg),
153
154 Core,
155 )
core/node/helpers.go
-7
@@ -3,8 +3,6 @@ package node
3 import (
4 "context"
5
6 - config "github.com/ipfs/go-ipfs-config"
7 - uio "github.com/ipfs/go-unixfs/io"
6 "github.com/jbenet/goprocess"
7 "github.com/pkg/errors"
8 "go.uber.org/fx"
@@ -45,11 +43,6 @@ func maybeProvide(opt interface{}, enable bool) fx.Option {
43 return fx.Options()
44 }
45
48 -func setupSharding(cfg *config.Config) {
49 - // TEMP: setting global sharding switch here
50 - uio.UseHAMTSharding = cfg.Experimental.ShardingEnabled
51 -}
52 -
46 // baseProcess creates a goprocess which is closed when the lifecycle signals it to stop
47 func baseProcess(lc fx.Lifecycle) goprocess.Process {
48 p := goprocess.WithParent(goprocess.Background())