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
4edd768c
Commit
4edd768c
authored
Dec 23, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pass peer into testnet adapter method
parent
20acf8b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
15 deletions
+16
-15
testnet/network.go
testnet/network.go
+6
-5
testnet/network_test.go
testnet/network_test.go
+9
-9
testutils.go
testutils.go
+1
-1
No files found.
testnet/network.go
View file @
4edd768c
...
@@ -12,10 +12,11 @@ import (
...
@@ -12,10 +12,11 @@ import (
mockrouting
"github.com/jbenet/go-ipfs/routing/mock"
mockrouting
"github.com/jbenet/go-ipfs/routing/mock"
util
"github.com/jbenet/go-ipfs/util"
util
"github.com/jbenet/go-ipfs/util"
delay
"github.com/jbenet/go-ipfs/util/delay"
delay
"github.com/jbenet/go-ipfs/util/delay"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
)
type
Network
interface
{
type
Network
interface
{
Adapter
(
peer
.
ID
)
bsnet
.
BitSwapNetwork
Adapter
(
testutil
.
Peer
)
bsnet
.
BitSwapNetwork
HasPeer
(
peer
.
ID
)
bool
HasPeer
(
peer
.
ID
)
bool
}
}
...
@@ -36,13 +37,13 @@ type network struct {
...
@@ -36,13 +37,13 @@ type network struct {
delay
delay
.
D
delay
delay
.
D
}
}
func
(
n
*
network
)
Adapter
(
p
peer
.
ID
)
bsnet
.
BitSwapNetwork
{
func
(
n
*
network
)
Adapter
(
p
testutil
.
Peer
)
bsnet
.
BitSwapNetwork
{
client
:=
&
networkClient
{
client
:=
&
networkClient
{
local
:
p
,
local
:
p
.
ID
()
,
network
:
n
,
network
:
n
,
routing
:
n
.
routingserver
.
Client
(
peer
.
PeerInfo
{
ID
:
p
}),
routing
:
n
.
routingserver
.
Client
(
peer
.
PeerInfo
{
ID
:
p
.
ID
()
}),
}
}
n
.
clients
[
p
]
=
client
n
.
clients
[
p
.
ID
()
]
=
client
return
client
return
client
}
}
...
...
testnet/network_test.go
View file @
4edd768c
...
@@ -5,24 +5,24 @@ import (
...
@@ -5,24 +5,24 @@ import (
"testing"
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
blocks
"github.com/jbenet/go-ipfs/blocks"
blocks
"github.com/jbenet/go-ipfs/blocks"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer
"github.com/jbenet/go-ipfs/peer"
peer
"github.com/jbenet/go-ipfs/peer"
mockrouting
"github.com/jbenet/go-ipfs/routing/mock"
mockrouting
"github.com/jbenet/go-ipfs/routing/mock"
delay
"github.com/jbenet/go-ipfs/util/delay"
delay
"github.com/jbenet/go-ipfs/util/delay"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
)
func
TestSendRequestToCooperativePeer
(
t
*
testing
.
T
)
{
func
TestSendRequestToCooperativePeer
(
t
*
testing
.
T
)
{
net
:=
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
0
))
net
:=
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
0
))
idOfR
ecipient
:=
peer
.
ID
(
"recipient"
)
r
ecipient
Peer
:=
testutil
.
RandPeerOrFatal
(
t
)
t
.
Log
(
"Get two network adapters"
)
t
.
Log
(
"Get two network adapters"
)
initiator
:=
net
.
Adapter
(
peer
.
ID
(
"initiator"
))
initiator
:=
net
.
Adapter
(
testutil
.
RandPeerOrFatal
(
t
))
recipient
:=
net
.
Adapter
(
idOfR
ecipient
)
recipient
:=
net
.
Adapter
(
r
ecipient
Peer
)
expectedStr
:=
"response from recipient"
expectedStr
:=
"response from recipient"
recipient
.
SetDelegate
(
lambda
(
func
(
recipient
.
SetDelegate
(
lambda
(
func
(
...
@@ -46,7 +46,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
...
@@ -46,7 +46,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
message
:=
bsmsg
.
New
()
message
:=
bsmsg
.
New
()
message
.
AddBlock
(
blocks
.
NewBlock
([]
byte
(
"data"
)))
message
.
AddBlock
(
blocks
.
NewBlock
([]
byte
(
"data"
)))
response
,
err
:=
initiator
.
SendRequest
(
response
,
err
:=
initiator
.
SendRequest
(
context
.
Background
(),
idOfR
ecipient
,
message
)
context
.
Background
(),
r
ecipient
Peer
.
ID
()
,
message
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -67,9 +67,9 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
...
@@ -67,9 +67,9 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
func
TestSendMessageAsyncButWaitForResponse
(
t
*
testing
.
T
)
{
func
TestSendMessageAsyncButWaitForResponse
(
t
*
testing
.
T
)
{
net
:=
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
0
))
net
:=
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
0
))
idOfR
esponder
:=
peer
.
ID
(
"responder"
)
r
esponder
Peer
:=
testutil
.
RandPeerOrFatal
(
t
)
waiter
:=
net
.
Adapter
(
peer
.
ID
(
"waiter"
))
waiter
:=
net
.
Adapter
(
testutil
.
RandPeerOrFatal
(
t
))
responder
:=
net
.
Adapter
(
idOfR
esponder
)
responder
:=
net
.
Adapter
(
r
esponder
Peer
)
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
...
@@ -114,7 +114,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
...
@@ -114,7 +114,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
messageSentAsync
:=
bsmsg
.
New
()
messageSentAsync
:=
bsmsg
.
New
()
messageSentAsync
.
AddBlock
(
blocks
.
NewBlock
([]
byte
(
"data"
)))
messageSentAsync
.
AddBlock
(
blocks
.
NewBlock
([]
byte
(
"data"
)))
errSending
:=
waiter
.
SendMessage
(
errSending
:=
waiter
.
SendMessage
(
context
.
Background
(),
idOfR
esponder
,
messageSentAsync
)
context
.
Background
(),
r
esponder
Peer
.
ID
()
,
messageSentAsync
)
if
errSending
!=
nil
{
if
errSending
!=
nil
{
t
.
Fatal
(
errSending
)
t
.
Fatal
(
errSending
)
}
}
...
...
testutils.go
View file @
4edd768c
...
@@ -80,7 +80,7 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
...
@@ -80,7 +80,7 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// just a much better idea.
// just a much better idea.
func
session
(
ctx
context
.
Context
,
net
tn
.
Network
,
p
testutil
.
Peer
)
Instance
{
func
session
(
ctx
context
.
Context
,
net
tn
.
Network
,
p
testutil
.
Peer
)
Instance
{
adapter
:=
net
.
Adapter
(
p
.
ID
()
)
adapter
:=
net
.
Adapter
(
p
)
bsdelay
:=
delay
.
Fixed
(
0
)
bsdelay
:=
delay
.
Fixed
(
0
)
const
kWriteCacheElems
=
100
const
kWriteCacheElems
=
100
...
...
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