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-blockservice
Commits
a4fea7bb
Commit
a4fea7bb
authored
May 05, 2016
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make blocks.Block an interface.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
364267d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
blockservice.go
blockservice.go
+5
-5
test/blocks_test.go
test/blocks_test.go
+3
-3
No files found.
blockservice.go
View file @
a4fea7bb
...
...
@@ -41,7 +41,7 @@ func New(bs blockstore.Blockstore, rem exchange.Interface) *BlockService {
// AddBlock adds a particular block to the service, Putting it into the datastore.
// TODO pass a context into this if the remote.HasBlock is going to remain here.
func
(
s
*
BlockService
)
AddBlock
(
b
*
blocks
.
Block
)
(
key
.
Key
,
error
)
{
func
(
s
*
BlockService
)
AddBlock
(
b
blocks
.
Block
)
(
key
.
Key
,
error
)
{
k
:=
b
.
Key
()
err
:=
s
.
Blockstore
.
Put
(
b
)
if
err
!=
nil
{
...
...
@@ -53,7 +53,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (key.Key, error) {
return
k
,
nil
}
func
(
s
*
BlockService
)
AddBlocks
(
bs
[]
*
blocks
.
Block
)
([]
key
.
Key
,
error
)
{
func
(
s
*
BlockService
)
AddBlocks
(
bs
[]
blocks
.
Block
)
([]
key
.
Key
,
error
)
{
err
:=
s
.
Blockstore
.
PutMany
(
bs
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -71,7 +71,7 @@ func (s *BlockService) AddBlocks(bs []*blocks.Block) ([]key.Key, error) {
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func
(
s
*
BlockService
)
GetBlock
(
ctx
context
.
Context
,
k
key
.
Key
)
(
*
blocks
.
Block
,
error
)
{
func
(
s
*
BlockService
)
GetBlock
(
ctx
context
.
Context
,
k
key
.
Key
)
(
blocks
.
Block
,
error
)
{
log
.
Debugf
(
"BlockService GetBlock: '%s'"
,
k
)
block
,
err
:=
s
.
Blockstore
.
Get
(
k
)
if
err
==
nil
{
...
...
@@ -103,8 +103,8 @@ func (s *BlockService) GetBlock(ctx context.Context, k key.Key) (*blocks.Block,
// GetBlocks gets a list of blocks asynchronously and returns through
// the returned channel.
// NB: No guarantees are made about order.
func
(
s
*
BlockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
key
.
Key
)
<-
chan
*
blocks
.
Block
{
out
:=
make
(
chan
*
blocks
.
Block
,
0
)
func
(
s
*
BlockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
key
.
Key
)
<-
chan
blocks
.
Block
{
out
:=
make
(
chan
blocks
.
Block
,
0
)
go
func
()
{
defer
close
(
out
)
var
misses
[]
key
.
Key
...
...
test/blocks_test.go
View file @
a4fea7bb
...
...
@@ -24,7 +24,7 @@ func TestBlocks(t *testing.T) {
b
:=
blocks
.
NewBlock
([]
byte
(
"beep boop"
))
h
:=
u
.
Hash
([]
byte
(
"beep boop"
))
if
!
bytes
.
Equal
(
b
.
Multihash
,
h
)
{
if
!
bytes
.
Equal
(
b
.
Multihash
()
,
h
)
{
t
.
Error
(
"Block Multihash and data multihash not equal"
)
}
...
...
@@ -54,7 +54,7 @@ func TestBlocks(t *testing.T) {
t
.
Error
(
"Block keys not equal."
)
}
if
!
bytes
.
Equal
(
b
.
Data
,
b2
.
Data
)
{
if
!
bytes
.
Equal
(
b
.
Data
()
,
b2
.
Data
()
)
{
t
.
Error
(
"Block data is not equal."
)
}
}
...
...
@@ -79,7 +79,7 @@ func TestGetBlocksSequential(t *testing.T) {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
50
)
defer
cancel
()
out
:=
servs
[
i
]
.
GetBlocks
(
ctx
,
keys
)
gotten
:=
make
(
map
[
key
.
Key
]
*
blocks
.
Block
)
gotten
:=
make
(
map
[
key
.
Key
]
blocks
.
Block
)
for
blk
:=
range
out
{
if
_
,
ok
:=
gotten
[
blk
.
Key
()];
ok
{
t
.
Fatal
(
"Got duplicate block!"
)
...
...
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