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
f8a265e7
Commit
f8a265e7
authored
Mar 02, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adder: add support for using CidV1
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
90386a37
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
3 deletions
+30
-3
coding.go
coding.go
+1
-1
node.go
node.go
+29
-2
No files found.
coding.go
View file @
f8a265e7
...
@@ -86,7 +86,7 @@ func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
...
@@ -86,7 +86,7 @@ func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
if
n
.
cached
==
nil
{
if
n
.
cached
==
nil
{
if
n
.
Prefix
.
Codec
==
0
{
// unset
if
n
.
Prefix
.
Codec
==
0
{
// unset
n
.
Prefix
=
default
CidPrefix
n
.
Prefix
=
v0
CidPrefix
}
}
c
,
err
:=
n
.
Prefix
.
Sum
(
n
.
encoded
)
c
,
err
:=
n
.
Prefix
.
Sum
(
n
.
encoded
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
node.go
View file @
f8a265e7
...
@@ -28,13 +28,37 @@ type ProtoNode struct {
...
@@ -28,13 +28,37 @@ type ProtoNode struct {
Prefix
cid
.
Prefix
Prefix
cid
.
Prefix
}
}
var
default
CidPrefix
=
cid
.
Prefix
{
var
v0
CidPrefix
=
cid
.
Prefix
{
Codec
:
cid
.
DagProtobuf
,
Codec
:
cid
.
DagProtobuf
,
MhLength
:
-
1
,
MhLength
:
-
1
,
MhType
:
mh
.
SHA2_256
,
MhType
:
mh
.
SHA2_256
,
Version
:
0
,
Version
:
0
,
}
}
var
v1CidPrefix
=
cid
.
Prefix
{
Codec
:
cid
.
DagProtobuf
,
MhLength
:
-
1
,
MhType
:
mh
.
SHA2_256
,
Version
:
1
,
}
func
PrefixForCidVersion
(
version
int
)
(
cid
.
Prefix
,
error
)
{
switch
version
{
case
0
:
return
v0CidPrefix
,
nil
case
1
:
return
v1CidPrefix
,
nil
default
:
return
cid
.
Prefix
{},
fmt
.
Errorf
(
"unknown CID version: %d"
,
version
)
}
}
func
(
n
*
ProtoNode
)
SetPrefix
(
prefix
cid
.
Prefix
)
{
n
.
Prefix
=
prefix
n
.
encoded
=
nil
n
.
cached
=
nil
}
type
LinkSlice
[]
*
node
.
Link
type
LinkSlice
[]
*
node
.
Link
func
(
ls
LinkSlice
)
Len
()
int
{
return
len
(
ls
)
}
func
(
ls
LinkSlice
)
Len
()
int
{
return
len
(
ls
)
}
...
@@ -158,6 +182,9 @@ func (n *ProtoNode) Copy() node.Node {
...
@@ -158,6 +182,9 @@ func (n *ProtoNode) Copy() node.Node {
nnode
.
links
=
make
([]
*
node
.
Link
,
len
(
n
.
links
))
nnode
.
links
=
make
([]
*
node
.
Link
,
len
(
n
.
links
))
copy
(
nnode
.
links
,
n
.
links
)
copy
(
nnode
.
links
,
n
.
links
)
}
}
nnode
.
Prefix
=
n
.
Prefix
return
nnode
return
nnode
}
}
...
@@ -260,7 +287,7 @@ func (n *ProtoNode) Cid() *cid.Cid {
...
@@ -260,7 +287,7 @@ func (n *ProtoNode) Cid() *cid.Cid {
}
}
if
n
.
Prefix
.
Codec
==
0
{
if
n
.
Prefix
.
Codec
==
0
{
n
.
Prefix
=
default
CidPrefix
n
.
Prefix
=
v0
CidPrefix
}
}
c
,
err
:=
n
.
Prefix
.
Sum
(
n
.
RawData
())
c
,
err
:=
n
.
Prefix
.
Sum
(
n
.
RawData
())
...
...
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