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
4cc17807
Commit
4cc17807
authored
Nov 24, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix issues in merkledag
parent
d721c448
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
15 deletions
+24
-15
core/core.go
core/core.go
+1
-0
exchange/bitswap/network/ipfs_impl.go
exchange/bitswap/network/ipfs_impl.go
+0
-3
merkledag/merkledag.go
merkledag/merkledag.go
+23
-12
No files found.
core/core.go
View file @
4cc17807
...
...
@@ -115,6 +115,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
Config
:
cfg
,
}
n
.
ContextCloser
=
ctxc
.
NewContextCloser
(
ctx
,
n
.
teardown
)
ctx
=
n
.
Context
()
// setup datastore.
if
n
.
Datastore
,
err
=
makeDatastore
(
cfg
.
Datastore
);
err
!=
nil
{
...
...
exchange/bitswap/network/ipfs_impl.go
View file @
4cc17807
package
network
import
(
"errors"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
...
...
@@ -54,7 +52,6 @@ func (bsnet *impl) HandleMessage(
// TODO(brian): put this in a helper function
if
bsmsg
==
nil
||
p
==
nil
{
bsnet
.
receiver
.
ReceiveError
(
errors
.
New
(
"ReceiveMessage returned nil peer or message"
))
return
nil
}
...
...
merkledag/merkledag.go
View file @
4cc17807
...
...
@@ -163,17 +163,6 @@ func (n *Node) Multihash() (mh.Multihash, error) {
return
n
.
cached
,
nil
}
// Searches this nodes links for one to the given key,
// returns the index of said link
func
(
n
*
Node
)
FindLink
(
k
u
.
Key
)
(
int
,
error
)
{
for
i
,
lnk
:=
range
n
.
Links
{
if
u
.
Key
(
lnk
.
Hash
)
==
k
{
return
i
,
nil
}
}
return
-
1
,
u
.
ErrNotFound
}
// Key returns the Multihash as a key, for maps.
func
(
n
*
Node
)
Key
()
(
u
.
Key
,
error
)
{
h
,
err
:=
n
.
Multihash
()
...
...
@@ -298,6 +287,17 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
return
done
}
// 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
)
{
for
i
,
lnk
:=
range
n
.
Links
{
if
u
.
Key
(
lnk
.
Hash
)
==
k
&&
found
[
i
]
==
nil
{
return
i
,
nil
}
}
return
-
1
,
u
.
ErrNotFound
}
// BatchFetch will fill out all of the links of the given Node.
// It returns a channel of nodes, which the caller can receive
// all the child nodes of 'root' on, in proper order.
...
...
@@ -324,7 +324,7 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
count
:=
0
for
blk
:=
range
blkchan
{
count
++
i
,
err
:=
root
.
FindLink
(
blk
.
Key
())
i
,
err
:=
FindLink
(
root
,
blk
.
Key
()
,
nodes
)
if
err
!=
nil
{
panic
(
"Received block that wasnt in this nodes links!"
)
}
...
...
@@ -356,3 +356,14 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
return
sig
}
func
checkForDupes
(
ks
[]
u
.
Key
)
bool
{
seen
:=
make
(
map
[
u
.
Key
]
struct
{})
for
_
,
k
:=
range
ks
{
if
_
,
ok
:=
seen
[
k
];
ok
{
return
true
}
seen
[
k
]
=
struct
{}{}
}
return
false
}
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