mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
169 lines
3.1 KiB
Go
169 lines
3.1 KiB
Go
package node
|
|
|
|
import (
|
|
"context"
|
|
|
|
offline "github.com/ipfs/go-ipfs-exchange-offline"
|
|
"github.com/ipfs/go-metrics-interface"
|
|
"github.com/ipfs/go-path/resolver"
|
|
"go.uber.org/fx"
|
|
|
|
offroute "github.com/ipfs/go-ipfs-routing/offline"
|
|
"github.com/ipfs/go-ipfs/p2p"
|
|
"github.com/ipfs/go-ipfs/provider"
|
|
"github.com/ipfs/go-ipfs/repo"
|
|
)
|
|
|
|
var BaseLibP2P = fx.Options(
|
|
fx.Provide(P2PAddrFilters),
|
|
fx.Provide(P2PBandwidthCounter),
|
|
fx.Provide(P2PPNet),
|
|
fx.Provide(P2PAddrsFactory),
|
|
fx.Provide(P2PConnectionManager),
|
|
fx.Provide(P2PNatPortMap),
|
|
fx.Provide(P2PRelay),
|
|
fx.Provide(P2PAutoRealy),
|
|
fx.Provide(P2PDefaultTransports),
|
|
fx.Provide(P2PQUIC),
|
|
|
|
fx.Provide(P2PHost),
|
|
|
|
fx.Provide(NewDiscoveryHandler),
|
|
|
|
fx.Invoke(AutoNATService),
|
|
fx.Invoke(P2PPNetChecker),
|
|
fx.Invoke(StartListening),
|
|
fx.Invoke(SetupDiscovery),
|
|
)
|
|
|
|
func LibP2P(cfg *BuildCfg) fx.Option {
|
|
return fx.Options(
|
|
BaseLibP2P,
|
|
|
|
maybeProvide(P2PNoSecurity, cfg.DisableEncryptedConnections),
|
|
maybeProvide(Pubsub, cfg.getOpt("pubsub") || cfg.getOpt("ipnsps")),
|
|
|
|
fx.Provide(P2PSmuxTransport(cfg.getOpt("mplex"))),
|
|
fx.Provide(P2POnlineRouting(cfg.getOpt("ipnsps"))),
|
|
)
|
|
}
|
|
|
|
func Storage(cfg *BuildCfg) fx.Option {
|
|
return fx.Options(
|
|
fx.Provide(RepoConfig),
|
|
fx.Provide(DatastoreCtor),
|
|
fx.Provide(BaseBlockstoreCtor(cfg.Permanent, cfg.NilRepo)),
|
|
fx.Provide(GcBlockstoreCtor),
|
|
)
|
|
}
|
|
|
|
var Identity = fx.Options(
|
|
fx.Provide(PeerID),
|
|
fx.Provide(PrivateKey),
|
|
fx.Provide(Peerstore),
|
|
)
|
|
|
|
var IPNS = fx.Options(
|
|
fx.Provide(RecordValidator),
|
|
)
|
|
|
|
var Providers = fx.Options(
|
|
fx.Provide(ProviderQueue),
|
|
fx.Provide(ProviderCtor),
|
|
fx.Provide(ReproviderCtor),
|
|
|
|
fx.Invoke(Reprovider),
|
|
fx.Invoke(provider.Provider.Run),
|
|
)
|
|
|
|
func Online(cfg *BuildCfg) fx.Option {
|
|
return fx.Options(
|
|
fx.Provide(OnlineExchangeCtor),
|
|
fx.Provide(OnlineNamesysCtor),
|
|
|
|
fx.Invoke(IpnsRepublisher),
|
|
|
|
fx.Provide(p2p.NewP2P),
|
|
|
|
LibP2P(cfg),
|
|
Providers,
|
|
)
|
|
}
|
|
|
|
var Offline = fx.Options(
|
|
fx.Provide(offline.Exchange),
|
|
fx.Provide(OfflineNamesysCtor),
|
|
fx.Provide(offroute.NewOfflineRouter),
|
|
fx.Provide(provider.NewOfflineProvider),
|
|
)
|
|
|
|
var Core = fx.Options(
|
|
fx.Provide(BlockServiceCtor),
|
|
fx.Provide(DagCtor),
|
|
fx.Provide(resolver.NewBasicResolver),
|
|
fx.Provide(Pinning),
|
|
fx.Provide(Files),
|
|
)
|
|
|
|
func Networked(cfg *BuildCfg) fx.Option {
|
|
if cfg.Online {
|
|
return Online(cfg)
|
|
}
|
|
return Offline
|
|
}
|
|
|
|
func IPFS(ctx context.Context, cfg *BuildCfg) fx.Option {
|
|
if cfg == nil {
|
|
cfg = new(BuildCfg)
|
|
}
|
|
|
|
err := cfg.fillDefaults()
|
|
if err != nil {
|
|
return fx.Error(err)
|
|
}
|
|
|
|
ctx = metrics.CtxScope(ctx, "ipfs")
|
|
|
|
repoOption := fx.Provide(func(lc fx.Lifecycle) repo.Repo {
|
|
lc.Append(fx.Hook{
|
|
OnStop: func(ctx context.Context) error {
|
|
return cfg.Repo.Close()
|
|
},
|
|
})
|
|
|
|
return cfg.Repo
|
|
})
|
|
|
|
metricsCtx := fx.Provide(func() MetricsCtx {
|
|
return MetricsCtx(ctx)
|
|
})
|
|
|
|
hostOption := fx.Provide(func() HostOption {
|
|
return cfg.Host
|
|
})
|
|
|
|
routingOption := fx.Provide(func() RoutingOption {
|
|
return cfg.Routing
|
|
})
|
|
|
|
params := fx.Options(
|
|
repoOption,
|
|
hostOption,
|
|
routingOption,
|
|
metricsCtx,
|
|
)
|
|
|
|
return fx.Options(
|
|
params,
|
|
fx.Provide(baseProcess),
|
|
fx.Invoke(setupSharding),
|
|
|
|
Storage(cfg),
|
|
Identity,
|
|
IPNS,
|
|
Networked(cfg),
|
|
|
|
Core,
|
|
)
|
|
}
|