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
99ae4320
Commit
99ae4320
authored
10 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start working getBlocks up the call chain
parent
5babfb97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
15 deletions
+73
-15
blockservice/blockservice.go
blockservice/blockservice.go
+23
-3
merkledag/merkledag.go
merkledag/merkledag.go
+50
-12
No files found.
blockservice/blockservice.go
View file @
99ae4320
...
...
@@ -96,9 +96,29 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
}
}
func
(
s
*
BlockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
u
.
Key
)
(
<-
chan
blocks
.
Block
,
error
)
{
// TODO:
return
nil
,
nil
func
(
s
*
BlockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
u
.
Key
)
<-
chan
*
blocks
.
Block
{
out
:=
make
(
chan
*
blocks
.
Block
,
32
)
go
func
()
{
var
toFetch
[]
u
.
Key
for
_
,
k
:=
range
ks
{
datai
,
err
:=
s
.
Datastore
.
Get
(
k
.
DsKey
())
if
err
==
nil
{
log
.
Debug
(
"Blockservice: Got data in datastore."
)
bdata
,
ok
:=
datai
.
([]
byte
)
if
!
ok
{
log
.
Criticalf
(
"data associated with %s is not a []byte"
,
k
)
continue
}
out
<-
&
blocks
.
Block
{
Multihash
:
mh
.
Multihash
(
k
),
Data
:
bdata
,
}
}
else
{
toFetch
=
append
(
toFetch
,
k
)
}
}
}()
return
out
}
// DeleteBlock deletes a block in the blockservice from the datastore
...
...
This diff is collapsed.
Click to expand it.
merkledag/merkledag.go
View file @
99ae4320
...
...
@@ -289,18 +289,56 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
// Take advantage of blockservice/bitswap batched requests to fetch all
// child nodes of a given node
// TODO: finish this
func
(
ds
*
dagService
)
BatchFetch
(
ctx
context
.
Context
,
root
*
Node
)
error
{
var
keys
[]
u
.
Key
for
_
,
lnk
:=
range
root
.
Links
{
keys
=
append
(
keys
,
u
.
Key
(
lnk
.
Hash
))
}
func
(
ds
*
dagService
)
BatchFetch
(
ctx
context
.
Context
,
root
*
Node
)
chan
struct
{}
{
sig
:=
make
(
chan
struct
{})
go
func
()
{
var
keys
[]
u
.
Key
for
_
,
lnk
:=
range
root
.
Links
{
keys
=
append
(
keys
,
u
.
Key
(
lnk
.
Hash
))
}
blocks
,
err
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
keys
)
if
err
!=
nil
{
return
err
}
blkchan
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
keys
)
//
next
:=
0
seen
:=
make
(
map
[
int
]
struct
{})
//
for
blk
:=
range
blkchan
{
for
i
,
lnk
:=
range
root
.
Links
{
//
seen
[
i
]
=
struct
{}{}
//
if
u
.
Key
(
lnk
.
Hash
)
!=
blk
.
Key
()
{
continue
}
nd
,
err
:=
Decoded
(
blk
.
Data
)
if
err
!=
nil
{
log
.
Error
(
"Got back bad block!"
)
break
}
lnk
.
Node
=
nd
//
if
next
==
i
{
sig
<-
struct
{}{}
next
++
for
{
if
_
,
ok
:=
seen
[
next
];
ok
{
sig
<-
struct
{}{}
next
++
}
else
{
break
}
}
}
//
}
}
}()
_
=
blocks
//what do i do with blocks?
return
nil
// TODO: return a channel, and signal when the 'Next' readable block is available
return
sig
}
This diff is collapsed.
Click to expand it.
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