Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Update to use new Builder interface for creating CIDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevina committed Aug 10, 2018
1 parent f222d6a commit c02218e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Shard struct {
tableSize int
tableSizeLg2 int

prefix *cid.Prefix
prefix cid.Builder
hashFunc uint64

prefixPadStr string
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions importer/helpers/dagbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// ----------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion importer/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
16 changes: 8 additions & 8 deletions io/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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.
Expand All @@ -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() {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion mod/dagmodifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c02218e

Please sign in to comment.