@cryptotaxi247 / kubo / commits / e4cf66008

Move option parsing to BuildCfg; fix imports

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

Łukasz Magiera committed Apr 3, 2019 at 16:56 UTC e4cf66008f82243df91df3ec414b152c958fa0f0
8 files changed +70 -65
core/builder.go
+3
@@ -3,6 +3,7 @@ package core
3 import (
4 "context"
5
6 + "github.com/ipfs/go-metrics-interface"
7 "go.uber.org/fx"
8
9 "github.com/ipfs/go-ipfs/core/bootstrap"
@@ -13,6 +14,8 @@ type BuildCfg = node.BuildCfg // Alias for compatibility until we properly refac
14
15 // NewNode constructs and returns an IpfsNode using the given cfg.
16 func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
17 + ctx = metrics.CtxScope(ctx, "ipfs")
18 +
19 n := &IpfsNode{
20 ctx: ctx,
21 }
core/coreapi/path.go
+3 -3
@@ -5,7 +5,7 @@ import (
5 "fmt"
6 gopath "path"
7
8 - node2 "github.com/ipfs/go-ipfs/namesys/resolve"
8 + "github.com/ipfs/go-ipfs/namesys/resolve"
9
10 "github.com/ipfs/go-cid"
11 ipld "github.com/ipfs/go-ipld-format"
@@ -42,8 +42,8 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p path.Path) (path.Resolved
42 }
43
44 ipath := ipfspath.Path(p.String())
45 - ipath, err := node2.ResolveIPNS(ctx, api.namesys, ipath)
46 - if err == node2.ErrNoNamesys {
45 + ipath, err := resolve.ResolveIPNS(ctx, api.namesys, ipath)
46 + if err == resolve.ErrNoNamesys {
47 return nil, coreiface.ErrOffline
48 } else if err != nil {
49 return nil, err
core/node/builder.go
+41 -2
@@ -1,17 +1,20 @@
1 package node
2
3 import (
4 + "context"
5 "crypto/rand"
6 "encoding/base64"
7 "errors"
8
9 + "go.uber.org/fx"
10 +
11 + "github.com/ipfs/go-ipfs/repo"
12 +
13 ds "github.com/ipfs/go-datastore"
14 dsync "github.com/ipfs/go-datastore/sync"
15 cfg "github.com/ipfs/go-ipfs-config"
16 ci "github.com/libp2p/go-libp2p-crypto"
17 peer "github.com/libp2p/go-libp2p-peer"
13 -
14 - "github.com/ipfs/go-ipfs/repo"
18 )
19
20 type BuildCfg struct {
@@ -75,6 +78,42 @@ func (cfg *BuildCfg) fillDefaults() error {
78 return nil
79 }
80
81 +func (cfg *BuildCfg) options(ctx context.Context) fx.Option {
82 + err := cfg.fillDefaults()
83 + if err != nil {
84 + return fx.Error(err)
85 + }
86 +
87 + repoOption := fx.Provide(func(lc fx.Lifecycle) repo.Repo {
88 + lc.Append(fx.Hook{
89 + OnStop: func(ctx context.Context) error {
90 + return cfg.Repo.Close()
91 + },
92 + })
93 +
94 + return cfg.Repo
95 + })
96 +
97 + metricsCtx := fx.Provide(func() MetricsCtx {
98 + return MetricsCtx(ctx)
99 + })
100 +
101 + hostOption := fx.Provide(func() HostOption {
102 + return cfg.Host
103 + })
104 +
105 + routingOption := fx.Provide(func() RoutingOption {
106 + return cfg.Routing
107 + })
108 +
109 + return fx.Options(
110 + repoOption,
111 + hostOption,
112 + routingOption,
113 + metricsCtx,
114 + )
115 +}
116 +
117 func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
118 c := cfg.Config{}
119 priv, pub, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, rand.Reader)
core/node/core.go
+9 -9
@@ -4,24 +4,24 @@ import (
4 "context"
5 "fmt"
6
7 + "github.com/ipfs/go-ipfs/pin"
8 + "github.com/ipfs/go-ipfs/repo"
9 +
10 "github.com/ipfs/go-bitswap"
11 "github.com/ipfs/go-bitswap/network"
12 "github.com/ipfs/go-blockservice"
13 "github.com/ipfs/go-cid"
14 "github.com/ipfs/go-datastore"
12 - blockstore "github.com/ipfs/go-ipfs-blockstore"
13 - exchange "github.com/ipfs/go-ipfs-exchange-interface"
14 - offline "github.com/ipfs/go-ipfs-exchange-offline"
15 - format "github.com/ipfs/go-ipld-format"
15 + "github.com/ipfs/go-ipfs-blockstore"
16 + "github.com/ipfs/go-ipfs-exchange-interface"
17 + "github.com/ipfs/go-ipfs-exchange-offline"
18 + "github.com/ipfs/go-ipld-format"
19 "github.com/ipfs/go-merkledag"
20 "github.com/ipfs/go-mfs"
21 "github.com/ipfs/go-unixfs"
19 - host "github.com/libp2p/go-libp2p-host"
20 - routing "github.com/libp2p/go-libp2p-routing"
22 + "github.com/libp2p/go-libp2p-host"
23 + "github.com/libp2p/go-libp2p-routing"
24 "go.uber.org/fx"
22 -
23 - "github.com/ipfs/go-ipfs/pin"
24 - "github.com/ipfs/go-ipfs/repo"
25 )
26
27 func BlockServiceCtor(lc fx.Lifecycle, bs blockstore.Blockstore, rem exchange.Interface) blockservice.BlockService {
core/node/groups.go
+6 -43
@@ -3,15 +3,13 @@ package node
3 import (
4 "context"
5
6 + "github.com/ipfs/go-ipfs/p2p"
7 + "github.com/ipfs/go-ipfs/provider"
8 +
9 offline "github.com/ipfs/go-ipfs-exchange-offline"
7 - "github.com/ipfs/go-metrics-interface"
10 + offroute "github.com/ipfs/go-ipfs-routing/offline"
11 "github.com/ipfs/go-path/resolver"
12 "go.uber.org/fx"
10 -
11 - offroute "github.com/ipfs/go-ipfs-routing/offline"
12 - "github.com/ipfs/go-ipfs/p2p"
13 - "github.com/ipfs/go-ipfs/provider"
14 - "github.com/ipfs/go-ipfs/repo"
13 )
14
15 var BaseLibP2P = fx.Options(
@@ -117,44 +115,9 @@ func IPFS(ctx context.Context, cfg *BuildCfg) fx.Option {
115 cfg = new(BuildCfg)
116 }
117
120 - err := cfg.fillDefaults()
121 - if err != nil {
122 - return fx.Error(err)
123 - }
124 -
125 - ctx = metrics.CtxScope(ctx, "ipfs")
126 -
127 - repoOption := fx.Provide(func(lc fx.Lifecycle) repo.Repo {
128 - lc.Append(fx.Hook{
129 - OnStop: func(ctx context.Context) error {
130 - return cfg.Repo.Close()
131 - },
132 - })
133 -
134 - return cfg.Repo
135 - })
136 -
137 - metricsCtx := fx.Provide(func() MetricsCtx {
138 - return MetricsCtx(ctx)
139 - })
140 -
141 - hostOption := fx.Provide(func() HostOption {
142 - return cfg.Host
143 - })
144 -
145 - routingOption := fx.Provide(func() RoutingOption {
146 - return cfg.Routing
147 - })
148 -
149 - params := fx.Options(
150 - repoOption,
151 - hostOption,
152 - routingOption,
153 - metricsCtx,
154 - )
155 -
118 return fx.Options(
157 - params,
119 + cfg.options(ctx),
120 +
121 fx.Provide(baseProcess),
122 fx.Invoke(setupSharding),
123
core/node/libp2p.go
+1
@@ -123,6 +123,7 @@ type Libp2pOpts struct {
123 }
124
125 type PNetFingerprint []byte
126 +
127 func P2PPNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) {
128 swarmkey, err := repo.SwarmKey()
129 if err != nil || swarmkey == nil {
fuse/ipns/ipns_unix.go
+2 -2
@@ -13,7 +13,7 @@ import (
13
14 core "github.com/ipfs/go-ipfs/core"
15 namesys "github.com/ipfs/go-ipfs/namesys"
16 - node2 "github.com/ipfs/go-ipfs/namesys/resolve"
16 + resolve "github.com/ipfs/go-ipfs/namesys/resolve"
17
18 dag "github.com/ipfs/go-merkledag"
19 path "github.com/ipfs/go-path"
@@ -98,7 +98,7 @@ func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string
98 return nil, err
99 }
100
101 - node, err := node2.Resolve(ctx, ipfs.Namesys, ipfs.Resolver, p)
101 + node, err := resolve.Resolve(ctx, ipfs.Namesys, ipfs.Resolver, p)
102 switch err {
103 case nil:
104 case namesys.ErrResolveFailed:
namesys/resolve/resolve.go
+5 -6
@@ -6,7 +6,6 @@ import (
6 "strings"
7
8 "github.com/ipfs/go-ipld-format"
9 - log2 "github.com/ipfs/go-log"
9 logging "github.com/ipfs/go-log"
10 "github.com/ipfs/go-path"
11 "github.com/ipfs/go-path/resolver"
@@ -30,34 +29,34 @@ func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (pat
29
30 // TODO(cryptix): we should be able to query the local cache for the path
31 if nsys == nil {
33 - evt.Append(log2.LoggableMap{"error": ErrNoNamesys.Error()})
32 + evt.Append(logging.LoggableMap{"error": ErrNoNamesys.Error()})
33 return "", ErrNoNamesys
34 }
35
36 seg := p.Segments()
37
38 if len(seg) < 2 || seg[1] == "" { // just "/<protocol/>" without further segments
40 - evt.Append(log2.LoggableMap{"error": path.ErrNoComponents.Error()})
39 + evt.Append(logging.LoggableMap{"error": path.ErrNoComponents.Error()})
40 return "", path.ErrNoComponents
41 }
42
43 extensions := seg[2:]
44 resolvable, err := path.FromSegments("/", seg[0], seg[1])
45 if err != nil {
47 - evt.Append(log2.LoggableMap{"error": err.Error()})
46 + evt.Append(logging.LoggableMap{"error": err.Error()})
47 return "", err
48 }
49
50 respath, err := nsys.Resolve(ctx, resolvable.String())
51 if err != nil {
53 - evt.Append(log2.LoggableMap{"error": err.Error()})
52 + evt.Append(logging.LoggableMap{"error": err.Error()})
53 return "", err
54 }
55
56 segments := append(respath.Segments(), extensions...)
57 p, err = path.FromSegments("/", segments...)
58 if err != nil {
60 - evt.Append(log2.LoggableMap{"error": err.Error()})
59 + evt.Append(logging.LoggableMap{"error": err.Error()})
60 return "", err
61 }
62 }