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
4ba46347
Commit
4ba46347
authored
Sep 19, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(bitswap) send block from one instance to another
parent
d2e4bad4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
13 deletions
+30
-13
bitswap.go
bitswap.go
+10
-3
bitswap_test.go
bitswap_test.go
+20
-10
No files found.
bitswap.go
View file @
4ba46347
...
...
@@ -119,9 +119,15 @@ func (bs *bitswap) ReceiveMessage(
if
incoming
.
Blocks
()
!=
nil
{
for
_
,
block
:=
range
incoming
.
Blocks
()
{
bs
.
blockstore
.
Put
(
block
)
// FIXME(brian): err ignored
err
:=
bs
.
blockstore
.
Put
(
block
)
// FIXME(brian): err ignored
if
err
!=
nil
{
return
nil
,
nil
,
err
}
bs
.
notifications
.
Publish
(
block
)
bs
.
HasBlock
(
ctx
,
block
)
// FIXME err ignored
err
=
bs
.
HasBlock
(
ctx
,
block
)
// FIXME err ignored
if
err
!=
nil
{
return
nil
,
nil
,
err
}
}
}
...
...
@@ -134,7 +140,8 @@ func (bs *bitswap) ReceiveMessage(
}
message
:=
bsmsg
.
New
()
message
.
AppendBlock
(
*
block
)
bs
.
send
(
ctx
,
p
,
message
)
defer
bs
.
strategy
.
MessageSent
(
p
,
message
)
return
p
,
message
,
nil
}
}
}
...
...
bitswap_test.go
View file @
4ba46347
package
bitswap
import
(
"bytes"
"testing"
"time"
...
...
@@ -20,11 +21,13 @@ func TestGetBlockTimeout(t *testing.T) {
net
:=
testnet
.
VirtualNetwork
()
rs
:=
testnet
.
VirtualRoutingServer
()
ipfs
:=
session
(
net
,
rs
,
[]
byte
(
"peer id"
))
self
:=
session
(
net
,
rs
,
[]
byte
(
"peer id"
))
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Nanosecond
)
block
:=
testutil
.
NewBlockOrFail
(
t
,
"block"
)
_
,
err
:=
self
.
exchange
.
Block
(
ctx
,
block
.
Key
())
_
,
err
:=
ipfs
.
exchange
.
Block
(
ctx
,
block
.
Key
())
if
err
!=
context
.
DeadlineExceeded
{
t
.
Fatal
(
"Expected DeadlineExceeded error"
)
}
...
...
@@ -59,28 +62,35 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
hasBlock
:=
session
(
net
,
rs
,
[]
byte
(
"hasBlock"
))
rs
.
Announce
(
hasBlock
.
peer
,
block
.
Key
())
hasBlock
.
blockstore
.
Put
(
block
)
hasBlock
.
exchange
.
HasBlock
(
context
.
Background
(),
block
)
if
err
:=
hasBlock
.
blockstore
.
Put
(
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
hasBlock
.
exchange
.
HasBlock
(
context
.
Background
(),
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
wantsBlock
:=
session
(
net
,
rs
,
[]
byte
(
"wantsBlock"
))
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
_
,
err
:=
wantsBlock
.
exchange
.
Block
(
ctx
,
block
.
Key
())
received
,
err
:=
wantsBlock
.
exchange
.
Block
(
ctx
,
block
.
Key
())
if
err
!=
nil
{
t
.
Log
(
err
)
t
.
Fatal
(
"Expected to succeed"
)
}
if
!
bytes
.
Equal
(
block
.
Data
,
received
.
Data
)
{
t
.
Fatal
(
"Data doesn't match"
)
}
}
type
ipfs
struct
{
type
testnetBitSwap
struct
{
peer
*
peer
.
Peer
exchange
exchange
.
Interface
blockstore
bstore
.
Blockstore
}
func
session
(
net
testnet
.
Network
,
rs
testnet
.
RoutingServer
,
id
peer
.
ID
)
ipfs
{
p
:=
&
peer
.
Peer
{}
func
session
(
net
testnet
.
Network
,
rs
testnet
.
RoutingServer
,
id
peer
.
ID
)
testnetBitSwap
{
p
:=
&
peer
.
Peer
{
ID
:
id
}
adapter
:=
net
.
Adapter
(
p
)
htc
:=
rs
.
Client
(
p
)
...
...
@@ -94,7 +104,7 @@ func session(net testnet.Network, rs testnet.RoutingServer, id peer.ID) ipfs {
sender
:
adapter
,
}
adapter
.
SetDelegate
(
bs
)
return
ipfs
{
return
testnetBitSwap
{
peer
:
p
,
exchange
:
bs
,
blockstore
:
blockstore
,
...
...
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