Commit 74e68092 authored by Jeromy's avatar Jeromy

a few more comments

parent be9e1d21
...@@ -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{})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment