@cryptotaxi247 / kubo / commits / 34e8f3ee2

refactor(core): init DAG and its dependents in shared constructor

fix: remove merkledag import may need to squash this commit into the merkledag move commit

Brian Tiger Chow committed Jan 10, 2015 at 20:24 UTC 34e8f3ee26a0d13606763bafe082265c5d8efca7
2 files changed +11 -9
core/core.go
+11 -7
@@ -96,6 +96,17 @@ func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
96 if err != nil {
97 return nil, err
98 }
99 +
100 + // Need to make sure it's perfectly clear 1) which variables are expected
101 + // to be initialized at this point, and 2) which variables will be
102 + // initialized after this point.
103 +
104 + node.DAG = merkledag.NewDAGService(node.Blocks)
105 + node.Pinning, err = pin.LoadPinner(node.Datastore, node.DAG)
106 + if err != nil {
107 + node.Pinning = pin.NewPinner(node.Datastore, node.DAG)
108 + }
109 + node.Resolver = &path.Resolver{DAG: node.DAG}
110 return node, nil
111 }
112
@@ -161,13 +172,6 @@ func Standard(cfg *config.Config, online bool) ConfigOption {
172 return nil, debugerror.Wrap(err)
173 }
174
164 - n.DAG = merkledag.NewDAGService(n.Blocks)
165 - n.Pinning, err = pin.LoadPinner(n.Datastore, n.DAG)
166 - if err != nil {
167 - n.Pinning = pin.NewPinner(n.Datastore, n.DAG)
168 - }
169 - n.Resolver = &path.Resolver{DAG: n.DAG}
170 -
175 success = true
176 return n, nil
177 }
test/epictest/core.go
-2
@@ -10,7 +10,6 @@ import (
10 core "github.com/jbenet/go-ipfs/core"
11 bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
12 bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
13 - merkledag "github.com/jbenet/go-ipfs/merkledag"
13 host "github.com/jbenet/go-ipfs/p2p/host"
14 peer "github.com/jbenet/go-ipfs/p2p/peer"
15 dht "github.com/jbenet/go-ipfs/routing/dht"
@@ -47,7 +46,6 @@ func MocknetTestRepo(p peer.ID, h host.Host, conf testutil.LatencyConfig) core.C
46 Exchange: exch,
47 Datastore: ds,
48 PeerHost: h,
50 - DAG: merkledag.NewDAGService(blockservice),
49 Blocks: blockservice,
50 Routing: dhtt,
51 Identity: p,