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
74e68092
Commit
74e68092
authored
Nov 03, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a few more comments
parent
be9e1d21
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
0 deletions
+7
-0
merkledag.go
merkledag.go
+7
-0
No files found.
merkledag.go
View file @
74e68092
...
@@ -48,6 +48,7 @@ type Link struct {
...
@@ -48,6 +48,7 @@ type Link struct {
Node
*
Node
Node
*
Node
}
}
// MakeLink creates a link to the given node
func
MakeLink
(
n
*
Node
)
(
*
Link
,
error
)
{
func
MakeLink
(
n
*
Node
)
(
*
Link
,
error
)
{
s
,
err
:=
n
.
Size
()
s
,
err
:=
n
.
Size
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -64,6 +65,7 @@ func MakeLink(n *Node) (*Link, error) {
...
@@ -64,6 +65,7 @@ func MakeLink(n *Node) (*Link, error) {
},
nil
},
nil
}
}
// GetNode returns the MDAG Node that this link points to
func
(
l
*
Link
)
GetNode
(
serv
DAGService
)
(
*
Node
,
error
)
{
func
(
l
*
Link
)
GetNode
(
serv
DAGService
)
(
*
Node
,
error
)
{
if
l
.
Node
!=
nil
{
if
l
.
Node
!=
nil
{
return
l
.
Node
,
nil
return
l
.
Node
,
nil
...
@@ -98,6 +100,7 @@ func (n *Node) AddNodeLinkClean(name string, that *Node) error {
...
@@ -98,6 +100,7 @@ func (n *Node) AddNodeLinkClean(name string, that *Node) error {
return
nil
return
nil
}
}
// Remove a link on this node by the given name
func
(
n
*
Node
)
RemoveNodeLink
(
name
string
)
error
{
func
(
n
*
Node
)
RemoveNodeLink
(
name
string
)
error
{
for
i
,
l
:=
range
n
.
Links
{
for
i
,
l
:=
range
n
.
Links
{
if
l
.
Name
==
name
{
if
l
.
Name
==
name
{
...
@@ -196,6 +199,7 @@ func (n *dagService) Add(nd *Node) (u.Key, error) {
...
@@ -196,6 +199,7 @@ func (n *dagService) Add(nd *Node) (u.Key, error) {
return
n
.
Blocks
.
AddBlock
(
b
)
return
n
.
Blocks
.
AddBlock
(
b
)
}
}
// AddRecursive adds the given node and all child nodes to the BlockService
func
(
n
*
dagService
)
AddRecursive
(
nd
*
Node
)
error
{
func
(
n
*
dagService
)
AddRecursive
(
nd
*
Node
)
error
{
_
,
err
:=
n
.
Add
(
nd
)
_
,
err
:=
n
.
Add
(
nd
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -230,6 +234,7 @@ func (n *dagService) Get(k u.Key) (*Node, error) {
...
@@ -230,6 +234,7 @@ func (n *dagService) Get(k u.Key) (*Node, error) {
return
Decoded
(
b
.
Data
)
return
Decoded
(
b
.
Data
)
}
}
// Remove deletes the given node and all of its children from the BlockService
func
(
n
*
dagService
)
Remove
(
nd
*
Node
)
error
{
func
(
n
*
dagService
)
Remove
(
nd
*
Node
)
error
{
for
_
,
l
:=
range
nd
.
Links
{
for
_
,
l
:=
range
nd
.
Links
{
if
l
.
Node
!=
nil
{
if
l
.
Node
!=
nil
{
...
@@ -243,6 +248,8 @@ func (n *dagService) Remove(nd *Node) error {
...
@@ -243,6 +248,8 @@ func (n *dagService) Remove(nd *Node) error {
return
n
.
Blocks
.
DeleteBlock
(
k
)
return
n
.
Blocks
.
DeleteBlock
(
k
)
}
}
// FetchGraph asynchronously fetches all nodes that are children of the given
// node, and returns a channel that may be waited upon for the fetch to complete
func
FetchGraph
(
ctx
context
.
Context
,
root
*
Node
,
serv
DAGService
)
chan
struct
{}
{
func
FetchGraph
(
ctx
context
.
Context
,
root
*
Node
,
serv
DAGService
)
chan
struct
{}
{
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
done
:=
make
(
chan
struct
{})
done
:=
make
(
chan
struct
{})
...
...
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