Skip to content
Snippets Groups Projects
Commit e539024e authored by Jeromy Johnson's avatar Jeromy Johnson
Browse files

some code cleanup

parent 298305e4
No related branches found
No related tags found
1 merge request!1New
......@@ -68,7 +68,7 @@ func TrickleAppend(base *dag.Node, db *h.DagBuilderHelper) (*dag.Node, error) {
}
// Get depth of this 'tree'
n, j := trickleDepthInfo(ufsn, db.Maxlinks())
n, layerProgress := trickleDepthInfo(ufsn, db.Maxlinks())
if n == 0 {
// If direct blocks not filled...
err := db.FillNodeLayer(ufsn)
......@@ -84,7 +84,8 @@ func TrickleAppend(base *dag.Node, db *h.DagBuilderHelper) (*dag.Node, error) {
n++
}
err = appendFillLastChild(ufsn, n-1, j, db)
// Last child in this node may not be a full tree, lets file it up
err = appendFillLastChild(ufsn, n-1, layerProgress, db)
if err != nil {
return nil, err
}
......@@ -113,8 +114,12 @@ func TrickleAppend(base *dag.Node, db *h.DagBuilderHelper) (*dag.Node, error) {
return ufsn.GetDagNode()
}
// appendFillLastChild will take in an incomplete trickledag node (uncomplete meaning, not full) and
// fill it out to the specified depth with blocks from the given DagBuilderHelper
func appendFillLastChild(ufsn *h.UnixfsNode, depth int, layerFill int, db *h.DagBuilderHelper) error {
if ufsn.NumChildren() > db.Maxlinks() {
if ufsn.NumChildren() <= db.Maxlinks() {
return nil
}
// Recursive step, grab last child
last := ufsn.NumChildren() - 1
lastChild, err := ufsn.GetChild(last, db.GetDagServ())
......@@ -150,18 +155,18 @@ func appendFillLastChild(ufsn *h.UnixfsNode, depth int, layerFill int, db *h.Dag
}
}
}
}
return nil
}
// recursive call for TrickleAppend
func trickleAppendRec(ufsn *h.UnixfsNode, db *h.DagBuilderHelper, depth int) (*h.UnixfsNode, error) {
if depth == 0 || db.Done() {
return ufsn, nil
}
// Get depth of this 'tree'
n, j := trickleDepthInfo(ufsn, db.Maxlinks())
n, layerProgress := trickleDepthInfo(ufsn, db.Maxlinks())
if n == 0 {
// If direct blocks not filled...
err := db.FillNodeLayer(ufsn)
......@@ -176,7 +181,7 @@ func trickleAppendRec(ufsn *h.UnixfsNode, db *h.DagBuilderHelper, depth int) (*h
return ufsn, nil
}
err := appendFillLastChild(ufsn, n, j, db)
err := appendFillLastChild(ufsn, n, layerProgress, db)
if err != nil {
return nil, err
}
......@@ -242,7 +247,7 @@ func verifyTDagRec(nd *dag.Node, depth, direct, layerRepeat int, ds dag.DAGServi
for i := 0; i < len(nd.Links); i++ {
child, err := nd.Links[i].GetNode(ds)
if err != nil {
return nil
return err
}
if i < direct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment