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-merkledag
Commits
ff4fe8a1
Commit
ff4fe8a1
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
4d2a12ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
22 deletions
+19
-22
coding.go
coding.go
+2
-5
node.go
node.go
+15
-12
raw.go
raw.go
+2
-5
No files found.
coding.go
View file @
ff4fe8a1
...
...
@@ -93,10 +93,7 @@ func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
}
if
n
.
cached
==
nil
{
if
n
.
Prefix
.
Codec
==
0
{
// unset
n
.
Prefix
=
v0CidPrefix
}
c
,
err
:=
n
.
Prefix
.
Sum
(
n
.
encoded
)
c
,
err
:=
n
.
Prefix
()
.
Sum
(
n
.
encoded
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -134,7 +131,7 @@ func DecodeProtobufBlock(b blocks.Block) (ipld.Node, error) {
}
decnd
.
cached
=
c
decnd
.
Prefix
=
c
.
Prefix
()
decnd
.
Set
Prefix
(
c
.
Prefix
()
)
return
decnd
,
nil
}
...
...
node.go
View file @
ff4fe8a1
...
...
@@ -27,8 +27,8 @@ type ProtoNode struct {
cached
*
cid
.
Cid
//
Prefix
specifies cid version and hashing function
Prefix
cid
.
Prefix
//
builder
specifies cid version and hashing function
builder
cid
.
Builder
}
var
v0CidPrefix
=
cid
.
Prefix
{
...
...
@@ -63,14 +63,21 @@ func PrefixForCidVersion(version int) (cid.Prefix, error) {
}
}
// Prefix returns the CID Prefix for this ProtoNode, it is never nil
func
(
n
*
ProtoNode
)
Prefix
()
cid
.
Builder
{
if
n
.
builder
==
nil
{
n
.
builder
=
v0CidPrefix
}
return
n
.
builder
}
// SetPrefix sets the CID prefix if it is non nil, if prefix is nil then
// it resets it the default value
func
(
n
*
ProtoNode
)
SetPrefix
(
prefix
*
cid
.
Prefix
)
{
func
(
n
*
ProtoNode
)
SetPrefix
(
prefix
cid
.
Builder
)
{
if
prefix
==
nil
{
n
.
Prefix
=
v0CidPrefix
n
.
builder
=
v0CidPrefix
}
else
{
n
.
Prefix
=
*
prefix
n
.
Prefix
.
Codec
=
cid
.
DagProtobuf
n
.
builder
=
prefix
.
WithCodec
(
cid
.
DagProtobuf
)
n
.
encoded
=
nil
n
.
cached
=
nil
}
...
...
@@ -191,7 +198,7 @@ func (n *ProtoNode) Copy() ipld.Node {
copy
(
nnode
.
links
,
n
.
links
)
}
nnode
.
Prefix
=
n
.
Prefix
nnode
.
builder
=
n
.
builder
return
nnode
}
...
...
@@ -301,11 +308,7 @@ func (n *ProtoNode) Cid() *cid.Cid {
return
n
.
cached
}
if
n
.
Prefix
.
Codec
==
0
{
n
.
SetPrefix
(
nil
)
}
c
,
err
:=
n
.
Prefix
.
Sum
(
n
.
RawData
())
c
,
err
:=
n
.
builder
.
Sum
(
n
.
RawData
())
if
err
!=
nil
{
// programmer error
err
=
fmt
.
Errorf
(
"invalid CID of length %d: %x: %v"
,
len
(
n
.
RawData
()),
n
.
RawData
(),
err
)
...
...
raw.go
View file @
ff4fe8a1
...
...
@@ -36,11 +36,8 @@ var _ ipld.DecodeBlockFunc = DecodeRawBlock
// NewRawNodeWPrefix creates a RawNode with the hash function
// specified in prefix.
func
NewRawNodeWPrefix
(
data
[]
byte
,
prefix
cid
.
Prefix
)
(
*
RawNode
,
error
)
{
prefix
.
Codec
=
cid
.
Raw
if
prefix
.
Version
==
0
{
prefix
.
Version
=
1
}
func
NewRawNodeWPrefix
(
data
[]
byte
,
prefix
cid
.
Builder
)
(
*
RawNode
,
error
)
{
prefix
=
prefix
.
WithCodec
(
cid
.
Raw
)
c
,
err
:=
prefix
.
Sum
(
data
)
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