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-dms3
Commits
e539024e
Commit
e539024e
authored
Mar 07, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some code cleanup
parent
298305e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
36 deletions
+41
-36
importer/trickle/trickledag.go
importer/trickle/trickledag.go
+41
-36
No files found.
importer/trickle/trickledag.go
View file @
e539024e
...
...
@@ -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,41 +114,44 @@ 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
()
{
// Recursive step, grab last child
last
:=
ufsn
.
NumChildren
()
-
1
lastChild
,
err
:=
ufsn
.
GetChild
(
last
,
db
.
GetDagServ
())
if
err
!=
nil
{
return
err
}
if
ufsn
.
NumChildren
()
<=
db
.
Maxlinks
()
{
return
nil
}
// Recursive step, grab last child
last
:=
ufsn
.
NumChildren
()
-
1
lastChild
,
err
:=
ufsn
.
GetChild
(
last
,
db
.
GetDagServ
())
if
err
!=
nil
{
return
err
}
// Fill out last child (may not be full tree)
nchild
,
err
:=
trickleAppendRec
(
lastChild
,
db
,
depth
-
1
)
if
err
!=
nil
{
return
err
}
// Fill out last child (may not be full tree)
nchild
,
err
:=
trickleAppendRec
(
lastChild
,
db
,
depth
-
1
)
if
err
!=
nil
{
return
err
}
// Update changed child in parent node
ufsn
.
RemoveChild
(
last
)
err
=
ufsn
.
AddChild
(
nchild
,
db
)
if
err
!=
nil
{
return
err
}
// Update changed child in parent node
ufsn
.
RemoveChild
(
last
)
err
=
ufsn
.
AddChild
(
nchild
,
db
)
if
err
!=
nil
{
return
err
}
// Partially filled depth layer
if
layerFill
!=
0
{
for
;
layerFill
<
layerRepeat
&&
!
db
.
Done
();
layerFill
++
{
next
:=
h
.
NewUnixfsNode
()
err
:=
fillTrickleRec
(
db
,
next
,
depth
)
if
err
!=
nil
{
return
err
}
// Partially filled depth layer
if
layerFill
!=
0
{
for
;
layerFill
<
layerRepeat
&&
!
db
.
Done
();
layerFill
++
{
next
:=
h
.
NewUnixfsNode
()
err
:=
fillTrickleRec
(
db
,
next
,
depth
)
if
err
!=
nil
{
return
err
}
err
=
ufsn
.
AddChild
(
next
,
db
)
if
err
!=
nil
{
return
err
}
err
=
ufsn
.
AddChild
(
next
,
db
)
if
err
!=
nil
{
return
err
}
}
}
...
...
@@ -155,13 +159,14 @@ 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
{
...
...
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