@cryptotaxi247 / kubo / commits / 48f7e1427

extract node interface

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Oct 14, 2016 at 07:53 UTC 48f7e14277146341079d9cad0cbaea0ed977c604
19 files changed +159 -199
core/commands/ls.go
+8 -6
@@ -12,6 +12,8 @@ import (
12 path "github.com/ipfs/go-ipfs/path"
13 unixfs "github.com/ipfs/go-ipfs/unixfs"
14 unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
15 +
16 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
17 )
18
19 type LsLink struct {
@@ -50,7 +52,7 @@ The JSON output contains type information.
52 cmds.BoolOption("resolve-type", "Resolve linked objects to find out their types.").Default(true),
53 },
54 Run: func(req cmds.Request, res cmds.Response) {
53 - node, err := req.InvocContext().GetNode()
55 + nd, err := req.InvocContext().GetNode()
56 if err != nil {
57 res.SetError(err, cmds.ErrNormal)
58 return
@@ -70,9 +72,9 @@ The JSON output contains type information.
72
73 paths := req.Arguments()
74
73 - var dagnodes []merkledag.Node
75 + var dagnodes []node.Node
76 for _, fpath := range paths {
75 - dagnode, err := core.Resolve(req.Context(), node, path.Path(fpath))
77 + dagnode, err := core.Resolve(req.Context(), nd, path.Path(fpath))
78 if err != nil {
79 res.SetError(err, cmds.ErrNormal)
80 return
@@ -90,8 +92,8 @@ The JSON output contains type information.
92 var linkNode *merkledag.ProtoNode
93 t := unixfspb.Data_DataType(-1)
94 linkKey := link.Cid
93 - if ok, err := node.Blockstore.Has(linkKey); ok && err == nil {
94 - b, err := node.Blockstore.Get(linkKey)
95 + if ok, err := nd.Blockstore.Has(linkKey); ok && err == nil {
96 + b, err := nd.Blockstore.Get(linkKey)
97 if err != nil {
98 res.SetError(err, cmds.ErrNormal)
99 return
@@ -104,7 +106,7 @@ The JSON output contains type information.
106 }
107
108 if linkNode == nil && resolve {
107 - nd, err := link.GetNode(req.Context(), node.DAG)
109 + nd, err := link.GetNode(req.Context(), nd.DAG)
110 if err != nil {
111 res.SetError(err, cmds.ErrNormal)
112 return
core/commands/object/object.go
+10 -9
@@ -19,6 +19,7 @@ import (
19 ft "github.com/ipfs/go-ipfs/unixfs"
20
21 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
22 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
23 )
24
25 // ErrObjectTooLarge is returned when too much data was read from stdin. current limit 2m
@@ -290,10 +291,10 @@ var ObjectStatCmd = &cmds.Command{
291
292 res.SetOutput(ns)
293 },
293 - Type: dag.NodeStat{},
294 + Type: node.NodeStat{},
295 Marshalers: cmds.MarshalerMap{
296 cmds.Text: func(res cmds.Response) (io.Reader, error) {
296 - ns := res.Output().(*dag.NodeStat)
297 + ns := res.Output().(*node.NodeStat)
298
299 buf := new(bytes.Buffer)
300 w := func(s string, n int) {
@@ -556,7 +557,7 @@ func getObjectEnc(o interface{}) objectEncoding {
557 return objectEncoding(v)
558 }
559
559 -func getOutput(dagnode dag.Node) (*Object, error) {
560 +func getOutput(dagnode node.Node) (*Object, error) {
561 c := dagnode.Cid()
562 output := &Object{
563 Hash: c.String(),
@@ -575,25 +576,25 @@ func getOutput(dagnode dag.Node) (*Object, error) {
576 }
577
578 // converts the Node object into a real dag.ProtoNode
578 -func deserializeNode(node *Node, dataFieldEncoding string) (*dag.ProtoNode, error) {
579 +func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error) {
580 dagnode := new(dag.ProtoNode)
581 switch dataFieldEncoding {
582 case "text":
582 - dagnode.SetData([]byte(node.Data))
583 + dagnode.SetData([]byte(nd.Data))
584 case "base64":
584 - data, _ := base64.StdEncoding.DecodeString(node.Data)
585 + data, _ := base64.StdEncoding.DecodeString(nd.Data)
586 dagnode.SetData(data)
587 default:
588 return nil, fmt.Errorf("Unkown data field encoding")
589 }
590
590 - dagnode.SetLinks(make([]*dag.Link, len(node.Links)))
591 - for i, link := range node.Links {
591 + dagnode.SetLinks(make([]*node.Link, len(nd.Links)))
592 + for i, link := range nd.Links {
593 c, err := cid.Decode(link.Hash)
594 if err != nil {
595 return nil, err
596 }
596 - dagnode.Links()[i] = &dag.Link{
597 + dagnode.Links()[i] = &node.Link{
598 Name: link.Name,
599 Size: link.Size,
600 Cid: c,
core/commands/refs.go
+6 -5
@@ -13,6 +13,7 @@ import (
13 path "github.com/ipfs/go-ipfs/path"
14
15 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
16 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
17 u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
18 )
19
@@ -195,8 +196,8 @@ var refsMarshallerMap = cmds.MarshalerMap{
196 },
197 }
198
198 -func objectsForPaths(ctx context.Context, n *core.IpfsNode, paths []string) ([]dag.Node, error) {
199 - objects := make([]dag.Node, len(paths))
199 +func objectsForPaths(ctx context.Context, n *core.IpfsNode, paths []string) ([]node.Node, error) {
200 + objects := make([]node.Node, len(paths))
201 for i, p := range paths {
202 o, err := core.Resolve(ctx, n, path.Path(p))
203 if err != nil {
@@ -225,14 +226,14 @@ type RefWriter struct {
226 }
227
228 // WriteRefs writes refs of the given object to the underlying writer.
228 -func (rw *RefWriter) WriteRefs(n dag.Node) (int, error) {
229 +func (rw *RefWriter) WriteRefs(n node.Node) (int, error) {
230 if rw.Recursive {
231 return rw.writeRefsRecursive(n)
232 }
233 return rw.writeRefsSingle(n)
234 }
235
235 -func (rw *RefWriter) writeRefsRecursive(n dag.Node) (int, error) {
236 +func (rw *RefWriter) writeRefsRecursive(n node.Node) (int, error) {
237 nc := n.Cid()
238
239 var count int
@@ -260,7 +261,7 @@ func (rw *RefWriter) writeRefsRecursive(n dag.Node) (int, error) {
261 return count, nil
262 }
263
263 -func (rw *RefWriter) writeRefsSingle(n dag.Node) (int, error) {
264 +func (rw *RefWriter) writeRefsSingle(n node.Node) (int, error) {
265 c := n.Cid()
266
267 if rw.skip(c) {
core/corerepo/pinning.go
+3 -3
@@ -14,18 +14,18 @@ objects.
14 package corerepo
15
16 import (
17 + "context"
18 "fmt"
19
20 "github.com/ipfs/go-ipfs/core"
20 - "github.com/ipfs/go-ipfs/merkledag"
21 path "github.com/ipfs/go-ipfs/path"
22
23 - context "context"
23 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
24 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
25 )
26
27 func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
28 - dagnodes := make([]merkledag.Node, 0)
28 + dagnodes := make([]node.Node, 0)
29 for _, fpath := range paths {
30 dagnode, err := core.Resolve(ctx, n, path.Path(fpath))
31 if err != nil {
core/pathresolver.go
+4 -4
@@ -1,14 +1,14 @@
1 package core
2
3 import (
4 + "context"
5 "errors"
6 "strings"
7
7 - context "context"
8 -
9 - merkledag "github.com/ipfs/go-ipfs/merkledag"
8 path "github.com/ipfs/go-ipfs/path"
9 +
10 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
11 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
12 )
13
14 // ErrNoNamesys is an explicit error for when an IPFS node doesn't
@@ -19,7 +19,7 @@ var ErrNoNamesys = errors.New(
19 // Resolve resolves the given path by parsing out protocol-specific
20 // entries (e.g. /ipns/<node-key>) and then going through the /ipfs/
21 // entries and returning the final merkledag node.
22 -func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (merkledag.Node, error) {
22 +func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (node.Node, error) {
23 if strings.HasPrefix(p.String(), "/ipns/") {
24 // resolve ipns paths
25
merkledag/coding.go
+3 -2
@@ -7,6 +7,7 @@ import (
7 pb "github.com/ipfs/go-ipfs/merkledag/pb"
8
9 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
10 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
11 u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
12 )
13
@@ -22,9 +23,9 @@ func (n *ProtoNode) unmarshal(encoded []byte) error {
23 }
24
25 pbnl := pbn.GetLinks()
25 - n.links = make([]*Link, len(pbnl))
26 + n.links = make([]*node.Link, len(pbnl))
27 for i, l := range pbnl {
27 - n.links[i] = &Link{Name: l.GetName(), Size: l.GetTsize()}
28 + n.links[i] = &node.Link{Name: l.GetName(), Size: l.GetTsize()}
29 c, err := cid.Cast(l.GetHash())
30 if err != nil {
31 return fmt.Errorf("Link hash #%d is not valid multihash. %v", i, err)
merkledag/merkledag.go
+21 -33
@@ -13,6 +13,7 @@ import (
13
14 logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
15 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
16 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
17 )
18
19 var log = logging.Logger("merkledag")
@@ -20,9 +21,9 @@ var ErrNotFound = fmt.Errorf("merkledag: not found")
21
22 // DAGService is an IPFS Merkle DAG service.
23 type DAGService interface {
23 - Add(Node) (*cid.Cid, error)
24 - Get(context.Context, *cid.Cid) (Node, error)
25 - Remove(Node) error
24 + Add(node.Node) (*cid.Cid, error)
25 + Get(context.Context, *cid.Cid) (node.Node, error)
26 + Remove(node.Node) error
27
28 // GetDAG returns, in order, all the single leve child
29 // nodes of the passed in node.
@@ -36,7 +37,7 @@ type DAGService interface {
37 type LinkService interface {
38 // Return all links for a node, may be more effect than
39 // calling Get in DAGService
39 - GetLinks(context.Context, *cid.Cid) ([]*Link, error)
40 + GetLinks(context.Context, *cid.Cid) ([]*node.Link, error)
41
42 GetOfflineLinkService() LinkService
43 }
@@ -45,19 +46,6 @@ func NewDAGService(bs bserv.BlockService) *dagService {
46 return &dagService{Blocks: bs}
47 }
48
48 -type Node interface {
49 - Resolve(path []string) (*Link, []string, error)
50 - Links() []*Link
51 - Tree() []string
52 -
53 - Stat() (*NodeStat, error)
54 - Size() (uint64, error)
55 - Cid() *cid.Cid
56 - Loggable() map[string]interface{}
57 - RawData() []byte
58 - String() string
59 -}
60 -
49 // dagService is an IPFS Merkle DAG service.
50 // - the root is virtual (like a forest)
51 // - stores nodes' data in a BlockService
@@ -68,7 +56,7 @@ type dagService struct {
56 }
57
58 // Add adds a node to the dagService, storing the block in the BlockService
71 -func (n *dagService) Add(nd Node) (*cid.Cid, error) {
59 +func (n *dagService) Add(nd node.Node) (*cid.Cid, error) {
60 if n == nil { // FIXME remove this assertion. protect with constructor invariant
61 return nil, fmt.Errorf("dagService is nil")
62 }
@@ -81,7 +69,7 @@ func (n *dagService) Batch() *Batch {
69 }
70
71 // Get retrieves a node from the dagService, fetching the block in the BlockService
84 -func (n *dagService) Get(ctx context.Context, c *cid.Cid) (Node, error) {
72 +func (n *dagService) Get(ctx context.Context, c *cid.Cid) (node.Node, error) {
73 if n == nil {
74 return nil, fmt.Errorf("dagService is nil")
75 }
@@ -97,7 +85,7 @@ func (n *dagService) Get(ctx context.Context, c *cid.Cid) (Node, error) {
85 return nil, fmt.Errorf("Failed to get block for %s: %v", c, err)
86 }
87
100 - var res Node
88 + var res node.Node
89 switch c.Type() {
90 case cid.Protobuf:
91 out, err := DecodeProtobuf(b.RawData())
@@ -116,7 +104,7 @@ func (n *dagService) Get(ctx context.Context, c *cid.Cid) (Node, error) {
104 return res, nil
105 }
106
119 -func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*Link, error) {
107 +func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*node.Link, error) {
108 node, err := n.Get(ctx, c)
109 if err != nil {
110 return nil, err
@@ -133,7 +121,7 @@ func (n *dagService) GetOfflineLinkService() LinkService {
121 }
122 }
123
136 -func (n *dagService) Remove(nd Node) error {
124 +func (n *dagService) Remove(nd node.Node) error {
125 return n.Blocks.DeleteBlock(nd)
126 }
127
@@ -155,7 +143,7 @@ func FindLinks(links []*cid.Cid, c *cid.Cid, start int) []int {
143 }
144
145 type NodeOption struct {
158 - Node Node
146 + Node node.Node
147 Err error
148 }
149
@@ -178,7 +166,7 @@ func (ds *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *Node
166
167 c := b.Cid()
168
181 - var nd Node
169 + var nd node.Node
170 switch c.Type() {
171 case cid.Protobuf:
172 decnd, err := DecodeProtobuf(b.RawData())
@@ -209,7 +197,7 @@ func (ds *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *Node
197 // GetDAG will fill out all of the links of the given Node.
198 // It returns a channel of nodes, which the caller can receive
199 // all the child nodes of 'root' on, in proper order.
212 -func GetDAG(ctx context.Context, ds DAGService, root Node) []NodeGetter {
200 +func GetDAG(ctx context.Context, ds DAGService, root node.Node) []NodeGetter {
201 var cids []*cid.Cid
202 for _, lnk := range root.Links() {
203 cids = append(cids, lnk.Cid)
@@ -281,16 +269,16 @@ func dedupeKeys(cids []*cid.Cid) []*cid.Cid {
269
270 func newNodePromise(ctx context.Context) NodeGetter {
271 return &nodePromise{
284 - recv: make(chan Node, 1),
272 + recv: make(chan node.Node, 1),
273 ctx: ctx,
274 err: make(chan error, 1),
275 }
276 }
277
278 type nodePromise struct {
291 - cache Node
279 + cache node.Node
280 clk sync.Mutex
293 - recv chan Node
281 + recv chan node.Node
282 ctx context.Context
283 err chan error
284 }
@@ -300,9 +288,9 @@ type nodePromise struct {
288 // from its internal channels, subsequent calls will return the
289 // cached node.
290 type NodeGetter interface {
303 - Get(context.Context) (Node, error)
291 + Get(context.Context) (node.Node, error)
292 Fail(err error)
305 - Send(Node)
293 + Send(node.Node)
294 }
295
296 func (np *nodePromise) Fail(err error) {
@@ -318,7 +306,7 @@ func (np *nodePromise) Fail(err error) {
306 np.err <- err
307 }
308
321 -func (np *nodePromise) Send(nd Node) {
309 +func (np *nodePromise) Send(nd node.Node) {
310 var already bool
311 np.clk.Lock()
312 if np.cache != nil {
@@ -334,7 +322,7 @@ func (np *nodePromise) Send(nd Node) {
322 np.recv <- nd
323 }
324
337 -func (np *nodePromise) Get(ctx context.Context) (Node, error) {
325 +func (np *nodePromise) Get(ctx context.Context) (node.Node, error) {
326 np.clk.Lock()
327 c := np.cache
328 np.clk.Unlock()
@@ -362,7 +350,7 @@ type Batch struct {
350 MaxSize int
351 }
352
365 -func (t *Batch) Add(nd Node) (*cid.Cid, error) {
353 +func (t *Batch) Add(nd node.Node) (*cid.Cid, error) {
354 t.blocks = append(t.blocks, nd)
355 t.size += len(nd.RawData())
356 if t.size > t.MaxSize {
merkledag/merkledag_test.go
+7 -6
@@ -2,6 +2,7 @@ package merkledag_test
2
3 import (
4 "bytes"
5 + "context"
6 "errors"
7 "fmt"
8 "io"
@@ -19,10 +20,10 @@ import (
20 mdpb "github.com/ipfs/go-ipfs/merkledag/pb"
21 dstest "github.com/ipfs/go-ipfs/merkledag/test"
22 uio "github.com/ipfs/go-ipfs/unixfs/io"
22 - key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
23
24 - "context"
24 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
25 + key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
26 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
27 u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
28 )
29
@@ -85,7 +86,7 @@ func SubtestNodeStat(t *testing.T, n *ProtoNode) {
86
87 k := n.Key()
88
88 - expected := NodeStat{
89 + expected := node.NodeStat{
90 NumLinks: len(n.Links()),
91 BlockSize: len(enc),
92 LinksSize: len(enc) - len(n.Data()), // includes framing.
@@ -206,7 +207,7 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
207 }
208 }
209
209 -func assertCanGet(t *testing.T, ds DAGService, n Node) {
210 +func assertCanGet(t *testing.T, ds DAGService, n node.Node) {
211 if _, err := ds.Get(context.Background(), n.Cid()); err != nil {
212 t.Fatal(err)
213 }
@@ -268,8 +269,8 @@ func TestEnumerateChildren(t *testing.T) {
269 t.Fatal(err)
270 }
271
271 - var traverse func(n Node)
272 - traverse = func(n Node) {
272 + var traverse func(n node.Node)
273 + traverse = func(n node.Node) {
274 // traverse dag and check
275 for _, lnk := range n.Links() {
276 c := lnk.Cid
merkledag/node.go
+22 -68
@@ -1,21 +1,22 @@
1 package merkledag
2
3 import (
4 - "fmt"
5 -
4 "context"
5 + "fmt"
6
7 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
8 mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash"
9 key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
10 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
11 )
12
13 +var ErrNotProtobuf = fmt.Errorf("expected protobuf dag node")
14 var ErrLinkNotFound = fmt.Errorf("no link by that name")
15
16 // Node represents a node in the IPFS Merkle DAG.
17 // nodes have opaque data and a set of navigable links.
18 type ProtoNode struct {
18 - links []*Link
19 + links []*node.Link
20 data []byte
21
22 // cache encoded/marshaled value
@@ -24,57 +25,12 @@ type ProtoNode struct {
25 cached *cid.Cid
26 }
27
27 -// NodeStat is a statistics object for a Node. Mostly sizes.
28 -type NodeStat struct {
29 - Hash string
30 - NumLinks int // number of links in link table
31 - BlockSize int // size of the raw, encoded data
32 - LinksSize int // size of the links segment
33 - DataSize int // size of the data segment
34 - CumulativeSize int // cumulative size of object and its references
35 -}
36 -
37 -func (ns NodeStat) String() string {
38 - f := "NodeStat{NumLinks: %d, BlockSize: %d, LinksSize: %d, DataSize: %d, CumulativeSize: %d}"
39 - return fmt.Sprintf(f, ns.NumLinks, ns.BlockSize, ns.LinksSize, ns.DataSize, ns.CumulativeSize)
40 -}
41 -
42 -// Link represents an IPFS Merkle DAG Link between Nodes.
43 -type Link struct {
44 - // utf string name. should be unique per object
45 - Name string // utf8
46 -
47 - // cumulative size of target object
48 - Size uint64
49 -
50 - // multihash of the target object
51 - Cid *cid.Cid
52 -}
53 -
54 -type LinkSlice []*Link
28 +type LinkSlice []*node.Link
29
30 func (ls LinkSlice) Len() int { return len(ls) }
31 func (ls LinkSlice) Swap(a, b int) { ls[a], ls[b] = ls[b], ls[a] }
32 func (ls LinkSlice) Less(a, b int) bool { return ls[a].Name < ls[b].Name }
33
60 -// MakeLink creates a link to the given node
61 -func MakeLink(n Node) (*Link, error) {
62 - s, err := n.Size()
63 - if err != nil {
64 - return nil, err
65 - }
66 -
67 - return &Link{
68 - Size: s,
69 - Cid: n.Cid(),
70 - }, nil
71 -}
72 -
73 -// GetNode returns the MDAG Node that this link points to
74 -func (l *Link) GetNode(ctx context.Context, serv DAGService) (Node, error) {
75 - return serv.Get(ctx, l.Cid)
76 -}
77 -
34 func NodeWithData(d []byte) *ProtoNode {
35 return &ProtoNode{data: d}
36 }
@@ -83,13 +39,13 @@ func NodeWithData(d []byte) *ProtoNode {
39 func (n *ProtoNode) AddNodeLink(name string, that *ProtoNode) error {
40 n.encoded = nil
41
86 - lnk, err := MakeLink(that)
87 -
88 - lnk.Name = name
42 + lnk, err := node.MakeLink(that)
43 if err != nil {
44 return err
45 }
46
47 + lnk.Name = name
48 +
49 n.AddRawLink(name, lnk)
50
51 return nil
@@ -97,9 +53,9 @@ func (n *ProtoNode) AddNodeLink(name string, that *ProtoNode) error {
53
54 // AddNodeLinkClean adds a link to another node. without keeping a reference to
55 // the child node
100 -func (n *ProtoNode) AddNodeLinkClean(name string, that Node) error {
56 +func (n *ProtoNode) AddNodeLinkClean(name string, that node.Node) error {
57 n.encoded = nil
102 - lnk, err := MakeLink(that)
58 + lnk, err := node.MakeLink(that)
59 if err != nil {
60 return err
61 }
@@ -109,9 +65,9 @@ func (n *ProtoNode) AddNodeLinkClean(name string, that Node) error {
65 }
66
67 // AddRawLink adds a copy of a link to this node
112 -func (n *ProtoNode) AddRawLink(name string, l *Link) error {
68 +func (n *ProtoNode) AddRawLink(name string, l *node.Link) error {
69 n.encoded = nil
114 - n.links = append(n.links, &Link{
70 + n.links = append(n.links, &node.Link{
71 Name: name,
72 Size: l.Size,
73 Cid: l.Cid,
@@ -123,7 +79,7 @@ func (n *ProtoNode) AddRawLink(name string, l *Link) error {
79 // Remove a link on this node by the given name
80 func (n *ProtoNode) RemoveNodeLink(name string) error {
81 n.encoded = nil
126 - good := make([]*Link, 0, len(n.links))
82 + good := make([]*node.Link, 0, len(n.links))
83 var found bool
84
85 for _, l := range n.links {
@@ -143,10 +99,10 @@ func (n *ProtoNode) RemoveNodeLink(name string) error {
99 }
100
101 // Return a copy of the link with given name
146 -func (n *ProtoNode) GetNodeLink(name string) (*Link, error) {
102 +func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error) {
103 for _, l := range n.links {
104 if l.Name == name {
149 - return &Link{
105 + return &node.Link{
106 Name: l.Name,
107 Size: l.Size,
108 Cid: l.Cid,
@@ -156,8 +112,6 @@ func (n *ProtoNode) GetNodeLink(name string) (*Link, error) {
112 return nil, ErrLinkNotFound
113 }
114
159 -var ErrNotProtobuf = fmt.Errorf("expected protobuf dag node")
160 -
115 func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds DAGService, name string) (*ProtoNode, error) {
116 nd, err := n.GetLinkedNode(ctx, ds, name)
117 if err != nil {
@@ -172,7 +126,7 @@ func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds DAGService, name
126 return pbnd, nil
127 }
128
175 -func (n *ProtoNode) GetLinkedNode(ctx context.Context, ds DAGService, name string) (Node, error) {
129 +func (n *ProtoNode) GetLinkedNode(ctx context.Context, ds DAGService, name string) (node.Node, error) {
130 lnk, err := n.GetNodeLink(name)
131 if err != nil {
132 return nil, err
@@ -191,7 +145,7 @@ func (n *ProtoNode) Copy() *ProtoNode {
145 }
146
147 if len(n.links) > 0 {
194 - nnode.links = make([]*Link, len(n.links))
148 + nnode.links = make([]*node.Link, len(n.links))
149 copy(nnode.links, n.links)
150 }
151 return nnode
@@ -238,7 +192,7 @@ func (n *ProtoNode) Size() (uint64, error) {
192 }
193
194 // Stat returns statistics on the node.
241 -func (n *ProtoNode) Stat() (*NodeStat, error) {
195 +func (n *ProtoNode) Stat() (*node.NodeStat, error) {
196 enc, err := n.EncodeProtobuf(false)
197 if err != nil {
198 return nil, err
@@ -249,7 +203,7 @@ func (n *ProtoNode) Stat() (*NodeStat, error) {
203 return nil, err
204 }
205
252 - return &NodeStat{
206 + return &node.NodeStat{
207 Hash: n.Key().B58String(),
208 NumLinks: len(n.links),
209 BlockSize: len(enc),
@@ -291,15 +245,15 @@ func (n *ProtoNode) Multihash() mh.Multihash {
245 return n.cached.Hash()
246 }
247
294 -func (n *ProtoNode) Links() []*Link {
248 +func (n *ProtoNode) Links() []*node.Link {
249 return n.links
250 }
251
298 -func (n *ProtoNode) SetLinks(links []*Link) {
252 +func (n *ProtoNode) SetLinks(links []*node.Link) {
253 n.links = links
254 }
255
302 -func (n *ProtoNode) Resolve(path []string) (*Link, []string, error) {
256 +func (n *ProtoNode) Resolve(path []string) (*node.Link, []string, error) {
257 if len(path) == 0 {
258 return nil, nil, fmt.Errorf("end of path, no more links to resolve")
259 }
merkledag/node_test.go
+17 -16
@@ -1,23 +1,24 @@
1 package merkledag_test
2
3 import (
4 + "context"
5 "testing"
6
7 . "github.com/ipfs/go-ipfs/merkledag"
8 mdtest "github.com/ipfs/go-ipfs/merkledag/test"
9
9 - "context"
10 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
11 )
12
13 func TestRemoveLink(t *testing.T) {
14 nd := &ProtoNode{}
14 - nd.SetLinks([]*Link{
15 - &Link{Name: "a"},
16 - &Link{Name: "b"},
17 - &Link{Name: "a"},
18 - &Link{Name: "a"},
19 - &Link{Name: "c"},
20 - &Link{Name: "a"},
15 + nd.SetLinks([]*node.Link{
16 + {Name: "a"},
17 + {Name: "b"},
18 + {Name: "a"},
19 + {Name: "a"},
20 + {Name: "c"},
21 + {Name: "a"},
22 })
23
24 err := nd.RemoveNodeLink("a")
@@ -65,10 +66,10 @@ func TestFindLink(t *testing.T) {
66 }
67
68 nd := &ProtoNode{}
68 - nd.SetLinks([]*Link{
69 - &Link{Name: "a", Cid: k},
70 - &Link{Name: "c", Cid: k},
71 - &Link{Name: "b", Cid: k},
69 + nd.SetLinks([]*node.Link{
70 + {Name: "a", Cid: k},
71 + {Name: "c", Cid: k},
72 + {Name: "b", Cid: k},
73 })
74
75 _, err = ds.Add(nd)
@@ -112,10 +113,10 @@ func TestFindLink(t *testing.T) {
113
114 func TestNodeCopy(t *testing.T) {
115 nd := &ProtoNode{}
115 - nd.SetLinks([]*Link{
116 - &Link{Name: "a"},
117 - &Link{Name: "c"},
118 - &Link{Name: "b"},
116 + nd.SetLinks([]*node.Link{
117 + {Name: "a"},
118 + {Name: "c"},
119 + {Name: "b"},
120 })
121
122 nd.SetData([]byte("testing"))
merkledag/traverse/traverse.go
+8 -9
@@ -2,11 +2,10 @@
2 package traverse
3
4 import (
5 - "errors"
6 -
5 "context"
6 + "errors"
7
9 - mdag "github.com/ipfs/go-ipfs/merkledag"
8 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
9 )
10
11 // Order is an identifier for traversal algorithm orders
@@ -20,7 +19,7 @@ const (
19
20 // Options specifies a series of traversal options
21 type Options struct {
23 - DAG mdag.DAGService // the dagservice to fetch nodes
22 + DAG node.NodeGetter // the dagservice to fetch nodes
23 Order Order // what order to traverse in
24 Func Func // the function to perform at each step
25 ErrFunc ErrFunc // see ErrFunc. Optional
@@ -30,7 +29,7 @@ type Options struct {
29
30 // State is a current traversal state
31 type State struct {
33 - Node mdag.Node
32 + Node node.Node
33 Depth int
34 }
35
@@ -39,7 +38,7 @@ type traversal struct {
38 seen map[string]struct{}
39 }
40
42 -func (t *traversal) shouldSkip(n mdag.Node) (bool, error) {
41 +func (t *traversal) shouldSkip(n node.Node) (bool, error) {
42 if t.opts.SkipDuplicates {
43 k := n.Cid()
44 if _, found := t.seen[k.KeyString()]; found {
@@ -59,9 +58,9 @@ func (t *traversal) callFunc(next State) error {
58 // stop processing. if it returns a nil node, just skip it.
59 //
60 // the error handling is a little complicated.
62 -func (t *traversal) getNode(link *mdag.Link) (mdag.Node, error) {
61 +func (t *traversal) getNode(link *node.Link) (node.Node, error) {
62
64 - getNode := func(l *mdag.Link) (mdag.Node, error) {
63 + getNode := func(l *node.Link) (node.Node, error) {
64 next, err := l.GetNode(context.TODO(), t.opts.DAG)
65 if err != nil {
66 return nil, err
@@ -99,7 +98,7 @@ type Func func(current State) error
98 //
99 type ErrFunc func(err error) error
100
102 -func Traverse(root mdag.Node, o Options) error {
101 +func Traverse(root node.Node, o Options) error {
102 t := traversal{
103 opts: o,
104 seen: map[string]struct{}{},
merkledag/traverse/traverse_test.go
+9 -7
@@ -7,6 +7,8 @@ import (
7
8 mdag "github.com/ipfs/go-ipfs/merkledag"
9 mdagtest "github.com/ipfs/go-ipfs/merkledag/test"
10 +
11 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
12 )
13
14 func TestDFSPreNoSkip(t *testing.T) {
@@ -321,7 +323,7 @@ func TestBFSSkip(t *testing.T) {
323 `))
324 }
325
324 -func testWalkOutputs(t *testing.T, root mdag.Node, opts Options, expect []byte) {
326 +func testWalkOutputs(t *testing.T, root node.Node, opts Options, expect []byte) {
327 expect = bytes.TrimLeft(expect, "\n")
328
329 buf := new(bytes.Buffer)
@@ -348,7 +350,7 @@ func testWalkOutputs(t *testing.T, root mdag.Node, opts Options, expect []byte)
350 }
351 }
352
351 -func newFan(t *testing.T, ds mdag.DAGService) mdag.Node {
353 +func newFan(t *testing.T, ds mdag.DAGService) node.Node {
354 a := mdag.NodeWithData([]byte("/a"))
355 addLink(t, ds, a, child(t, ds, a, "aa"))
356 addLink(t, ds, a, child(t, ds, a, "ab"))
@@ -357,7 +359,7 @@ func newFan(t *testing.T, ds mdag.DAGService) mdag.Node {
359 return a
360 }
361
360 -func newLinkedList(t *testing.T, ds mdag.DAGService) mdag.Node {
362 +func newLinkedList(t *testing.T, ds mdag.DAGService) node.Node {
363 a := mdag.NodeWithData([]byte("/a"))
364 aa := child(t, ds, a, "aa")
365 aaa := child(t, ds, aa, "aaa")
@@ -370,7 +372,7 @@ func newLinkedList(t *testing.T, ds mdag.DAGService) mdag.Node {
372 return a
373 }
374
373 -func newBinaryTree(t *testing.T, ds mdag.DAGService) mdag.Node {
375 +func newBinaryTree(t *testing.T, ds mdag.DAGService) node.Node {
376 a := mdag.NodeWithData([]byte("/a"))
377 aa := child(t, ds, a, "aa")
378 ab := child(t, ds, a, "ab")
@@ -383,7 +385,7 @@ func newBinaryTree(t *testing.T, ds mdag.DAGService) mdag.Node {
385 return a
386 }
387
386 -func newBinaryDAG(t *testing.T, ds mdag.DAGService) mdag.Node {
388 +func newBinaryDAG(t *testing.T, ds mdag.DAGService) node.Node {
389 a := mdag.NodeWithData([]byte("/a"))
390 aa := child(t, ds, a, "aa")
391 aaa := child(t, ds, aa, "aaa")
@@ -400,7 +402,7 @@ func newBinaryDAG(t *testing.T, ds mdag.DAGService) mdag.Node {
402 return a
403 }
404
403 -func addLink(t *testing.T, ds mdag.DAGService, a, b mdag.Node) {
405 +func addLink(t *testing.T, ds mdag.DAGService, a, b node.Node) {
406 to := string(a.(*mdag.ProtoNode).Data()) + "2" + string(b.(*mdag.ProtoNode).Data())
407 if _, err := ds.Add(b); err != nil {
408 t.Error(err)
@@ -410,6 +412,6 @@ func addLink(t *testing.T, ds mdag.DAGService, a, b mdag.Node) {
412 }
413 }
414
413 -func child(t *testing.T, ds mdag.DAGService, a mdag.Node, name string) mdag.Node {
415 +func child(t *testing.T, ds mdag.DAGService, a node.Node, name string) node.Node {
416 return mdag.NodeWithData([]byte(string(a.(*mdag.ProtoNode).Data()) + "/" + name))
417 }
mfs/mfs_test.go
+5 -4
@@ -2,6 +2,7 @@ package mfs
2
3 import (
4 "bytes"
5 + "context"
6 "errors"
7 "fmt"
8 "io"
@@ -23,8 +24,8 @@ import (
24 ft "github.com/ipfs/go-ipfs/unixfs"
25 uio "github.com/ipfs/go-ipfs/unixfs/io"
26
26 - "context"
27 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
28 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
29 u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
30 ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
31 dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync"
@@ -291,12 +292,12 @@ func TestDirectoryLoadFromDag(t *testing.T) {
292 dirhash := dir.Cid()
293
294 top := emptyDirNode()
294 - top.SetLinks([]*dag.Link{
295 - &dag.Link{
295 + top.SetLinks([]*node.Link{
296 + {
297 Name: "a",
298 Cid: fihash,
299 },
299 - &dag.Link{
300 + {
301 Name: "b",
302 Cid: dirhash,
303 },
package.json
+6
@@ -269,6 +269,12 @@
269 "hash": "QmTgcWwxttM74AY7UYA6qMP9WpzfBEjbZntx7ZWLttRMJJ",
270 "name": "floodsub",
271 "version": "0.7.0"
272 + },
273 + {
274 + "author": "whyrusleeping",
275 + "hash": "QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB",
276 + "name": "go-ipld-node",
277 + "version": "0.1.0"
278 }
279 ],
280 "gxVersion": "0.4.0",
path/resolver.go
+5 -4
@@ -11,6 +11,7 @@ import (
11
12 logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
13 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
14 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
15 )
16
17 var log = logging.Logger("path")
@@ -61,7 +62,7 @@ func SplitAbsPath(fpath Path) (*cid.Cid, []string, error) {
62
63 // ResolvePath fetches the node for given path. It returns the last item
64 // returned by ResolvePathComponents.
64 -func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (merkledag.Node, error) {
65 +func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (node.Node, error) {
66 // validate path
67 if err := fpath.IsValid(); err != nil {
68 return nil, err
@@ -77,7 +78,7 @@ func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (merkledag.Node,
78 // ResolvePathComponents fetches the nodes for each segment of the given path.
79 // It uses the first path component as a hash (key) of the first node, then
80 // resolves all other components walking the links, with ResolveLinks.
80 -func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]merkledag.Node, error) {
81 +func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]node.Node, error) {
82 h, parts, err := SplitAbsPath(fpath)
83 if err != nil {
84 return nil, err
@@ -99,9 +100,9 @@ func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]mer
100 //
101 // ResolveLinks(nd, []string{"foo", "bar", "baz"})
102 // would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links
102 -func (s *Resolver) ResolveLinks(ctx context.Context, ndd merkledag.Node, names []string) ([]merkledag.Node, error) {
103 +func (s *Resolver) ResolveLinks(ctx context.Context, ndd node.Node, names []string) ([]node.Node, error) {
104
104 - result := make([]merkledag.Node, 0, len(names)+1)
105 + result := make([]node.Node, 0, len(names)+1)
106 result = append(result, ndd)
107 nd := ndd // dup arg workaround
108
path/resolver_test.go
+4 -3
@@ -1,15 +1,16 @@
1 package path_test
2
3 import (
4 + "context"
5 "fmt"
6 "testing"
7
7 - context "context"
8 -
8 merkledag "github.com/ipfs/go-ipfs/merkledag"
9 dagmock "github.com/ipfs/go-ipfs/merkledag/test"
10 path "github.com/ipfs/go-ipfs/path"
11 +
12 key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
13 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
14 util "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
15 )
16
@@ -39,7 +40,7 @@ func TestRecurivePathResolution(t *testing.T) {
40 t.Fatal(err)
41 }
42
42 - for _, n := range []merkledag.Node{a, b, c} {
43 + for _, n := range []node.Node{a, b, c} {
44 _, err = dagService.Add(n)
45 if err != nil {
46 t.Fatal(err)
pin/pin.go
+8 -10
@@ -3,17 +3,17 @@
3 package pin
4
5 import (
6 + "context"
7 "fmt"
8 "os"
9 "sync"
10 "time"
11
12 mdag "github.com/ipfs/go-ipfs/merkledag"
12 - key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
13
14 - context "context"
14 logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
15 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
16 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
17 ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
18 )
19
@@ -83,7 +83,7 @@ func StringToPinMode(s string) (PinMode, bool) {
83 type Pinner interface {
84 IsPinned(*cid.Cid) (string, bool, error)
85 IsPinnedWithType(*cid.Cid, PinMode) (string, bool, error)
86 - Pin(context.Context, mdag.Node, bool) error
86 + Pin(context.Context, node.Node, bool) error
87 Unpin(context.Context, *cid.Cid, bool) error
88
89 // Check if a set of keys are pinned, more efficient than
@@ -162,11 +162,10 @@ func NewPinner(dstore ds.Datastore, serv, internal mdag.DAGService) Pinner {
162 }
163
164 // Pin the given node, optionally recursive
165 -func (p *pinner) Pin(ctx context.Context, node mdag.Node, recurse bool) error {
165 +func (p *pinner) Pin(ctx context.Context, node node.Node, recurse bool) error {
166 p.lock.Lock()
167 defer p.lock.Unlock()
168 c := node.Cid()
169 - k := key.Key(c.Hash())
169
170 if recurse {
171 if p.recursePin.Has(c) {
@@ -190,7 +189,7 @@ func (p *pinner) Pin(ctx context.Context, node mdag.Node, recurse bool) error {
189 }
190
191 if p.recursePin.Has(c) {
193 - return fmt.Errorf("%s already pinned recursively", k.B58String())
192 + return fmt.Errorf("%s already pinned recursively", c.String())
193 }
194
195 p.directPin.Add(c)
@@ -248,7 +247,6 @@ func (p *pinner) IsPinnedWithType(c *cid.Cid, mode PinMode) (string, bool, error
247 // isPinnedWithType is the implementation of IsPinnedWithType that does not lock.
248 // intended for use by other pinned methods that already take locks
249 func (p *pinner) isPinnedWithType(c *cid.Cid, mode PinMode) (string, bool, error) {
251 - k := key.Key(c.Hash())
250 switch mode {
251 case Any, Direct, Indirect, Recursive, Internal:
252 default:
@@ -279,7 +277,7 @@ func (p *pinner) isPinnedWithType(c *cid.Cid, mode PinMode) (string, bool, error
277
278 // Default is Indirect
279 for _, rc := range p.recursePin.Keys() {
282 - has, err := hasChild(p.dserv, rc, k)
280 + has, err := hasChild(p.dserv, rc, c)
281 if err != nil {
282 return "", false, err
283 }
@@ -521,14 +519,14 @@ func (p *pinner) PinWithMode(c *cid.Cid, mode PinMode) {
519 }
520 }
521
524 -func hasChild(ds mdag.LinkService, root *cid.Cid, child key.Key) (bool, error) {
522 +func hasChild(ds mdag.LinkService, root *cid.Cid, child *cid.Cid) (bool, error) {
523 links, err := ds.GetLinks(context.Background(), root)
524 if err != nil {
525 return false, err
526 }
527 for _, lnk := range links {
528 c := lnk.Cid
531 - if key.Key(c.Hash()) == child {
529 + if lnk.Cid.Equals(child) {
530 return true, nil
531 }
532
pin/set.go
+9 -7
@@ -12,9 +12,11 @@ import (
12
13 "github.com/ipfs/go-ipfs/merkledag"
14 "github.com/ipfs/go-ipfs/pin/internal/pb"
15 +
16 cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
17 "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
18 "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
19 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
20 )
21
22 const (
@@ -47,7 +49,7 @@ type itemIterator func() (c *cid.Cid, ok bool)
49 type keyObserver func(*cid.Cid)
50
51 type sortByHash struct {
50 - links []*merkledag.Link
52 + links []*node.Link
53 }
54
55 func (s sortByHash) Len() int {
@@ -67,9 +69,9 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
69 if err != nil {
70 return nil, err
71 }
70 - links := make([]*merkledag.Link, 0, defaultFanout+maxItems)
72 + links := make([]*node.Link, 0, defaultFanout+maxItems)
73 for i := 0; i < defaultFanout; i++ {
72 - links = append(links, &merkledag.Link{Cid: emptyKey})
74 + links = append(links, &node.Link{Cid: emptyKey})
75 }
76
77 // add emptyKey to our set of internal pinset objects
@@ -97,7 +99,7 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
99 break
100 }
101
100 - links = append(links, &merkledag.Link{Cid: k})
102 + links = append(links, &node.Link{Cid: k})
103 }
104
105 n.SetLinks(links)
@@ -159,7 +161,7 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
161 internalKeys(childKey)
162
163 // overwrite the 'empty key' in the existing links array
162 - n.Links()[h] = &merkledag.Link{
164 + n.Links()[h] = &node.Link{
165 Cid: childKey,
166 Size: size,
167 }
@@ -212,7 +214,7 @@ func writeHdr(n *merkledag.ProtoNode, hdr *pb.Set) error {
214 return nil
215 }
216
215 -type walkerFunc func(idx int, link *merkledag.Link) error
217 +type walkerFunc func(idx int, link *node.Link) error
218
219 func walkItems(ctx context.Context, dag merkledag.DAGService, n *merkledag.ProtoNode, fn walkerFunc, children keyObserver) error {
220 hdr, err := readHdr(n)
@@ -269,7 +271,7 @@ func loadSet(ctx context.Context, dag merkledag.DAGService, root *merkledag.Prot
271 }
272
273 var res []*cid.Cid
272 - walk := func(idx int, link *merkledag.Link) error {
274 + walk := func(idx int, link *node.Link) error {
275 res = append(res, link.Cid)
276 return nil
277 }
tar/format.go
+4 -3
@@ -3,6 +3,7 @@ package tarfmt
3 import (
4 "archive/tar"
5 "bytes"
6 + "context"
7 "errors"
8 "io"
9 "io/ioutil"
@@ -14,9 +15,9 @@ import (
15 dagutil "github.com/ipfs/go-ipfs/merkledag/utils"
16 path "github.com/ipfs/go-ipfs/path"
17 uio "github.com/ipfs/go-ipfs/unixfs/io"
17 - logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
18
19 - context "context"
19 + logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
20 + node "gx/ipfs/QmZx42H5khbVQhV5odp66TApShV4XCujYazcvYduZ4TroB/go-ipld-node"
21 )
22
23 var log = logging.Logger("tarfmt")
@@ -106,7 +107,7 @@ func escapePath(pth string) string {
107 }
108
109 type tarReader struct {
109 - links []*dag.Link
110 + links []*node.Link
111 ds dag.DAGService
112
113 childRead *tarReader