Commit 4132fbd1 authored by Kevin Atkinson's avatar Kevin Atkinson

gx update and fix code to use new Cid type

parent 40ad25b0
......@@ -68,7 +68,7 @@ func (n *ProtoNode) getPBNode() *pb.PBNode {
pbn.Links[i] = &pb.PBLink{}
pbn.Links[i].Name = &l.Name
pbn.Links[i].Tsize = &l.Size
if l.Cid != nil {
if l.Cid.Defined() {
pbn.Links[i].Hash = l.Cid.Bytes()
}
}
......@@ -84,7 +84,7 @@ func (n *ProtoNode) getPBNode() *pb.PBNode {
func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
sort.Stable(LinkSlice(n.links)) // keep links sorted
if n.encoded == nil || force {
n.cached = nil
n.cached = cid.Undef
var err error
n.encoded, err = n.Marshal()
if err != nil {
......@@ -92,7 +92,7 @@ func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
}
}
if n.cached == nil {
if !n.cached.Defined() {
c, err := n.CidBuilder().Sum(n.encoded)
if err != nil {
return nil, err
......
......@@ -25,23 +25,23 @@ func (cs *ErrorService) AddMany(ctx context.Context, nds []ipld.Node) error {
}
// Get returns the cs.Err.
func (cs *ErrorService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
func (cs *ErrorService) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
return nil, cs.Err
}
// GetMany many returns the cs.Err.
func (cs *ErrorService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption {
func (cs *ErrorService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *ipld.NodeOption {
ch := make(chan *ipld.NodeOption)
close(ch)
return ch
}
// Remove returns the cs.Err.
func (cs *ErrorService) Remove(ctx context.Context, c *cid.Cid) error {
func (cs *ErrorService) Remove(ctx context.Context, c cid.Cid) error {
return cs.Err
}
// RemoveMany returns the cs.Err.
func (cs *ErrorService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
func (cs *ErrorService) RemoveMany(ctx context.Context, cids []cid.Cid) error {
return cs.Err
}
......@@ -60,7 +60,7 @@ func (n *dagService) AddMany(ctx context.Context, nds []ipld.Node) error {
}
// Get retrieves a node from the dagService, fetching the block in the BlockService
func (n *dagService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
func (n *dagService) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
if n == nil {
return nil, fmt.Errorf("dagService is nil")
}
......@@ -81,7 +81,7 @@ func (n *dagService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
// GetLinks return the links for the node, the node doesn't necessarily have
// to exist locally.
func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
func (n *dagService) GetLinks(ctx context.Context, c cid.Cid) ([]*ipld.Link, error) {
if c.Type() == cid.Raw {
return nil, nil
}
......@@ -92,7 +92,7 @@ func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*ipld.Link, er
return node.Links(), nil
}
func (n *dagService) Remove(ctx context.Context, c *cid.Cid) error {
func (n *dagService) Remove(ctx context.Context, c cid.Cid) error {
return n.Blocks.DeleteBlock(c)
}
......@@ -101,7 +101,7 @@ func (n *dagService) Remove(ctx context.Context, c *cid.Cid) error {
//
// This operation is not atomic. If it returns an error, some nodes may or may
// not have been removed.
func (n *dagService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
func (n *dagService) RemoveMany(ctx context.Context, cids []cid.Cid) error {
// TODO(#4608): make this batch all the way down.
for _, c := range cids {
if err := n.Blocks.DeleteBlock(c); err != nil {
......@@ -115,7 +115,7 @@ func (n *dagService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
// the node, bypassing the LinkService. If the node does not exist
// locally (and can not be retrieved) an error will be returned.
func GetLinksDirect(serv ipld.NodeGetter) GetLinks {
return func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
return func(ctx context.Context, c cid.Cid) ([]*ipld.Link, error) {
nd, err := serv.Get(ctx, c)
if err != nil {
if err == bserv.ErrNotFound {
......@@ -132,7 +132,7 @@ type sesGetter struct {
}
// Get gets a single node from the DAG.
func (sg *sesGetter) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
func (sg *sesGetter) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
blk, err := sg.bs.GetBlock(ctx, c)
switch err {
case bserv.ErrNotFound:
......@@ -147,7 +147,7 @@ func (sg *sesGetter) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
}
// GetMany gets many nodes at once, batching the request if possible.
func (sg *sesGetter) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.NodeOption {
func (sg *sesGetter) GetMany(ctx context.Context, keys []cid.Cid) <-chan *ipld.NodeOption {
return getNodesFromBG(ctx, sg.bs, keys)
}
......@@ -157,7 +157,7 @@ func (n *dagService) Session(ctx context.Context) ipld.NodeGetter {
}
// FetchGraph fetches all nodes that are children of the given node
func FetchGraph(ctx context.Context, root *cid.Cid, serv ipld.DAGService) error {
func FetchGraph(ctx context.Context, root cid.Cid, serv ipld.DAGService) error {
return FetchGraphWithDepthLimit(ctx, root, -1, serv)
}
......@@ -165,7 +165,7 @@ func FetchGraph(ctx context.Context, root *cid.Cid, serv ipld.DAGService) error
// node down to the given depth. maxDetph=0 means "only fetch root",
// maxDepth=1 means "fetch root and its direct children" and so on...
// maxDepth=-1 means unlimited.
func FetchGraphWithDepthLimit(ctx context.Context, root *cid.Cid, depthLim int, serv ipld.DAGService) error {
func FetchGraphWithDepthLimit(ctx context.Context, root cid.Cid, depthLim int, serv ipld.DAGService) error {
var ng ipld.NodeGetter = serv
ds, ok := serv.(*dagService)
if ok {
......@@ -181,7 +181,7 @@ func FetchGraphWithDepthLimit(ctx context.Context, root *cid.Cid, depthLim int,
// to explore deeper than before).
// depthLim = -1 means we only return true if the element is not in the
// set.
visit := func(c *cid.Cid, depth int) bool {
visit := func(c cid.Cid, depth int) bool {
key := string(c.Bytes())
oldDepth, ok := set[key]
......@@ -201,7 +201,7 @@ func FetchGraphWithDepthLimit(ctx context.Context, root *cid.Cid, depthLim int,
return EnumerateChildrenAsyncDepth(ctx, GetLinksDirect(ng), root, 0, visit)
}
visitProgress := func(c *cid.Cid, depth int) bool {
visitProgress := func(c cid.Cid, depth int) bool {
if visit(c, depth) {
v.Increment()
return true
......@@ -216,11 +216,11 @@ func FetchGraphWithDepthLimit(ctx context.Context, root *cid.Cid, depthLim int,
// This method may not return all requested nodes (and may or may not return an
// error indicating that it failed to do so. It is up to the caller to verify
// that it received all nodes.
func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.NodeOption {
func (n *dagService) GetMany(ctx context.Context, keys []cid.Cid) <-chan *ipld.NodeOption {
return getNodesFromBG(ctx, n.Blocks, keys)
}
func dedupKeys(keys []*cid.Cid) []*cid.Cid {
func dedupKeys(keys []cid.Cid) []cid.Cid {
set := cid.NewSet()
for _, c := range keys {
set.Add(c)
......@@ -231,7 +231,7 @@ func dedupKeys(keys []*cid.Cid) []*cid.Cid {
return set.Keys()
}
func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid) <-chan *ipld.NodeOption {
func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []cid.Cid) <-chan *ipld.NodeOption {
keys = dedupKeys(keys)
out := make(chan *ipld.NodeOption, len(keys))
......@@ -270,14 +270,14 @@ func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid)
// GetLinks is the type of function passed to the EnumerateChildren function(s)
// for getting the children of an IPLD node.
type GetLinks func(context.Context, *cid.Cid) ([]*ipld.Link, error)
type GetLinks func(context.Context, cid.Cid) ([]*ipld.Link, error)
// GetLinksWithDAG returns a GetLinks function that tries to use the given
// NodeGetter as a LinkGetter to get the children of a given IPLD node. This may
// allow us to traverse the DAG without actually loading and parsing the node in
// question (if we already have the links cached).
func GetLinksWithDAG(ng ipld.NodeGetter) GetLinks {
return func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
return func(ctx context.Context, c cid.Cid) ([]*ipld.Link, error) {
return ipld.GetLinks(ctx, ng, c)
}
}
......@@ -285,8 +285,8 @@ func GetLinksWithDAG(ng ipld.NodeGetter) GetLinks {
// EnumerateChildren will walk the dag below the given root node and add all
// unseen children to the passed in set.
// TODO: parallelize to avoid disk latency perf hits?
func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, visit func(*cid.Cid) bool) error {
visitDepth := func(c *cid.Cid, depth int) bool {
func EnumerateChildren(ctx context.Context, getLinks GetLinks, root cid.Cid, visit func(cid.Cid) bool) error {
visitDepth := func(c cid.Cid, depth int) bool {
return visit(c)
}
......@@ -296,7 +296,7 @@ func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, vi
// EnumerateChildrenDepth walks the dag below the given root and passes the
// current depth to a given visit function. The visit function can be used to
// limit DAG exploration.
func EnumerateChildrenDepth(ctx context.Context, getLinks GetLinks, root *cid.Cid, depth int, visit func(*cid.Cid, int) bool) error {
func EnumerateChildrenDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, depth int, visit func(cid.Cid, int) bool) error {
links, err := getLinks(ctx, root)
if err != nil {
return err
......@@ -348,8 +348,8 @@ var FetchGraphConcurrency = 8
// fetches children in parallel.
//
// NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.
func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c *cid.Cid, visit func(*cid.Cid) bool) error {
visitDepth := func(c *cid.Cid, depth int) bool {
func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c cid.Cid, visit func(cid.Cid) bool) error {
visitDepth := func(c cid.Cid, depth int) bool {
return visit(c)
}
......@@ -360,9 +360,9 @@ func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c *cid.Cid,
// that it fetches children in parallel (down to a maximum depth in the graph).
//
// NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.
func EnumerateChildrenAsyncDepth(ctx context.Context, getLinks GetLinks, c *cid.Cid, startDepth int, visit func(*cid.Cid, int) bool) error {
func EnumerateChildrenAsyncDepth(ctx context.Context, getLinks GetLinks, c cid.Cid, startDepth int, visit func(cid.Cid, int) bool) error {
type cidDepth struct {
cid *cid.Cid
cid cid.Cid
depth int
}
......
......@@ -57,7 +57,7 @@ func makeDepthTestingGraph(t *testing.T, ds ipld.DAGService) ipld.Node {
}
// Check that all children of root are in the given set and in the datastore
func traverseAndCheck(t *testing.T, root ipld.Node, ds ipld.DAGService, hasF func(c *cid.Cid) bool) {
func traverseAndCheck(t *testing.T, root ipld.Node, ds ipld.DAGService, hasF func(c cid.Cid) bool) {
// traverse dag and check
for _, lnk := range root.Links() {
c := lnk.Cid
......@@ -333,7 +333,7 @@ func TestFetchGraph(t *testing.T) {
offlineDS := NewDAGService(bs)
err = EnumerateChildren(context.Background(), offlineDS.GetLinks, root.Cid(), func(_ *cid.Cid) bool { return true })
err = EnumerateChildren(context.Background(), offlineDS.GetLinks, root.Cid(), func(_ cid.Cid) bool { return true })
if err != nil {
t.Fatal(err)
}
......@@ -373,7 +373,7 @@ func TestFetchGraphWithDepthLimit(t *testing.T) {
offlineDS := NewDAGService(bs)
set := make(map[string]int)
visitF := func(c *cid.Cid, depth int) bool {
visitF := func(c cid.Cid, depth int) bool {
if tc.depthLim < 0 || depth <= tc.depthLim {
set[string(c.Bytes())] = depth
return true
......@@ -649,7 +649,7 @@ func TestGetManyDuplicate(t *testing.T) {
if err := srv.Add(ctx, nd); err != nil {
t.Fatal(err)
}
nds := srv.GetMany(ctx, []*cid.Cid{nd.Cid(), nd.Cid(), nd.Cid()})
nds := srv.GetMany(ctx, []cid.Cid{nd.Cid(), nd.Cid(), nd.Cid()})
out, ok := <-nds
if !ok {
t.Fatal("expecting node foo")
......@@ -742,7 +742,7 @@ func testProgressIndicator(t *testing.T, depth int) {
}
}
func mkDag(ds ipld.DAGService, depth int) (*cid.Cid, int) {
func mkDag(ds ipld.DAGService, depth int) (cid.Cid, int) {
ctx := context.Background()
totalChildren := 0
......
......@@ -25,7 +25,7 @@ type ProtoNode struct {
// cache encoded/marshaled value
encoded []byte
cached *cid.Cid
cached cid.Cid
// builder specifies cid version and hashing function
builder cid.Builder
......@@ -79,7 +79,7 @@ func (n *ProtoNode) SetCidBuilder(builder cid.Builder) {
} else {
n.builder = builder.WithCodec(cid.DagProtobuf)
n.encoded = nil
n.cached = nil
n.cached = cid.Undef
}
}
......@@ -219,7 +219,7 @@ func (n *ProtoNode) Data() []byte {
// SetData stores data in this nodes.
func (n *ProtoNode) SetData(d []byte) {
n.encoded = nil
n.cached = nil
n.cached = cid.Undef
n.data = d
}
......@@ -305,8 +305,8 @@ func (n *ProtoNode) MarshalJSON() ([]byte, error) {
// Cid returns the node's Cid, calculated according to its prefix
// and raw data contents.
func (n *ProtoNode) Cid() *cid.Cid {
if n.encoded != nil && n.cached != nil {
func (n *ProtoNode) Cid() cid.Cid {
if n.encoded != nil && n.cached.Defined() {
return n.cached
}
......
......@@ -9,27 +9,27 @@
"gxDependencies": [
{
"author": "stebalien",
"hash": "QmWAzSEoqZ6xU6pu8yL8e5WaMb7wtbfbhhN4p1DknUPtr3",
"hash": "QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM",
"name": "go-block-format",
"version": "0.1.11"
"version": "0.2.0"
},
{
"author": "whyrusleeping",
"hash": "QmepvyyduWnXHm1G7ybmGbJfQQHTAo36DjP2nvF7H7ZXjE",
"hash": "QmPrv66vmh2P7vLJMpYx6DWLTNKvVB4Jdkyxs6V3QvWKvf",
"name": "go-ipld-cbor",
"version": "1.2.17"
"version": "1.3.0"
},
{
"author": "whyrusleeping",
"hash": "QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb",
"hash": "QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7",
"name": "go-cid",
"version": "0.8.0"
"version": "0.9.0"
},
{
"author": "whyrusleeping",
"hash": "QmX5CsuHyVZeTLxgRSYkgLSDQKb9UjE8xnhQzCEJWWWFsC",
"hash": "QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL",
"name": "go-ipld-format",
"version": "0.5.8"
"version": "0.6.0"
},
{
"author": "whyrusleeping",
......@@ -39,9 +39,9 @@
},
{
"author": "hsanjuan",
"hash": "QmPuLWvxK1vg6ckKUpT53Dow9VLCcQGdL5Trwxa8PTLp7r",
"hash": "QmXHsHBveZF6ueKzDJbUg476gmrbzoR1yijiyH5SZAEuDT",
"name": "go-ipfs-exchange-offline",
"version": "0.0.17"
"version": "0.1.0"
},
{
"author": "whyrusleeping",
......@@ -51,9 +51,9 @@
},
{
"author": "why",
"hash": "QmQLG22wSEStiociTSKQpZAuuaaWoF1B3iKyjPFvWiTQ77",
"hash": "QmYHXfGs5GVxXN233aFr5Jenvd7NG4qZ7pmjfyz7yvG93m",
"name": "go-blockservice",
"version": "1.0.14"
"version": "1.1.0"
}
],
"gxVersion": "0.12.1",
......
......@@ -22,7 +22,7 @@ func TestReadonlyProperties(t *testing.T) {
NewRawNode([]byte("foo3")),
NewRawNode([]byte("foo4")),
}
cids := []*cid.Cid{
cids := []cid.Cid{
nds[0].Cid(),
nds[1].Cid(),
nds[2].Cid(),
......
......@@ -27,21 +27,21 @@ func (cs *ComboService) AddMany(ctx context.Context, nds []ipld.Node) error {
}
// Get fetches a node using the Read DAGService.
func (cs *ComboService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
func (cs *ComboService) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
return cs.Read.Get(ctx, c)
}
// GetMany fetches nodes using the Read DAGService.
func (cs *ComboService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption {
func (cs *ComboService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *ipld.NodeOption {
return cs.Read.GetMany(ctx, cids)
}
// Remove deletes a node using the Write DAGService.
func (cs *ComboService) Remove(ctx context.Context, c *cid.Cid) error {
func (cs *ComboService) Remove(ctx context.Context, c cid.Cid) error {
return cs.Write.Remove(ctx, c)
}
// RemoveMany deletes nodes using the Write DAGService.
func (cs *ComboService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
func (cs *ComboService) RemoveMany(ctx context.Context, cids []cid.Cid) error {
return cs.Write.RemoveMany(ctx, cids)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment