@cryptotaxi247 / kubo / commits / 361ba691e

Organize NewNode a bit

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

Łukasz Magiera committed Mar 28, 2019 at 02:02 UTC 361ba691ed0115933da1a8c17038fe3f82e570db
2 files changed +48 -18
core/builder.go
+45 -17
@@ -155,46 +155,74 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
155 return cfg
156 })
157
158 - n := &IpfsNode{
159 - ctx: ctx,
160 - }
158
162 - app := fx.New(
159 + params := fx.Options(
160 repoOption,
161 cfgOption,
162 + )
163
164 + storage := fx.Options(
165 fx.Provide(repoConfig),
167 - fx.Provide(identity),
168 - fx.Provide(privateKey),
169 -
170 - fx.Provide(peerstore),
166 fx.Provide(baseBlockstoreCtor),
167 fx.Provide(gcBlockstoreCtor),
168 + )
169
170 + ident := fx.Options(
171 + fx.Provide(identity),
172 + fx.Provide(privateKey),
173 + )
174 +
175 + ipns := fx.Options(
176 fx.Provide(recordValidator),
177 + )
178
176 - ipfsp2p,
179 + online := fx.Options(
180 + fx.Provide(onlineExchangeCtor),
181 + fx.Provide(onlineNamesysCtor),
182
178 - fx.Invoke(setupSharding),
183 + fx.Invoke(ipnsRepublisher),
184 + fx.Invoke(provider.Provider.Run),
185 + )
186 + if !cfg.Online {
187 + online = fx.Options(
188 + fx.Provide(offline.Exchange),
189 + fx.Provide(offlineNamesysCtor),
190 + )
191 + }
192
180 - fx.Provide(onlineExchangeCtor), // TODO: offline
181 - fx.Provide(onlineNamesysCtor), // TODO: ^^
193 + core := fx.Options(
194 fx.Provide(bserv.New),
183 - fx.Provide(onlineDagCtor),
195 + fx.Provide(dagCtor),
196 fx.Provide(resolver.NewBasicResolver),
185 -
197 fx.Provide(pinning),
198 fx.Provide(files),
199 + )
200
201 + providers := fx.Options(
202 fx.Provide(providerQueue),
203 fx.Provide(providerCtor),
204 fx.Provide(reproviderCtor),
205 fx.Invoke(reprovider),
206 + )
207
194 - fx.Provide(p2p.NewP2P),
208 + n := &IpfsNode{
209 + ctx: ctx,
210 + }
211
196 - fx.Invoke(ipnsRepublisher),
197 - fx.Invoke(provider.Provider.Run),
212 + app := fx.New(
213 + params,
214 + storage,
215 + ident,
216 + ipfsp2p,
217 + ipns,
218 + online,
219 +
220 + fx.Invoke(setupSharding),
221 +
222 + core,
223 + providers,
224 +
225 + fx.Provide(p2p.NewP2P),
226
227 fx.Extract(n),
228 )
core/ncore.go
+3 -1
@@ -180,6 +180,8 @@ func recordValidator(ps pstore.Peerstore) record.Validator {
180 // libp2p
181
182 var ipfsp2p = fx.Options(
183 + fx.Provide(peerstore),
184 +
185 fx.Provide(p2pAddrFilters),
186 fx.Provide(p2pBandwidthCounter),
187 fx.Provide(p2pPNet),
@@ -564,7 +566,7 @@ func pinning(bstore bstore.Blockstore, ds format.DAGService, repo repo.Repo) (pi
566 return pinning, nil
567 }
568
567 -func onlineDagCtor(bs bserv.BlockService) format.DAGService {
569 +func dagCtor(bs bserv.BlockService) format.DAGService {
570 return merkledag.NewDAGService(bs)
571 }
572