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
e907b2e0
Commit
e907b2e0
authored
Sep 18, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(exchange) pass ctx to exchange.HasBlock(...)
parent
1054b8d8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
9 additions
and
13 deletions
+9
-13
blockservice/blockservice.go
blockservice/blockservice.go
+2
-1
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+1
-2
exchange/bitswap/offline.go
exchange/bitswap/offline.go
+1
-1
exchange/bitswap/offline_test.go
exchange/bitswap/offline_test.go
+2
-2
exchange/interface.go
exchange/interface.go
+3
-7
No files found.
blockservice/blockservice.go
View file @
e907b2e0
...
@@ -43,7 +43,8 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
...
@@ -43,7 +43,8 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
return
k
,
err
return
k
,
err
}
}
if
s
.
Remote
!=
nil
{
if
s
.
Remote
!=
nil
{
err
=
s
.
Remote
.
HasBlock
(
*
b
)
ctx
:=
context
.
TODO
()
err
=
s
.
Remote
.
HasBlock
(
ctx
,
*
b
)
}
}
return
k
,
err
return
k
,
err
}
}
...
...
exchange/bitswap/bitswap.go
View file @
e907b2e0
...
@@ -128,8 +128,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
...
@@ -128,8 +128,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
// HasBlock announces the existance of a block to bitswap, potentially sending
// HasBlock announces the existance of a block to bitswap, potentially sending
// it to peers (Partners) whose WantLists include it.
// it to peers (Partners) whose WantLists include it.
func
(
bs
*
bitswap
)
HasBlock
(
blk
blocks
.
Block
)
error
{
func
(
bs
*
bitswap
)
HasBlock
(
ctx
context
.
Context
,
blk
blocks
.
Block
)
error
{
ctx
:=
context
.
TODO
()
go
bs
.
sendToPeersThatWant
(
ctx
,
blk
)
go
bs
.
sendToPeersThatWant
(
ctx
,
blk
)
return
bs
.
routing
.
Provide
(
blk
.
Key
())
return
bs
.
routing
.
Provide
(
blk
.
Key
())
}
}
...
...
exchange/bitswap/offline.go
View file @
e907b2e0
...
@@ -27,6 +27,6 @@ func (_ *offlineExchange) Block(context.Context, u.Key) (*blocks.Block, error) {
...
@@ -27,6 +27,6 @@ func (_ *offlineExchange) Block(context.Context, u.Key) (*blocks.Block, error) {
}
}
// HasBlock always returns nil.
// HasBlock always returns nil.
func
(
_
*
offlineExchange
)
HasBlock
(
blocks
.
Block
)
error
{
func
(
_
*
offlineExchange
)
HasBlock
(
context
.
Context
,
blocks
.
Block
)
error
{
return
nil
return
nil
}
}
exchange/bitswap/offline_test.go
View file @
e907b2e0
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
func
TestBlockReturnsErr
(
t
*
testing
.
T
)
{
func
TestBlockReturnsErr
(
t
*
testing
.
T
)
{
off
:=
NewOfflineExchange
()
off
:=
NewOfflineExchange
()
_
,
err
:=
off
.
Block
(
context
.
TODO
(),
u
.
Key
(
"foo"
))
_
,
err
:=
off
.
Block
(
context
.
Background
(),
u
.
Key
(
"foo"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
// as desired
return
// as desired
}
}
...
@@ -21,7 +21,7 @@ func TestBlockReturnsErr(t *testing.T) {
...
@@ -21,7 +21,7 @@ func TestBlockReturnsErr(t *testing.T) {
func
TestHasBlockReturnsNil
(
t
*
testing
.
T
)
{
func
TestHasBlockReturnsNil
(
t
*
testing
.
T
)
{
off
:=
NewOfflineExchange
()
off
:=
NewOfflineExchange
()
block
:=
testutil
.
NewBlockOrFail
(
t
,
"data"
)
block
:=
testutil
.
NewBlockOrFail
(
t
,
"data"
)
err
:=
off
.
HasBlock
(
block
)
err
:=
off
.
HasBlock
(
context
.
Background
(),
block
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
""
)
t
.
Fatal
(
""
)
}
}
...
...
exchange/interface.go
View file @
e907b2e0
...
@@ -12,13 +12,9 @@ import (
...
@@ -12,13 +12,9 @@ import (
type
Interface
interface
{
type
Interface
interface
{
// Block returns the block associated with a given key.
// Block returns the block associated with a given key.
// TODO(brian): pass a context instead of a timeout
Block
(
context
.
Context
,
u
.
Key
)
(
*
blocks
.
Block
,
error
)
Block
(
context
.
Context
,
u
.
Key
)
(
*
blocks
.
Block
,
error
)
// HasBlock asserts the existence of this block
// TODO Should callers be concerned with whether the block was made
// TODO(brian): rename -> HasBlock
// available on the network?
// TODO(brian): accept a value, not a pointer
HasBlock
(
context
.
Context
,
blocks
.
Block
)
error
// TODO(brian): remove error return value. Should callers be concerned with
// whether the block was made available on the network?
HasBlock
(
blocks
.
Block
)
error
}
}
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