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-bitswap
Commits
afee5e33
Commit
afee5e33
authored
Sep 02, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove context from HasBlock, use bitswap process instead
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
f62acec4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
13 deletions
+8
-13
bitswap.go
bitswap.go
+4
-6
bitswap_test.go
bitswap_test.go
+4
-7
No files found.
bitswap.go
View file @
afee5e33
...
...
@@ -228,7 +228,7 @@ func (bs *Bitswap) CancelWants(ks []key.Key) {
// HasBlock announces the existance of a block to this bitswap service. The
// service will potentially notify its peers.
func
(
bs
*
Bitswap
)
HasBlock
(
ctx
context
.
Context
,
blk
*
blocks
.
Block
)
error
{
func
(
bs
*
Bitswap
)
HasBlock
(
blk
*
blocks
.
Block
)
error
{
select
{
case
<-
bs
.
process
.
Closing
()
:
return
errors
.
New
(
"bitswap is closed"
)
...
...
@@ -246,8 +246,8 @@ func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
select
{
case
bs
.
newBlocks
<-
blk
:
// send block off to be reprovided
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
<-
bs
.
process
.
Closing
()
:
return
bs
.
process
.
Close
()
}
return
nil
}
...
...
@@ -328,9 +328,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
log
.
Event
(
ctx
,
"Bitswap.GetBlockRequest.End"
,
&
k
)
log
.
Debugf
(
"got block %s from %s"
,
b
,
p
)
hasBlockCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
hasBlockTimeout
)
defer
cancel
()
if
err
:=
bs
.
HasBlock
(
hasBlockCtx
,
b
);
err
!=
nil
{
if
err
:=
bs
.
HasBlock
(
b
);
err
!=
nil
{
log
.
Warningf
(
"ReceiveMessage HasBlock error: %s"
,
err
)
}
}(
block
)
...
...
bitswap_test.go
View file @
afee5e33
...
...
@@ -70,7 +70,7 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
hasBlock
:=
peers
[
0
]
defer
hasBlock
.
Exchange
.
Close
()
if
err
:=
hasBlock
.
Exchange
.
HasBlock
(
context
.
Background
(),
block
);
err
!=
nil
{
if
err
:=
hasBlock
.
Exchange
.
HasBlock
(
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -162,7 +162,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
first
:=
instances
[
0
]
for
_
,
b
:=
range
blocks
{
blkeys
=
append
(
blkeys
,
b
.
Key
())
first
.
Exchange
.
HasBlock
(
ctx
,
b
)
first
.
Exchange
.
HasBlock
(
b
)
}
t
.
Log
(
"Distribute!"
)
...
...
@@ -224,7 +224,6 @@ func TestSendToWantingPeer(t *testing.T) {
t
.
Logf
(
"Session %v
\n
"
,
peerA
.
Peer
)
t
.
Logf
(
"Session %v
\n
"
,
peerB
.
Peer
)
timeout
:=
time
.
Second
waitTime
:=
time
.
Second
*
5
alpha
:=
bg
.
Next
()
...
...
@@ -237,9 +236,7 @@ func TestSendToWantingPeer(t *testing.T) {
}
// peerB announces to the network that he has block alpha
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
defer
cancel
()
err
=
peerB
.
Exchange
.
HasBlock
(
ctx
,
alpha
)
err
=
peerB
.
Exchange
.
HasBlock
(
alpha
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -266,7 +263,7 @@ func TestBasicBitswap(t *testing.T) {
instances
:=
sg
.
Instances
(
2
)
blocks
:=
bg
.
Blocks
(
1
)
err
:=
instances
[
0
]
.
Exchange
.
HasBlock
(
context
.
Background
(),
blocks
[
0
])
err
:=
instances
[
0
]
.
Exchange
.
HasBlock
(
blocks
[
0
])
if
err
!=
nil
{
t
.
Fatal
(
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