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
p2p
go-reuseport-transport
Commits
32c2e408
Commit
32c2e408
authored
Mar 29, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test ipv6
parent
0e2041a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
29 deletions
+62
-29
transport_test.go
transport_test.go
+62
-29
No files found.
transport_test.go
View file @
32c2e408
...
...
@@ -8,10 +8,13 @@ import (
manet
"github.com/multiformats/go-multiaddr-net"
)
var
loopback
,
_
=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/tcp/0"
)
var
unspec
,
_
=
ma
.
NewMultiaddr
(
"/ip4/0.0.0.0/tcp/0"
)
var
loopbackV4
,
_
=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/tcp/0"
)
var
loopbackV6
,
_
=
ma
.
NewMultiaddr
(
"/ip6/::1/tcp/0"
)
var
unspecV6
,
_
=
ma
.
NewMultiaddr
(
"/ip6/::/tcp/0"
)
var
unspecV4
,
_
=
ma
.
NewMultiaddr
(
"/ip4/0.0.0.0/tcp/0"
)
var
global
ma
.
Multiaddr
var
globalV4
ma
.
Multiaddr
var
globalV6
ma
.
Multiaddr
func
init
()
{
addrs
,
err
:=
manet
.
InterfaceMultiaddrs
()
...
...
@@ -21,8 +24,16 @@ func init() {
for
_
,
addr
:=
range
addrs
{
if
!
manet
.
IsIP6LinkLocal
(
addr
)
&&
!
manet
.
IsIPLoopback
(
addr
)
{
tcp
,
_
:=
ma
.
NewMultiaddr
(
"/tcp/0"
)
global
=
addr
.
Encapsulate
(
tcp
)
return
switch
addr
.
Protocols
()[
0
]
.
Code
{
case
ma
.
P_IP4
:
if
globalV4
==
nil
{
globalV4
=
addr
.
Encapsulate
(
tcp
)
}
case
ma
.
P_IP6
:
if
globalV6
==
nil
{
globalV6
=
addr
.
Encapsulate
(
tcp
)
}
}
}
}
}
...
...
@@ -68,7 +79,7 @@ func dialOne(t *testing.T, tr *Transport, listener manet.Listener, expected ...i
func
TestNoneAndSingle
(
t
*
testing
.
T
)
{
var
trA
Transport
var
trB
Transport
listenerA
,
err
:=
trA
.
Listen
(
loopback
)
listenerA
,
err
:=
trA
.
Listen
(
loopback
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -76,7 +87,7 @@ func TestNoneAndSingle(t *testing.T) {
dialOne
(
t
,
&
trB
,
listenerA
)
listenerB
,
err
:=
trB
.
Listen
(
loopback
)
listenerB
,
err
:=
trB
.
Listen
(
loopback
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -88,19 +99,19 @@ func TestNoneAndSingle(t *testing.T) {
func
TestTwoLocal
(
t
*
testing
.
T
)
{
var
trA
Transport
var
trB
Transport
listenerA
,
err
:=
trA
.
Listen
(
loopback
)
listenerA
,
err
:=
trA
.
Listen
(
loopback
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerA
.
Close
()
listenerB1
,
err
:=
trB
.
Listen
(
loopback
)
listenerB1
,
err
:=
trB
.
Listen
(
loopback
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerB1
.
Close
()
listenerB2
,
err
:=
trB
.
Listen
(
loopback
)
listenerB2
,
err
:=
trB
.
Listen
(
loopback
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -111,20 +122,33 @@ func TestTwoLocal(t *testing.T) {
listenerB2
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
)
}
func
TestGlobalPreference
(
t
*
testing
.
T
)
{
if
global
==
nil
{
t
.
Skip
(
"no global addresses configured"
)
func
TestGlobalPreference
V4
(
t
*
testing
.
T
)
{
if
global
V4
==
nil
{
t
.
Skip
(
"no global
IPv4
addresses configured"
)
return
}
testPrefer
(
t
,
loopback
,
loopback
,
global
)
testPrefer
(
t
,
loopback
,
unspec
,
global
)
testPrefer
(
t
,
loopback
V4
,
loopback
V4
,
global
V4
)
testPrefer
(
t
,
loopback
V4
,
unspec
V4
,
global
V4
)
testPrefer
(
t
,
global
,
unspec
,
global
)
testPrefer
(
t
,
global
,
unspec
,
loopback
)
testPrefer
(
t
,
globalV4
,
unspecV4
,
globalV4
)
testPrefer
(
t
,
globalV4
,
unspecV4
,
loopbackV4
)
}
func
TestGlobalPreferenceV6
(
t
*
testing
.
T
)
{
if
globalV6
==
nil
{
t
.
Skip
(
"no global IPv6 addresses configured"
)
return
}
testPrefer
(
t
,
loopbackV6
,
loopbackV6
,
globalV6
)
testPrefer
(
t
,
loopbackV6
,
unspecV6
,
globalV6
)
testPrefer
(
t
,
globalV6
,
unspecV6
,
globalV6
)
testPrefer
(
t
,
globalV6
,
unspecV6
,
loopbackV6
)
}
func
TestLoopbackPreference
(
t
*
testing
.
T
)
{
testPrefer
(
t
,
loopback
,
loopback
,
unspec
)
testPrefer
(
t
,
loopbackV4
,
loopbackV4
,
unspecV4
)
testPrefer
(
t
,
loopbackV6
,
loopbackV6
,
unspecV6
)
}
func
testPrefer
(
t
*
testing
.
T
,
listen
,
prefer
,
avoid
ma
.
Multiaddr
)
{
...
...
@@ -158,21 +182,30 @@ func testPrefer(t *testing.T, listen, prefer, avoid ma.Multiaddr) {
dialOne
(
t
,
&
trB
,
listenerA
,
listenerB1
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
)
}
func
TestV6V4
(
t
*
testing
.
T
)
{
testUseFirst
(
t
,
loopbackV4
,
loopbackV4
,
loopbackV6
)
testUseFirst
(
t
,
loopbackV6
,
loopbackV6
,
loopbackV4
)
}
func
TestGlobalToGlobal
(
t
*
testing
.
T
)
{
if
global
==
nil
{
t
.
Skip
(
"no global addresses configured"
)
if
global
V4
==
nil
{
t
.
Skip
(
"no global
V4
addresses configured"
)
return
}
testUseFirst
(
t
,
globalV4
,
globalV4
,
loopbackV4
)
testUseFirst
(
t
,
globalV6
,
globalV6
,
loopbackV6
)
}
func
testUseFirst
(
t
*
testing
.
T
,
listen
,
use
,
never
ma
.
Multiaddr
)
{
var
trA
Transport
var
trB
Transport
listenerA
,
err
:=
trA
.
Listen
(
global
)
listenerA
,
err
:=
trA
.
Listen
(
global
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerA
.
Close
()
listenerB1
,
err
:=
trB
.
Listen
(
loopback
)
listenerB1
,
err
:=
trB
.
Listen
(
loopback
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -181,13 +214,13 @@ func TestGlobalToGlobal(t *testing.T) {
// It works (random port)
dialOne
(
t
,
&
trB
,
listenerA
)
listenerB2
,
err
:=
trB
.
Listen
(
global
)
listenerB2
,
err
:=
trB
.
Listen
(
global
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerB2
.
Close
()
// Uses global port.
// Uses global
V4
port.
dialOne
(
t
,
&
trB
,
listenerA
,
listenerB2
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
)
// Closing the listener should reset the dialer.
...
...
@@ -198,26 +231,26 @@ func TestGlobalToGlobal(t *testing.T) {
}
func
TestDuplicateGlobal
(
t
*
testing
.
T
)
{
if
global
==
nil
{
t
.
Skip
(
"no global addresses configured"
)
if
global
V4
==
nil
{
t
.
Skip
(
"no global
V4
addresses configured"
)
return
}
var
trA
Transport
var
trB
Transport
listenerA
,
err
:=
trA
.
Listen
(
global
)
listenerA
,
err
:=
trA
.
Listen
(
global
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerA
.
Close
()
listenerB1
,
err
:=
trB
.
Listen
(
global
)
listenerB1
,
err
:=
trB
.
Listen
(
global
V4
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerB1
.
Close
()
listenerB2
,
err
:=
trB
.
Listen
(
global
)
listenerB2
,
err
:=
trB
.
Listen
(
global
V4
)
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