diff --git a/core/builder.go b/core/builder.go index 7eb80c91f..330fb9498 100644 --- a/core/builder.go +++ b/core/builder.go @@ -245,18 +245,18 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) { n.IsOnline = cfg.Online n.app = app -/* n := &IpfsNode{ - IsOnline: cfg.Online, - Repo: cfg.Repo, - ctx: ctx, - Peerstore: pstoremem.NewPeerstore(), - } + /* n := &IpfsNode{ + IsOnline: cfg.Online, + Repo: cfg.Repo, + ctx: ctx, + Peerstore: pstoremem.NewPeerstore(), + } - n.RecordValidator = record.NamespacedValidator{ - "pk": record.PublicKeyValidator{}, - "ipns": ipns.Validator{KeyBook: n.Peerstore}, - } -*/ + n.RecordValidator = record.NamespacedValidator{ + "pk": record.PublicKeyValidator{}, + "ipns": ipns.Validator{KeyBook: n.Peerstore}, + } + */ // TODO: port to lifetimes // n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown) @@ -264,11 +264,20 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) { n.Close() return nil, err }*/ - if app.Err() != nil { - return nil, app.Err() - } + if app.Err() != nil { + return nil, app.Err() + } - return n, app.Start(ctx) + if err := app.Start(ctx); err != nil { + return nil, err + } + + // TODO: DI-ify bootstrap + if !cfg.Online { + return n, nil + } + + return n, n.Bootstrap(DefaultBootstrapConfig) } func isTooManyFDError(err error) bool { diff --git a/core/core.go b/core/core.go index 9b18782d2..a587389c5 100644 --- a/core/core.go +++ b/core/core.go @@ -100,13 +100,13 @@ type IpfsNode struct { Repo repo.Repo // Local node - Pinning pin.Pinner // the pinning manager - Mounts Mounts `optional:"true"` // current mount state, if any. - PrivateKey ic.PrivKey // the local node's private Key - PNetFingerprint PNetFingerprint `optional:"true"` // fingerprint of private network + Pinning pin.Pinner // the pinning manager + Mounts Mounts `optional:"true"` // current mount state, if any. + PrivateKey ic.PrivKey // the local node's private Key + PNetFingerprint PNetFingerprint `optional:"true"` // fingerprint of private network // Services - Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances + Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances Blockstore bstore.GCBlockstore // the block store (lower level) Filestore *filestore.Filestore // the filestore blockstore BaseBlocks bstore.Blockstore // the raw blockstore, no filestore wrapping @@ -114,35 +114,35 @@ type IpfsNode struct { Blocks bserv.BlockService // the block service, get/add blocks. DAG ipld.DAGService // the merkle dag service, get/add objects. Resolver *resolver.Resolver // the path resolution system - Reporter metrics.Reporter `optional:"true"` - Discovery discovery.Service `optional:"true"` + Reporter metrics.Reporter `optional:"true"` + Discovery discovery.Service `optional:"true"` FilesRoot *mfs.Root RecordValidator record.Validator // Online - PeerHost p2phost.Host `optional:"true"` // the network host (server+client) + PeerHost p2phost.Host `optional:"true"` // the network host (server+client) Bootstrapper io.Closer `optional:"true"` // the periodic bootstrapper Routing routing.IpfsRouting `optional:"true"` // the routing system. recommend ipfs-dht Exchange exchange.Interface // the block exchange + strategy (bitswap) Namesys namesys.NameSystem // the name system, resolves paths to hashes - Provider provider.Provider // the value provider system - Reprovider *rp.Reprovider `optional:"true"` // the value reprovider system + Provider provider.Provider // the value provider system + Reprovider *rp.Reprovider `optional:"true"` // the value reprovider system IpnsRepub *ipnsrp.Republisher `optional:"true"` - AutoNAT *autonat.AutoNATService `optional:"true"` - PubSub *pubsub.PubSub `optional:"true"` + AutoNAT *autonat.AutoNATService `optional:"true"` + PubSub *pubsub.PubSub `optional:"true"` PSRouter *psrouter.PubsubValueStore `optional:"true"` - DHT *dht.IpfsDHT `optional:"true"` - P2P *p2p.P2P `optional:"true"` + DHT *dht.IpfsDHT `optional:"true"` + P2P *p2p.P2P `optional:"true"` Process goprocess.Process - ctx context.Context + ctx context.Context app *fx.App // Flags - IsOnline bool `optional:"true"` // Online is set when networking is enabled. - IsDaemon bool `optional:"true"` // Daemon is set when running on a long-running daemon. + IsOnline bool `optional:"true"` // Online is set when networking is enabled. + IsDaemon bool `optional:"true"` // Daemon is set when running on a long-running daemon. } // Mounts defines what the node's mount state is. This should @@ -206,9 +206,9 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin log.Warning("This might be configuration mistake.") } } - //case <-n.Process().Closing(): - // t.Stop() - // return + //case <-n.Process().Closing(): + // t.Stop() + // return } } }() diff --git a/core/ncore.go b/core/ncore.go index cd716edcb..fa4b385bb 100644 --- a/core/ncore.go +++ b/core/ncore.go @@ -452,11 +452,11 @@ func p2pHost(lc fx.Lifecycle, params p2pHostIn) (out p2pHostOut, err error) { type p2pRoutingIn struct { fx.In - BCfg *BuildCfg - Repo repo.Repo - Validator record.Validator - Host p2phost.Host - PubSub *pubsub.PubSub + BCfg *BuildCfg + Repo repo.Repo + Validator record.Validator + Host p2phost.Host + PubSub *pubsub.PubSub BaseRouting BaseRouting } @@ -553,7 +553,6 @@ func offlineNamesysCtor(rt routing.IpfsRouting, repo repo.Repo) (namesys.NameSys return namesys.NewNameSystem(rt, repo.Datastore(), 0), nil } - //////////// // IPFS services @@ -621,7 +620,7 @@ func ipnsRepublisher(lc lcProcess, cfg *iconfig.Config, namesys namesys.NameSyst } type discoveryHandler struct { - ctx context.Context + ctx context.Context host p2phost.Host } @@ -636,7 +635,7 @@ func (dh *discoveryHandler) HandlePeerFound(p pstore.PeerInfo) { func newDiscoveryHandler(lc fx.Lifecycle, host p2phost.Host) *discoveryHandler { return &discoveryHandler{ - ctx: lifecycleCtx(lc), + ctx: lifecycleCtx(lc), host: host, } } @@ -739,11 +738,6 @@ func files(lc fx.Lifecycle, repo repo.Repo, dag format.DAGService) (*mfs.Root, e return mfs.NewRoot(ctx, dag, nd, pf) } -// TODO !!!!!!!! -func bootstrap(n IpfsNode) error { - return n.Bootstrap(DefaultBootstrapConfig) -} - //////////// // Hacks @@ -765,7 +759,7 @@ func lifecycleCtx(lc fx.Lifecycle) context.Context { type lcProcess struct { fx.In - LC fx.Lifecycle + LC fx.Lifecycle Proc goprocess.Process }