Organize NewNode a bit

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera 2019-03-28 02:02:05 +01:00 committed by Steven Allen
parent 0fd2f80be7
commit 361ba691ed
2 changed files with 60 additions and 30 deletions

View File

@ -155,47 +155,75 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
return cfg
})
params := fx.Options(
repoOption,
cfgOption,
)
storage := fx.Options(
fx.Provide(repoConfig),
fx.Provide(baseBlockstoreCtor),
fx.Provide(gcBlockstoreCtor),
)
ident := fx.Options(
fx.Provide(identity),
fx.Provide(privateKey),
)
ipns := fx.Options(
fx.Provide(recordValidator),
)
online := fx.Options(
fx.Provide(onlineExchangeCtor),
fx.Provide(onlineNamesysCtor),
fx.Invoke(ipnsRepublisher),
fx.Invoke(provider.Provider.Run),
)
if !cfg.Online {
online = fx.Options(
fx.Provide(offline.Exchange),
fx.Provide(offlineNamesysCtor),
)
}
core := fx.Options(
fx.Provide(bserv.New),
fx.Provide(dagCtor),
fx.Provide(resolver.NewBasicResolver),
fx.Provide(pinning),
fx.Provide(files),
)
providers := fx.Options(
fx.Provide(providerQueue),
fx.Provide(providerCtor),
fx.Provide(reproviderCtor),
fx.Invoke(reprovider),
)
n := &IpfsNode{
ctx: ctx,
}
app := fx.New(
repoOption,
cfgOption,
fx.Provide(repoConfig),
fx.Provide(identity),
fx.Provide(privateKey),
fx.Provide(peerstore),
fx.Provide(baseBlockstoreCtor),
fx.Provide(gcBlockstoreCtor),
fx.Provide(recordValidator),
params,
storage,
ident,
ipfsp2p,
ipns,
online,
fx.Invoke(setupSharding),
fx.Provide(onlineExchangeCtor), // TODO: offline
fx.Provide(onlineNamesysCtor), // TODO: ^^
fx.Provide(bserv.New),
fx.Provide(onlineDagCtor),
fx.Provide(resolver.NewBasicResolver),
fx.Provide(pinning),
fx.Provide(files),
fx.Provide(providerQueue),
fx.Provide(providerCtor),
fx.Provide(reproviderCtor),
fx.Invoke(reprovider),
core,
providers,
fx.Provide(p2p.NewP2P),
fx.Invoke(ipnsRepublisher),
fx.Invoke(provider.Provider.Run),
fx.Extract(n),
)

View File

@ -180,6 +180,8 @@ func recordValidator(ps pstore.Peerstore) record.Validator {
// libp2p
var ipfsp2p = fx.Options(
fx.Provide(peerstore),
fx.Provide(p2pAddrFilters),
fx.Provide(p2pBandwidthCounter),
fx.Provide(p2pPNet),
@ -564,7 +566,7 @@ func pinning(bstore bstore.Blockstore, ds format.DAGService, repo repo.Repo) (pi
return pinning, nil
}
func onlineDagCtor(bs bserv.BlockService) format.DAGService {
func dagCtor(bs bserv.BlockService) format.DAGService {
return merkledag.NewDAGService(bs)
}