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
fc23250f
Commit
fc23250f
authored
Jul 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added .Key
parent
e9cb869d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
merkledag.go
merkledag.go
+13
-0
merkledag_test.go
merkledag_test.go
+10
-1
No files found.
merkledag.go
View file @
fc23250f
package
merkledag
package
merkledag
import
(
import
(
u
"github.com/jbenet/go-ipfs/util"
mh
"github.com/jbenet/go-multihash"
mh
"github.com/jbenet/go-multihash"
)
)
// can't use []byte/Multihash for keys :(
// so have to convert Multihash bytes to string
type
NodeMap
map
[
u
.
Key
]
*
Node
// A node in the IPFS Merkle DAG.
// A node in the IPFS Merkle DAG.
// nodes have opaque data and a set of navigable links.
// nodes have opaque data and a set of navigable links.
type
Node
struct
{
type
Node
struct
{
...
@@ -24,6 +29,9 @@ type Link struct {
...
@@ -24,6 +29,9 @@ type Link struct {
// multihash of the target object
// multihash of the target object
Hash
mh
.
Multihash
Hash
mh
.
Multihash
// a ptr to the actual node for graph manipulation
Node
*
Node
}
}
func
(
n
*
Node
)
AddNodeLink
(
name
string
,
that
*
Node
)
error
{
func
(
n
*
Node
)
AddNodeLink
(
name
string
,
that
*
Node
)
error
{
...
@@ -66,3 +74,8 @@ func (n *Node) Multihash() (mh.Multihash, error) {
...
@@ -66,3 +74,8 @@ func (n *Node) Multihash() (mh.Multihash, error) {
return
mh
.
Sum
(
b
,
mh
.
SHA2_256
,
-
1
)
return
mh
.
Sum
(
b
,
mh
.
SHA2_256
,
-
1
)
}
}
func
(
n
*
Node
)
Key
()
(
u
.
Key
,
error
)
{
h
,
err
:=
n
.
Multihash
()
return
u
.
Key
(
h
),
err
}
merkledag_test.go
View file @
fc23250f
...
@@ -2,7 +2,7 @@ package merkledag
...
@@ -2,7 +2,7 @@ package merkledag
import
(
import
(
"fmt"
"fmt"
// mh
"github.com/jbenet/go-
multihash
"
u
"github.com/jbenet/go-
ipfs/util
"
"testing"
"testing"
)
)
...
@@ -40,6 +40,15 @@ func TestNode(t *testing.T) {
...
@@ -40,6 +40,15 @@ func TestNode(t *testing.T) {
}
else
{
}
else
{
fmt
.
Println
(
"hash:"
,
h
)
fmt
.
Println
(
"hash:"
,
h
)
}
}
k
,
err
:=
n
.
Key
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
else
if
k
!=
u
.
Key
(
h
)
{
t
.
Error
(
"Key is not equivalent to multihash"
)
}
else
{
fmt
.
Println
(
"key: "
,
k
)
}
}
}
printn
(
"beep"
,
n1
)
printn
(
"beep"
,
n1
)
...
...
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