forked from database64128/tfo-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tfo_supported_test.go
96 lines (86 loc) · 1.88 KB
/
tfo_supported_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//go:build darwin || freebsd || linux || windows
package tfo
import (
"net"
"testing"
)
func testClientWriteReadServerReadWriteTCPAddr(listenTCPAddr, dialLocalTCPAddr *net.TCPAddr, t *testing.T) {
t.Logf("c->s payload: %v", helloworld)
t.Logf("s->c payload: %v", worldhello)
lntcp, err := ListenTCP("tcp", listenTCPAddr)
if err != nil {
t.Fatal(err)
}
defer lntcp.Close()
t.Log("Started listener on", lntcp.Addr())
ctrlCh := make(chan struct{})
go func() {
conn, err := lntcp.AcceptTCP()
if err != nil {
t.Error(err)
return
}
defer conn.Close()
t.Log("Accepted", conn.RemoteAddr())
readUntilEOF(conn, helloworld, t)
write(conn, world, t)
write(conn, hello, t)
conn.CloseWrite()
close(ctrlCh)
}()
port := lntcp.Addr().(*net.TCPAddr).Port
ip := net.IPv6loopback
if listenTCPAddr != nil && listenTCPAddr.IP != nil {
ip = listenTCPAddr.IP
}
tc, err := DialTCP("tcp", dialLocalTCPAddr, &net.TCPAddr{
IP: ip,
Port: port,
}, hello)
if err != nil {
t.Fatal(err)
}
defer tc.Close()
write(tc, world, t)
tc.CloseWrite()
readUntilEOF(tc, worldhello, t)
<-ctrlCh
}
func TestClientWriteReadServerReadWriteTCPAddr(t *testing.T) {
for _, c := range []struct {
name string
listenTCPAddr *net.TCPAddr
dialLocalTCPAddr *net.TCPAddr
}{
{
name: "Unspecified",
listenTCPAddr: nil,
dialLocalTCPAddr: nil,
},
{
name: "IPv4Loopback",
listenTCPAddr: &net.TCPAddr{
IP: net.IPv4(127, 0, 0, 1),
},
dialLocalTCPAddr: nil,
},
{
name: "IPv6Loopback",
listenTCPAddr: &net.TCPAddr{
IP: net.IPv6loopback,
},
dialLocalTCPAddr: nil,
},
{
name: "DialBind",
listenTCPAddr: nil,
dialLocalTCPAddr: &net.TCPAddr{
IP: net.IPv6loopback,
},
},
} {
t.Run(c.name, func(t *testing.T) {
testClientWriteReadServerReadWriteTCPAddr(c.listenTCPAddr, c.dialLocalTCPAddr, t)
})
}
}