Skip to content

Commit 4132fbd

Browse files
committed
gx update and fix code to use new Cid type
1 parent 40ad25b commit 4132fbd

8 files changed

+57
-57
lines changed

coding.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (n *ProtoNode) getPBNode() *pb.PBNode {
6868
pbn.Links[i] = &pb.PBLink{}
6969
pbn.Links[i].Name = &l.Name
7070
pbn.Links[i].Tsize = &l.Size
71-
if l.Cid != nil {
71+
if l.Cid.Defined() {
7272
pbn.Links[i].Hash = l.Cid.Bytes()
7373
}
7474
}
@@ -84,15 +84,15 @@ func (n *ProtoNode) getPBNode() *pb.PBNode {
8484
func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
8585
sort.Stable(LinkSlice(n.links)) // keep links sorted
8686
if n.encoded == nil || force {
87-
n.cached = nil
87+
n.cached = cid.Undef
8888
var err error
8989
n.encoded, err = n.Marshal()
9090
if err != nil {
9191
return nil, err
9292
}
9393
}
9494

95-
if n.cached == nil {
95+
if !n.cached.Defined() {
9696
c, err := n.CidBuilder().Sum(n.encoded)
9797
if err != nil {
9898
return nil, err

errservice.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ func (cs *ErrorService) AddMany(ctx context.Context, nds []ipld.Node) error {
2525
}
2626

2727
// Get returns the cs.Err.
28-
func (cs *ErrorService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
28+
func (cs *ErrorService) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
2929
return nil, cs.Err
3030
}
3131

3232
// GetMany many returns the cs.Err.
33-
func (cs *ErrorService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption {
33+
func (cs *ErrorService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *ipld.NodeOption {
3434
ch := make(chan *ipld.NodeOption)
3535
close(ch)
3636
return ch
3737
}
3838

3939
// Remove returns the cs.Err.
40-
func (cs *ErrorService) Remove(ctx context.Context, c *cid.Cid) error {
40+
func (cs *ErrorService) Remove(ctx context.Context, c cid.Cid) error {
4141
return cs.Err
4242
}
4343

4444
// RemoveMany returns the cs.Err.
45-
func (cs *ErrorService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
45+
func (cs *ErrorService) RemoveMany(ctx context.Context, cids []cid.Cid) error {
4646
return cs.Err
4747
}

merkledag.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (n *dagService) AddMany(ctx context.Context, nds []ipld.Node) error {
6060
}
6161

6262
// Get retrieves a node from the dagService, fetching the block in the BlockService
63-
func (n *dagService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
63+
func (n *dagService) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
6464
if n == nil {
6565
return nil, fmt.Errorf("dagService is nil")
6666
}
@@ -81,7 +81,7 @@ func (n *dagService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
8181

8282
// GetLinks return the links for the node, the node doesn't necessarily have
8383
// to exist locally.
84-
func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
84+
func (n *dagService) GetLinks(ctx context.Context, c cid.Cid) ([]*ipld.Link, error) {
8585
if c.Type() == cid.Raw {
8686
return nil, nil
8787
}
@@ -92,7 +92,7 @@ func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*ipld.Link, er
9292
return node.Links(), nil
9393
}
9494

95-
func (n *dagService) Remove(ctx context.Context, c *cid.Cid) error {
95+
func (n *dagService) Remove(ctx context.Context, c cid.Cid) error {
9696
return n.Blocks.DeleteBlock(c)
9797
}
9898

@@ -101,7 +101,7 @@ func (n *dagService) Remove(ctx context.Context, c *cid.Cid) error {
101101
//
102102
// This operation is not atomic. If it returns an error, some nodes may or may
103103
// not have been removed.
104-
func (n *dagService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
104+
func (n *dagService) RemoveMany(ctx context.Context, cids []cid.Cid) error {
105105
// TODO(#4608): make this batch all the way down.
106106
for _, c := range cids {
107107
if err := n.Blocks.DeleteBlock(c); err != nil {
@@ -115,7 +115,7 @@ func (n *dagService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
115115
// the node, bypassing the LinkService. If the node does not exist
116116
// locally (and can not be retrieved) an error will be returned.
117117
func GetLinksDirect(serv ipld.NodeGetter) GetLinks {
118-
return func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
118+
return func(ctx context.Context, c cid.Cid) ([]*ipld.Link, error) {
119119
nd, err := serv.Get(ctx, c)
120120
if err != nil {
121121
if err == bserv.ErrNotFound {
@@ -132,7 +132,7 @@ type sesGetter struct {
132132
}
133133

134134
// Get gets a single node from the DAG.
135-
func (sg *sesGetter) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
135+
func (sg *sesGetter) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
136136
blk, err := sg.bs.GetBlock(ctx, c)
137137
switch err {
138138
case bserv.ErrNotFound:
@@ -147,7 +147,7 @@ func (sg *sesGetter) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
147147
}
148148

149149
// GetMany gets many nodes at once, batching the request if possible.
150-
func (sg *sesGetter) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.NodeOption {
150+
func (sg *sesGetter) GetMany(ctx context.Context, keys []cid.Cid) <-chan *ipld.NodeOption {
151151
return getNodesFromBG(ctx, sg.bs, keys)
152152
}
153153

@@ -157,15 +157,15 @@ func (n *dagService) Session(ctx context.Context) ipld.NodeGetter {
157157
}
158158

159159
// FetchGraph fetches all nodes that are children of the given node
160-
func FetchGraph(ctx context.Context, root *cid.Cid, serv ipld.DAGService) error {
160+
func FetchGraph(ctx context.Context, root cid.Cid, serv ipld.DAGService) error {
161161
return FetchGraphWithDepthLimit(ctx, root, -1, serv)
162162
}
163163

164164
// FetchGraphWithDepthLimit fetches all nodes that are children to the given
165165
// node down to the given depth. maxDetph=0 means "only fetch root",
166166
// maxDepth=1 means "fetch root and its direct children" and so on...
167167
// maxDepth=-1 means unlimited.
168-
func FetchGraphWithDepthLimit(ctx context.Context, root *cid.Cid, depthLim int, serv ipld.DAGService) error {
168+
func FetchGraphWithDepthLimit(ctx context.Context, root cid.Cid, depthLim int, serv ipld.DAGService) error {
169169
var ng ipld.NodeGetter = serv
170170
ds, ok := serv.(*dagService)
171171
if ok {
@@ -181,7 +181,7 @@ func FetchGraphWithDepthLimit(ctx context.Context, root *cid.Cid, depthLim int,
181181
// to explore deeper than before).
182182
// depthLim = -1 means we only return true if the element is not in the
183183
// set.
184-
visit := func(c *cid.Cid, depth int) bool {
184+
visit := func(c cid.Cid, depth int) bool {
185185
key := string(c.Bytes())
186186
oldDepth, ok := set[key]
187187

@@ -201,7 +201,7 @@ func FetchGraphWithDepthLimit(ctx context.Context, root *cid.Cid, depthLim int,
201201
return EnumerateChildrenAsyncDepth(ctx, GetLinksDirect(ng), root, 0, visit)
202202
}
203203

204-
visitProgress := func(c *cid.Cid, depth int) bool {
204+
visitProgress := func(c cid.Cid, depth int) bool {
205205
if visit(c, depth) {
206206
v.Increment()
207207
return true
@@ -216,11 +216,11 @@ func FetchGraphWithDepthLimit(ctx context.Context, root *cid.Cid, depthLim int,
216216
// This method may not return all requested nodes (and may or may not return an
217217
// error indicating that it failed to do so. It is up to the caller to verify
218218
// that it received all nodes.
219-
func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.NodeOption {
219+
func (n *dagService) GetMany(ctx context.Context, keys []cid.Cid) <-chan *ipld.NodeOption {
220220
return getNodesFromBG(ctx, n.Blocks, keys)
221221
}
222222

223-
func dedupKeys(keys []*cid.Cid) []*cid.Cid {
223+
func dedupKeys(keys []cid.Cid) []cid.Cid {
224224
set := cid.NewSet()
225225
for _, c := range keys {
226226
set.Add(c)
@@ -231,7 +231,7 @@ func dedupKeys(keys []*cid.Cid) []*cid.Cid {
231231
return set.Keys()
232232
}
233233

234-
func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid) <-chan *ipld.NodeOption {
234+
func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []cid.Cid) <-chan *ipld.NodeOption {
235235
keys = dedupKeys(keys)
236236

237237
out := make(chan *ipld.NodeOption, len(keys))
@@ -270,23 +270,23 @@ func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid)
270270

271271
// GetLinks is the type of function passed to the EnumerateChildren function(s)
272272
// for getting the children of an IPLD node.
273-
type GetLinks func(context.Context, *cid.Cid) ([]*ipld.Link, error)
273+
type GetLinks func(context.Context, cid.Cid) ([]*ipld.Link, error)
274274

275275
// GetLinksWithDAG returns a GetLinks function that tries to use the given
276276
// NodeGetter as a LinkGetter to get the children of a given IPLD node. This may
277277
// allow us to traverse the DAG without actually loading and parsing the node in
278278
// question (if we already have the links cached).
279279
func GetLinksWithDAG(ng ipld.NodeGetter) GetLinks {
280-
return func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
280+
return func(ctx context.Context, c cid.Cid) ([]*ipld.Link, error) {
281281
return ipld.GetLinks(ctx, ng, c)
282282
}
283283
}
284284

285285
// EnumerateChildren will walk the dag below the given root node and add all
286286
// unseen children to the passed in set.
287287
// TODO: parallelize to avoid disk latency perf hits?
288-
func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, visit func(*cid.Cid) bool) error {
289-
visitDepth := func(c *cid.Cid, depth int) bool {
288+
func EnumerateChildren(ctx context.Context, getLinks GetLinks, root cid.Cid, visit func(cid.Cid) bool) error {
289+
visitDepth := func(c cid.Cid, depth int) bool {
290290
return visit(c)
291291
}
292292

@@ -296,7 +296,7 @@ func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, vi
296296
// EnumerateChildrenDepth walks the dag below the given root and passes the
297297
// current depth to a given visit function. The visit function can be used to
298298
// limit DAG exploration.
299-
func EnumerateChildrenDepth(ctx context.Context, getLinks GetLinks, root *cid.Cid, depth int, visit func(*cid.Cid, int) bool) error {
299+
func EnumerateChildrenDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, depth int, visit func(cid.Cid, int) bool) error {
300300
links, err := getLinks(ctx, root)
301301
if err != nil {
302302
return err
@@ -348,8 +348,8 @@ var FetchGraphConcurrency = 8
348348
// fetches children in parallel.
349349
//
350350
// NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.
351-
func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c *cid.Cid, visit func(*cid.Cid) bool) error {
352-
visitDepth := func(c *cid.Cid, depth int) bool {
351+
func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c cid.Cid, visit func(cid.Cid) bool) error {
352+
visitDepth := func(c cid.Cid, depth int) bool {
353353
return visit(c)
354354
}
355355

@@ -360,9 +360,9 @@ func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c *cid.Cid,
360360
// that it fetches children in parallel (down to a maximum depth in the graph).
361361
//
362362
// NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.
363-
func EnumerateChildrenAsyncDepth(ctx context.Context, getLinks GetLinks, c *cid.Cid, startDepth int, visit func(*cid.Cid, int) bool) error {
363+
func EnumerateChildrenAsyncDepth(ctx context.Context, getLinks GetLinks, c cid.Cid, startDepth int, visit func(cid.Cid, int) bool) error {
364364
type cidDepth struct {
365-
cid *cid.Cid
365+
cid cid.Cid
366366
depth int
367367
}
368368

merkledag_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func makeDepthTestingGraph(t *testing.T, ds ipld.DAGService) ipld.Node {
5757
}
5858

5959
// Check that all children of root are in the given set and in the datastore
60-
func traverseAndCheck(t *testing.T, root ipld.Node, ds ipld.DAGService, hasF func(c *cid.Cid) bool) {
60+
func traverseAndCheck(t *testing.T, root ipld.Node, ds ipld.DAGService, hasF func(c cid.Cid) bool) {
6161
// traverse dag and check
6262
for _, lnk := range root.Links() {
6363
c := lnk.Cid
@@ -333,7 +333,7 @@ func TestFetchGraph(t *testing.T) {
333333

334334
offlineDS := NewDAGService(bs)
335335

336-
err = EnumerateChildren(context.Background(), offlineDS.GetLinks, root.Cid(), func(_ *cid.Cid) bool { return true })
336+
err = EnumerateChildren(context.Background(), offlineDS.GetLinks, root.Cid(), func(_ cid.Cid) bool { return true })
337337
if err != nil {
338338
t.Fatal(err)
339339
}
@@ -373,7 +373,7 @@ func TestFetchGraphWithDepthLimit(t *testing.T) {
373373
offlineDS := NewDAGService(bs)
374374

375375
set := make(map[string]int)
376-
visitF := func(c *cid.Cid, depth int) bool {
376+
visitF := func(c cid.Cid, depth int) bool {
377377
if tc.depthLim < 0 || depth <= tc.depthLim {
378378
set[string(c.Bytes())] = depth
379379
return true
@@ -649,7 +649,7 @@ func TestGetManyDuplicate(t *testing.T) {
649649
if err := srv.Add(ctx, nd); err != nil {
650650
t.Fatal(err)
651651
}
652-
nds := srv.GetMany(ctx, []*cid.Cid{nd.Cid(), nd.Cid(), nd.Cid()})
652+
nds := srv.GetMany(ctx, []cid.Cid{nd.Cid(), nd.Cid(), nd.Cid()})
653653
out, ok := <-nds
654654
if !ok {
655655
t.Fatal("expecting node foo")
@@ -742,7 +742,7 @@ func testProgressIndicator(t *testing.T, depth int) {
742742
}
743743
}
744744

745-
func mkDag(ds ipld.DAGService, depth int) (*cid.Cid, int) {
745+
func mkDag(ds ipld.DAGService, depth int) (cid.Cid, int) {
746746
ctx := context.Background()
747747

748748
totalChildren := 0

node.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ProtoNode struct {
2525
// cache encoded/marshaled value
2626
encoded []byte
2727

28-
cached *cid.Cid
28+
cached cid.Cid
2929

3030
// builder specifies cid version and hashing function
3131
builder cid.Builder
@@ -79,7 +79,7 @@ func (n *ProtoNode) SetCidBuilder(builder cid.Builder) {
7979
} else {
8080
n.builder = builder.WithCodec(cid.DagProtobuf)
8181
n.encoded = nil
82-
n.cached = nil
82+
n.cached = cid.Undef
8383
}
8484
}
8585

@@ -219,7 +219,7 @@ func (n *ProtoNode) Data() []byte {
219219
// SetData stores data in this nodes.
220220
func (n *ProtoNode) SetData(d []byte) {
221221
n.encoded = nil
222-
n.cached = nil
222+
n.cached = cid.Undef
223223
n.data = d
224224
}
225225

@@ -305,8 +305,8 @@ func (n *ProtoNode) MarshalJSON() ([]byte, error) {
305305

306306
// Cid returns the node's Cid, calculated according to its prefix
307307
// and raw data contents.
308-
func (n *ProtoNode) Cid() *cid.Cid {
309-
if n.encoded != nil && n.cached != nil {
308+
func (n *ProtoNode) Cid() cid.Cid {
309+
if n.encoded != nil && n.cached.Defined() {
310310
return n.cached
311311
}
312312

package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@
99
"gxDependencies": [
1010
{
1111
"author": "stebalien",
12-
"hash": "QmWAzSEoqZ6xU6pu8yL8e5WaMb7wtbfbhhN4p1DknUPtr3",
12+
"hash": "QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM",
1313
"name": "go-block-format",
14-
"version": "0.1.11"
14+
"version": "0.2.0"
1515
},
1616
{
1717
"author": "whyrusleeping",
18-
"hash": "QmepvyyduWnXHm1G7ybmGbJfQQHTAo36DjP2nvF7H7ZXjE",
18+
"hash": "QmPrv66vmh2P7vLJMpYx6DWLTNKvVB4Jdkyxs6V3QvWKvf",
1919
"name": "go-ipld-cbor",
20-
"version": "1.2.17"
20+
"version": "1.3.0"
2121
},
2222
{
2323
"author": "whyrusleeping",
24-
"hash": "QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb",
24+
"hash": "QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7",
2525
"name": "go-cid",
26-
"version": "0.8.0"
26+
"version": "0.9.0"
2727
},
2828
{
2929
"author": "whyrusleeping",
30-
"hash": "QmX5CsuHyVZeTLxgRSYkgLSDQKb9UjE8xnhQzCEJWWWFsC",
30+
"hash": "QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL",
3131
"name": "go-ipld-format",
32-
"version": "0.5.8"
32+
"version": "0.6.0"
3333
},
3434
{
3535
"author": "whyrusleeping",
@@ -39,9 +39,9 @@
3939
},
4040
{
4141
"author": "hsanjuan",
42-
"hash": "QmPuLWvxK1vg6ckKUpT53Dow9VLCcQGdL5Trwxa8PTLp7r",
42+
"hash": "QmXHsHBveZF6ueKzDJbUg476gmrbzoR1yijiyH5SZAEuDT",
4343
"name": "go-ipfs-exchange-offline",
44-
"version": "0.0.17"
44+
"version": "0.1.0"
4545
},
4646
{
4747
"author": "whyrusleeping",
@@ -51,9 +51,9 @@
5151
},
5252
{
5353
"author": "why",
54-
"hash": "QmQLG22wSEStiociTSKQpZAuuaaWoF1B3iKyjPFvWiTQ77",
54+
"hash": "QmYHXfGs5GVxXN233aFr5Jenvd7NG4qZ7pmjfyz7yvG93m",
5555
"name": "go-blockservice",
56-
"version": "1.0.14"
56+
"version": "1.1.0"
5757
}
5858
],
5959
"gxVersion": "0.12.1",

readonly_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestReadonlyProperties(t *testing.T) {
2222
NewRawNode([]byte("foo3")),
2323
NewRawNode([]byte("foo4")),
2424
}
25-
cids := []*cid.Cid{
25+
cids := []cid.Cid{
2626
nds[0].Cid(),
2727
nds[1].Cid(),
2828
nds[2].Cid(),

0 commit comments

Comments
 (0)