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
a2363121
Commit
a2363121
authored
Oct 25, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add context to blockservice Get
parent
131764a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
blocks_test.go
blocks_test.go
+5
-1
blockservice.go
blockservice.go
+1
-3
No files found.
blocks_test.go
View file @
a2363121
...
...
@@ -3,6 +3,9 @@ package blockservice
import
(
"bytes"
"testing"
"time"
"code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
blocks
"github.com/jbenet/go-ipfs/blocks"
...
...
@@ -37,7 +40,8 @@ func TestBlocks(t *testing.T) {
t
.
Error
(
"returned key is not equal to block key"
,
err
)
}
b2
,
err
:=
bs
.
GetBlock
(
b
.
Key
())
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
time
.
Second
*
5
)
b2
,
err
:=
bs
.
GetBlock
(
ctx
,
b
.
Key
())
if
err
!=
nil
{
t
.
Error
(
"failed to retrieve block from BlockService"
,
err
)
return
...
...
blockservice.go
View file @
a2363121
...
...
@@ -2,7 +2,6 @@ package blockservice
import
(
"fmt"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
...
...
@@ -52,7 +51,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func
(
s
*
BlockService
)
GetBlock
(
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
func
(
s
*
BlockService
)
GetBlock
(
ctx
context
.
Context
,
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
log
.
Debug
(
"BlockService GetBlock: '%s'"
,
k
)
datai
,
err
:=
s
.
Datastore
.
Get
(
k
.
DsKey
())
if
err
==
nil
{
...
...
@@ -67,7 +66,6 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
},
nil
}
else
if
err
==
ds
.
ErrNotFound
&&
s
.
Remote
!=
nil
{
log
.
Debug
(
"Blockservice: Searching bitswap."
)
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
5
*
time
.
Second
)
blk
,
err
:=
s
.
Remote
.
Block
(
ctx
,
k
)
if
err
!=
nil
{
return
nil
,
err
...
...
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