Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
dc95f6c3
Commit
dc95f6c3
authored
Aug 10, 2018
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to use new Builder interface for creating CIDs.
parent
f84f499c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
23 deletions
+23
-23
hamt/hamt.go
hamt/hamt.go
+5
-5
importer/helpers/dagbuilder.go
importer/helpers/dagbuilder.go
+6
-6
importer/helpers/helpers.go
importer/helpers/helpers.go
+2
-2
io/directory.go
io/directory.go
+9
-9
mod/dagmodifier.go
mod/dagmodifier.go
+1
-1
No files found.
hamt/hamt.go
View file @
dc95f6c3
...
...
@@ -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
.
Set
Prefix
(
ds
.
prefix
)
out
.
Set
CidBuilder
(
ds
.
prefix
)
cindex
:=
0
// TODO: optimized 'for each set bit'
...
...
importer/helpers/dagbuilder.go
View file @
dc95f6c3
...
...
@@ -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
.
Set
Prefix
(
db
.
GetPrefix
())
node
.
dag
.
Set
CidBuilder
(
db
.
GetPrefix
())
node
.
file
=
ft
.
NewFSNode
(
fsNodeType
)
...
...
importer/helpers/helpers.go
View file @
dc95f6c3
...
...
@@ -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
.
Set
Prefix
(
prefix
)
func
(
n
*
UnixfsNode
)
SetPrefix
(
prefix
cid
.
Builder
)
{
n
.
node
.
Set
CidBuilder
(
prefix
)
}
// NumChildren returns the number of children referenced by this UnixfsNode.
...
...
io/directory.go
View file @
dc95f6c3
...
...
@@ -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
.
Set
Prefix
(
prefix
)
func
(
d
*
BasicDirectory
)
SetPrefix
(
prefix
cid
.
Builder
)
{
d
.
node
.
Set
CidBuilder
(
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
()
}
mod/dagmodifier.go
View file @
dc95f6c3
...
...
@@ -256,7 +256,7 @@ func (dm *DagModifier) modifyDag(n ipld.Node, offset uint64) (*cid.Cid, error) {
nd
:=
new
(
mdag
.
ProtoNode
)
nd
.
SetData
(
b
)
nd
.
Set
Prefix
(
&
nd0
.
Prefix
)
nd
.
Set
CidBuilder
(
nd0
.
CidBuilder
()
)
err
=
dm
.
dagserv
.
Add
(
dm
.
ctx
,
nd
)
if
err
!=
nil
{
return
nil
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment