From c02218e51ebca7903d507a1078acd7c369375e26 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Fri, 10 Aug 2018 16:09:09 -0400 Subject: [PATCH] Update to use new Builder interface for creating CIDs. --- hamt/hamt.go | 8 ++++---- importer/helpers/dagbuilder.go | 10 +++++----- importer/helpers/helpers.go | 2 +- io/directory.go | 16 ++++++++-------- mod/dagmodifier.go | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/hamt/hamt.go b/hamt/hamt.go index 6887a148d..4bb055b2f 100644 --- a/hamt/hamt.go +++ b/hamt/hamt.go @@ -52,7 +52,7 @@ type Shard struct { tableSize int tableSizeLg2 int - prefix *cid.Prefix + prefix cid.Builder hashFunc uint64 prefixPadStr string @@ -124,18 +124,18 @@ func NewHamtFromDag(dserv ipld.DAGService, nd ipld.Node) (*Shard, error) { ds.children = make([]child, len(pbnd.Links())) ds.bitfield.SetBytes(pbd.GetData()) ds.hashFunc = pbd.GetHashType() - ds.prefix = &ds.nd.Prefix + ds.prefix = ds.nd.Prefix() return ds, nil } // SetPrefix sets the CID Prefix -func (ds *Shard) SetPrefix(prefix *cid.Prefix) { +func (ds *Shard) SetPrefix(prefix cid.Builder) { ds.prefix = prefix } // Prefix gets the CID Prefix, may be nil if unset -func (ds *Shard) Prefix() *cid.Prefix { +func (ds *Shard) Prefix() cid.Builder { return ds.prefix } diff --git a/importer/helpers/dagbuilder.go b/importer/helpers/dagbuilder.go index 387b26304..a85dade17 100644 --- a/importer/helpers/dagbuilder.go +++ b/importer/helpers/dagbuilder.go @@ -26,7 +26,7 @@ type DagBuilderHelper struct { nextData []byte // the next item to return. maxlinks int batch *ipld.Batch - prefix *cid.Prefix + prefix cid.Builder // Filestore support variables. // ---------------------------- @@ -54,7 +54,7 @@ type DagBuilderParams struct { RawLeaves bool // CID Prefix to use if set - Prefix *cid.Prefix + Prefix cid.Builder // DAGService to write blocks to (required) Dagserv ipld.DAGService @@ -146,7 +146,7 @@ func (db *DagBuilderHelper) NewUnixfsNode() *UnixfsNode { } // GetPrefix returns the internal `cid.Prefix` set in the builder. -func (db *DagBuilderHelper) GetPrefix() *cid.Prefix { +func (db *DagBuilderHelper) GetPrefix() cid.Builder { return db.prefix } @@ -166,7 +166,7 @@ func (db *DagBuilderHelper) NewLeaf(data []byte) (*UnixfsNode, error) { raw: true, }, nil } - rawnode, err := dag.NewRawNodeWPrefix(data, *db.prefix) + rawnode, err := dag.NewRawNodeWPrefix(data, db.prefix) if err != nil { return nil, err } @@ -197,7 +197,7 @@ func (db *DagBuilderHelper) NewLeafNode(data []byte) (ipld.Node, error) { if db.prefix == nil { return dag.NewRawNode(data), nil } - rawnode, err := dag.NewRawNodeWPrefix(data, *db.prefix) + rawnode, err := dag.NewRawNodeWPrefix(data, db.prefix) if err != nil { return nil, err } diff --git a/importer/helpers/helpers.go b/importer/helpers/helpers.go index 6fb0f83c8..271e5c9a2 100644 --- a/importer/helpers/helpers.go +++ b/importer/helpers/helpers.go @@ -61,7 +61,7 @@ func NewUnixfsNodeFromDag(nd *dag.ProtoNode) (*UnixfsNode, error) { } // SetPrefix sets the CID Prefix -func (n *UnixfsNode) SetPrefix(prefix *cid.Prefix) { +func (n *UnixfsNode) SetPrefix(prefix cid.Builder) { n.node.SetPrefix(prefix) } diff --git a/io/directory.go b/io/directory.go index 89864566e..af76c423f 100644 --- a/io/directory.go +++ b/io/directory.go @@ -30,7 +30,7 @@ var DefaultShardWidth = 256 type Directory interface { // SetPrefix sets the CID prefix of the root node. - SetPrefix(*cid.Prefix) + SetPrefix(cid.Builder) // AddChild adds a (name, key) pair to the root node. AddChild(context.Context, string, ipld.Node) error @@ -52,7 +52,7 @@ type Directory interface { GetNode() (ipld.Node, error) // GetPrefix returns the CID Prefix used. - GetPrefix() *cid.Prefix + GetPrefix() cid.Builder } // TODO: Evaluate removing `dserv` from this layer and providing it in MFS. @@ -128,7 +128,7 @@ func NewDirectoryFromNode(dserv ipld.DAGService, node ipld.Node) (Directory, err } // SetPrefix implements the `Directory` interface. -func (d *BasicDirectory) SetPrefix(prefix *cid.Prefix) { +func (d *BasicDirectory) SetPrefix(prefix cid.Builder) { d.node.SetPrefix(prefix) } @@ -180,8 +180,8 @@ func (d *BasicDirectory) GetNode() (ipld.Node, error) { } // GetPrefix implements the `Directory` interface. -func (d *BasicDirectory) GetPrefix() *cid.Prefix { - return &d.node.Prefix +func (d *BasicDirectory) GetPrefix() cid.Builder { + return d.node.Prefix() } // SwitchToSharding returns a HAMT implementation of this directory. @@ -193,7 +193,7 @@ func (d *BasicDirectory) SwitchToSharding(ctx context.Context) (Directory, error if err != nil { return nil, err } - shard.SetPrefix(&d.node.Prefix) + shard.SetPrefix(d.node.Prefix()) hamtDir.shard = shard for _, lnk := range d.node.Links() { @@ -212,7 +212,7 @@ func (d *BasicDirectory) SwitchToSharding(ctx context.Context) (Directory, error } // SetPrefix implements the `Directory` interface. -func (d *HAMTDirectory) SetPrefix(prefix *cid.Prefix) { +func (d *HAMTDirectory) SetPrefix(prefix cid.Builder) { d.shard.SetPrefix(prefix) } @@ -252,6 +252,6 @@ func (d *HAMTDirectory) GetNode() (ipld.Node, error) { } // GetPrefix implements the `Directory` interface. -func (d *HAMTDirectory) GetPrefix() *cid.Prefix { +func (d *HAMTDirectory) GetPrefix() cid.Builder { return d.shard.Prefix() } diff --git a/mod/dagmodifier.go b/mod/dagmodifier.go index 09665b80c..f17efa503 100644 --- a/mod/dagmodifier.go +++ b/mod/dagmodifier.go @@ -256,7 +256,7 @@ func (dm *DagModifier) modifyDag(n ipld.Node, offset uint64) (*cid.Cid, error) { nd := new(mdag.ProtoNode) nd.SetData(b) - nd.SetPrefix(&nd0.Prefix) + nd.SetPrefix(nd0.Prefix()) err = dm.dagserv.Add(dm.ctx, nd) if err != nil { return nil, err