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
d5fcd17e
Commit
d5fcd17e
authored
Dec 15, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change FindLink to FindLinks
cc @maybebtc
parent
21f3add5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
18 deletions
+9
-18
merkledag.go
merkledag.go
+9
-18
No files found.
merkledag.go
View file @
d5fcd17e
...
...
@@ -292,13 +292,14 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
// Searches this nodes links for one to the given key,
// returns the index of said link
func
FindLink
(
n
*
Node
,
k
u
.
Key
,
found
[]
*
Node
)
(
int
,
error
)
{
func
FindLinks
(
n
*
Node
,
k
u
.
Key
)
[]
int
{
var
out
[]
int
for
i
,
lnk
:=
range
n
.
Links
{
if
u
.
Key
(
lnk
.
Hash
)
==
k
&&
found
[
i
]
==
nil
{
return
i
,
nil
if
u
.
Key
(
lnk
.
Hash
)
==
k
{
out
=
append
(
out
,
i
)
}
}
return
-
1
,
u
.
ErrNotFound
return
out
}
// GetDAG will fill out all of the links of the given Node.
...
...
@@ -318,12 +319,6 @@ func (ds *dagService) GetDAG(ctx context.Context, root *Node) <-chan *Node {
nodes
:=
make
([]
*
Node
,
len
(
root
.
Links
))
next
:=
0
for
blk
:=
range
blkchan
{
i
,
err
:=
FindLink
(
root
,
blk
.
Key
(),
nodes
)
if
err
!=
nil
{
// NB: can only occur as a result of programmer error
panic
(
"Received block that wasnt in this nodes links!"
)
}
nd
,
err
:=
Decoded
(
blk
.
Data
)
if
err
!=
nil
{
// NB: can occur in normal situations, with improperly formatted
...
...
@@ -331,16 +326,12 @@ func (ds *dagService) GetDAG(ctx context.Context, root *Node) <-chan *Node {
log
.
Error
(
"Got back bad block!"
)
break
}
is
:=
FindLinks
(
root
,
blk
.
Key
())
for
_
,
i
:=
range
is
{
nodes
[
i
]
=
nd
for
{
//Check for duplicate links
ni
,
err
:=
FindLink
(
root
,
blk
.
Key
(),
nodes
)
if
err
!=
nil
{
break
}
nodes
[
ni
]
=
nd
}
if
next
==
i
{
if
next
==
i
s
[
0
]
{
sig
<-
nd
next
++
for
;
next
<
len
(
nodes
)
&&
nodes
[
next
]
!=
nil
;
next
++
{
...
...
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