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
7d7fd57a
Commit
7d7fd57a
authored
Dec 12, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(bs/testnet) use delay in virtual network
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
c211b061
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
10 deletions
+17
-10
bitswap_test.go
bitswap_test.go
+7
-6
testnet/network.go
testnet/network.go
+7
-2
testnet/network_test.go
testnet/network_test.go
+3
-2
No files found.
bitswap_test.go
View file @
7d7fd57a
...
...
@@ -11,13 +11,14 @@ import (
blocksutil
"github.com/jbenet/go-ipfs/blocks/blocksutil"
tn
"github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
mock
"github.com/jbenet/go-ipfs/routing/mock"
delay
"github.com/jbenet/go-ipfs/util/delay"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestClose
(
t
*
testing
.
T
)
{
// TODO
t
.
Skip
(
"TODO Bitswap's Close implementation is a WIP"
)
vnet
:=
tn
.
VirtualNetwork
()
vnet
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rout
:=
mock
.
VirtualRoutingServer
()
sesgen
:=
NewSessionGenerator
(
vnet
,
rout
)
bgen
:=
blocksutil
.
NewBlockGenerator
()
...
...
@@ -31,7 +32,7 @@ func TestClose(t *testing.T) {
func
TestGetBlockTimeout
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
g
:=
NewSessionGenerator
(
net
,
rs
)
...
...
@@ -48,7 +49,7 @@ func TestGetBlockTimeout(t *testing.T) {
func
TestProviderForKeyButNetworkCannotFind
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
g
:=
NewSessionGenerator
(
net
,
rs
)
...
...
@@ -69,7 +70,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
func
TestGetBlockFromPeerAfterPeerAnnounces
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
))
g
:=
NewSessionGenerator
(
net
,
rs
)
...
...
@@ -121,7 +122,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
if
testing
.
Short
()
{
t
.
SkipNow
()
}
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
blocksutil
.
NewBlockGenerator
()
...
...
@@ -181,7 +182,7 @@ func TestSendToWantingPeer(t *testing.T) {
t
.
SkipNow
()
}
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
blocksutil
.
NewBlockGenerator
()
...
...
testnet/network.go
View file @
7d7fd57a
...
...
@@ -10,6 +10,7 @@ import (
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer
"github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/util"
delay
"github.com/jbenet/go-ipfs/util/delay"
)
type
Network
interface
{
...
...
@@ -33,14 +34,16 @@ type Network interface {
// network impl
func
VirtualNetwork
()
Network
{
func
VirtualNetwork
(
d
delay
.
D
)
Network
{
return
&
network
{
clients
:
make
(
map
[
util
.
Key
]
bsnet
.
Receiver
),
delay
:
d
,
}
}
type
network
struct
{
clients
map
[
util
.
Key
]
bsnet
.
Receiver
delay
delay
.
D
}
func
(
n
*
network
)
Adapter
(
p
peer
.
Peer
)
bsnet
.
BitSwapNetwork
{
...
...
@@ -84,13 +87,15 @@ func (n *network) deliver(
return
errors
.
New
(
"Invalid input"
)
}
n
.
delay
.
Wait
()
nextPeer
,
nextMsg
:=
r
.
ReceiveMessage
(
context
.
TODO
(),
from
,
message
)
if
(
nextPeer
==
nil
&&
nextMsg
!=
nil
)
||
(
nextMsg
==
nil
&&
nextPeer
!=
nil
)
{
return
errors
.
New
(
"Malformed client request"
)
}
if
nextPeer
==
nil
&&
nextMsg
==
nil
{
if
nextPeer
==
nil
&&
nextMsg
==
nil
{
// no response to send
return
nil
}
...
...
testnet/network_test.go
View file @
7d7fd57a
...
...
@@ -9,11 +9,12 @@ import (
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer
"github.com/jbenet/go-ipfs/peer"
delay
"github.com/jbenet/go-ipfs/util/delay"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestSendRequestToCooperativePeer
(
t
*
testing
.
T
)
{
net
:=
VirtualNetwork
()
net
:=
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
idOfRecipient
:=
[]
byte
(
"recipient"
)
...
...
@@ -60,7 +61,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
}
func
TestSendMessageAsyncButWaitForResponse
(
t
*
testing
.
T
)
{
net
:=
VirtualNetwork
()
net
:=
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
idOfResponder
:=
[]
byte
(
"responder"
)
waiter
:=
net
.
Adapter
(
testutil
.
NewPeerWithIDString
(
"waiter"
))
responder
:=
net
.
Adapter
(
testutil
.
NewPeerWithID
(
idOfResponder
))
...
...
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