Commit dc95f6c3 authored by Kevin Atkinson's avatar Kevin Atkinson

Update to use new Builder interface for creating CIDs.

parent f84f499c
......@@ -52,7 +52,7 @@ type Shard struct {
tableSize int
tableSizeLg2 int
prefix *cid.Prefix
prefix cid.Builder
hashFunc uint64
prefixPadStr string
......@@ -124,25 +124,25 @@ 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.CidBuilder()
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
}
// Node serializes the HAMT structure into a merkledag node with unixfs formatting
func (ds *Shard) Node() (ipld.Node, error) {
out := new(dag.ProtoNode)
out.SetPrefix(ds.prefix)
out.SetCidBuilder(ds.prefix)
cindex := 0
// TODO: optimized 'for each set bit'
......
......@@ -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
}
......@@ -401,7 +401,7 @@ type FSNodeOverDag struct {
func (db *DagBuilderHelper) NewFSNodeOverDag(fsNodeType pb.Data_DataType) *FSNodeOverDag {
node := new(FSNodeOverDag)
node.dag = new(dag.ProtoNode)
node.dag.SetPrefix(db.GetPrefix())
node.dag.SetCidBuilder(db.GetPrefix())
node.file = ft.NewFSNode(fsNodeType)
......
......@@ -61,8 +61,8 @@ func NewUnixfsNodeFromDag(nd *dag.ProtoNode) (*UnixfsNode, error) {
}
// SetPrefix sets the CID Prefix
func (n *UnixfsNode) SetPrefix(prefix *cid.Prefix) {
n.node.SetPrefix(prefix)
func (n *UnixfsNode) SetPrefix(prefix cid.Builder) {
n.node.SetCidBuilder(prefix)
}
// NumChildren returns the number of children referenced by this UnixfsNode.
......
......@@ -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,8 +128,8 @@ func NewDirectoryFromNode(dserv ipld.DAGService, node ipld.Node) (Directory, err
}
// SetPrefix implements the `Directory` interface.
func (d *BasicDirectory) SetPrefix(prefix *cid.Prefix) {
d.node.SetPrefix(prefix)
func (d *BasicDirectory) SetPrefix(prefix cid.Builder) {
d.node.SetCidBuilder(prefix)
}
// AddChild implements the `Directory` interface. It adds (or replaces)
......@@ -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.CidBuilder()
}
// 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.CidBuilder())
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()
}
......@@ -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.SetCidBuilder(nd0.CidBuilder())
err = dm.dagserv.Add(dm.ctx, nd)
if err != nil {
return nil, err
......
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