diff --git a/core/builder.go b/core/builder.go index 64b4acee603c..60cf2cb23366 100644 --- a/core/builder.go +++ b/core/builder.go @@ -3,6 +3,7 @@ package core import ( "context" + "github.com/ipfs/go-metrics-interface" "go.uber.org/fx" "github.com/ipfs/go-ipfs/core/bootstrap" @@ -13,6 +14,8 @@ type BuildCfg = node.BuildCfg // Alias for compatibility until we properly refac // NewNode constructs and returns an IpfsNode using the given cfg. func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) { + ctx = metrics.CtxScope(ctx, "ipfs") + n := &IpfsNode{ ctx: ctx, } diff --git a/core/coreapi/path.go b/core/coreapi/path.go index ed3a39f954a3..f580f6545e8a 100644 --- a/core/coreapi/path.go +++ b/core/coreapi/path.go @@ -5,7 +5,7 @@ import ( "fmt" gopath "path" - node2 "github.com/ipfs/go-ipfs/namesys/resolve" + "github.com/ipfs/go-ipfs/namesys/resolve" "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" @@ -38,8 +38,8 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreifac } ipath := ipfspath.Path(p.String()) - ipath, err := node2.ResolveIPNS(ctx, api.namesys, ipath) - if err == node2.ErrNoNamesys { + ipath, err := resolve.ResolveIPNS(ctx, api.namesys, ipath) + if err == resolve.ErrNoNamesys { return nil, coreiface.ErrOffline } else if err != nil { return nil, err diff --git a/core/node/builder.go b/core/node/builder.go index 267aac895cef..e83fa764e1c7 100644 --- a/core/node/builder.go +++ b/core/node/builder.go @@ -1,17 +1,20 @@ package node import ( + "context" "crypto/rand" "encoding/base64" "errors" + "go.uber.org/fx" + + "github.com/ipfs/go-ipfs/repo" + ds "github.com/ipfs/go-datastore" dsync "github.com/ipfs/go-datastore/sync" cfg "github.com/ipfs/go-ipfs-config" ci "github.com/libp2p/go-libp2p-crypto" peer "github.com/libp2p/go-libp2p-peer" - - "github.com/ipfs/go-ipfs/repo" ) type BuildCfg struct { @@ -75,6 +78,42 @@ func (cfg *BuildCfg) fillDefaults() error { return nil } +func (cfg *BuildCfg) options(ctx context.Context) fx.Option { + err := cfg.fillDefaults() + if err != nil { + return fx.Error(err) + } + + 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 + }) + + return fx.Options( + repoOption, + hostOption, + routingOption, + metricsCtx, + ) +} + func defaultRepo(dstore repo.Datastore) (repo.Repo, error) { c := cfg.Config{} priv, pub, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, rand.Reader) diff --git a/core/node/core.go b/core/node/core.go index 160a833cf26f..7bba419e866f 100644 --- a/core/node/core.go +++ b/core/node/core.go @@ -4,24 +4,24 @@ import ( "context" "fmt" + "github.com/ipfs/go-ipfs/pin" + "github.com/ipfs/go-ipfs/repo" + "github.com/ipfs/go-bitswap" "github.com/ipfs/go-bitswap/network" "github.com/ipfs/go-blockservice" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" - blockstore "github.com/ipfs/go-ipfs-blockstore" - exchange "github.com/ipfs/go-ipfs-exchange-interface" - offline "github.com/ipfs/go-ipfs-exchange-offline" - format "github.com/ipfs/go-ipld-format" + "github.com/ipfs/go-ipfs-blockstore" + "github.com/ipfs/go-ipfs-exchange-interface" + "github.com/ipfs/go-ipfs-exchange-offline" + "github.com/ipfs/go-ipld-format" "github.com/ipfs/go-merkledag" "github.com/ipfs/go-mfs" "github.com/ipfs/go-unixfs" - host "github.com/libp2p/go-libp2p-host" - routing "github.com/libp2p/go-libp2p-routing" + "github.com/libp2p/go-libp2p-host" + "github.com/libp2p/go-libp2p-routing" "go.uber.org/fx" - - "github.com/ipfs/go-ipfs/pin" - "github.com/ipfs/go-ipfs/repo" ) func BlockServiceCtor(lc fx.Lifecycle, bs blockstore.Blockstore, rem exchange.Interface) blockservice.BlockService { diff --git a/core/node/groups.go b/core/node/groups.go index 7bcbbfb4b1f9..a568c3901d98 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -3,15 +3,14 @@ package node import ( "context" + "github.com/ipfs/go-ipfs/p2p" + "github.com/ipfs/go-ipfs/provider" + offline "github.com/ipfs/go-ipfs-exchange-offline" - "github.com/ipfs/go-metrics-interface" + offroute "github.com/ipfs/go-ipfs-routing/offline" "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( @@ -117,44 +116,9 @@ func IPFS(ctx context.Context, cfg *BuildCfg) fx.Option { 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, + cfg.options(ctx), + fx.Provide(baseProcess), fx.Invoke(setupSharding), diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index fb56d8353c40..a662ab22e78b 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -13,7 +13,7 @@ import ( core "github.com/ipfs/go-ipfs/core" namesys "github.com/ipfs/go-ipfs/namesys" - node2 "github.com/ipfs/go-ipfs/namesys/resolve" + resolve "github.com/ipfs/go-ipfs/namesys/resolve" dag "github.com/ipfs/go-merkledag" path "github.com/ipfs/go-path" @@ -98,7 +98,7 @@ func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string return nil, err } - node, err := node2.Resolve(ctx, ipfs.Namesys, ipfs.Resolver, p) + node, err := resolve.Resolve(ctx, ipfs.Namesys, ipfs.Resolver, p) switch err { case nil: case namesys.ErrResolveFailed: diff --git a/namesys/resolve/resolve.go b/namesys/resolve/resolve.go index bd1667fa41d7..128619c65b04 100644 --- a/namesys/resolve/resolve.go +++ b/namesys/resolve/resolve.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/ipfs/go-ipld-format" - log2 "github.com/ipfs/go-log" logging "github.com/ipfs/go-log" "github.com/ipfs/go-path" "github.com/ipfs/go-path/resolver" @@ -30,34 +29,34 @@ func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (pat // TODO(cryptix): we should be able to query the local cache for the path if nsys == nil { - evt.Append(log2.LoggableMap{"error": ErrNoNamesys.Error()}) + evt.Append(logging.LoggableMap{"error": ErrNoNamesys.Error()}) return "", ErrNoNamesys } seg := p.Segments() if len(seg) < 2 || seg[1] == "" { // just "/" without further segments - evt.Append(log2.LoggableMap{"error": path.ErrNoComponents.Error()}) + evt.Append(logging.LoggableMap{"error": path.ErrNoComponents.Error()}) return "", path.ErrNoComponents } extensions := seg[2:] resolvable, err := path.FromSegments("/", seg[0], seg[1]) if err != nil { - evt.Append(log2.LoggableMap{"error": err.Error()}) + evt.Append(logging.LoggableMap{"error": err.Error()}) return "", err } respath, err := nsys.Resolve(ctx, resolvable.String()) if err != nil { - evt.Append(log2.LoggableMap{"error": err.Error()}) + evt.Append(logging.LoggableMap{"error": err.Error()}) return "", err } segments := append(respath.Segments(), extensions...) p, err = path.FromSegments("/", segments...) if err != nil { - evt.Append(log2.LoggableMap{"error": err.Error()}) + evt.Append(logging.LoggableMap{"error": err.Error()}) return "", err } }