-
Notifications
You must be signed in to change notification settings - Fork 1
/
gota_test.go
108 lines (94 loc) · 1.92 KB
/
gota_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
97
98
99
100
101
102
103
104
105
106
107
108
package gota
import (
"net"
"net/http"
"testing"
"time"
log "github.com/Sirupsen/logrus"
)
func TestGota_ListenAndServe(t *testing.T) {
saddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:32771")
// Gota Client
clientConfig := []TunnelActiveConfig{
{
LocalAddr: nil,
RemoteAddr: saddr,
},
{
LocalAddr: nil,
RemoteAddr: saddr,
},
{
LocalAddr: nil,
RemoteAddr: saddr,
},
{
LocalAddr: nil,
RemoteAddr: saddr,
},
{
LocalAddr: nil,
RemoteAddr: saddr,
},
{
LocalAddr: nil,
RemoteAddr: saddr,
},
}
client := NewGota(clientConfig, nil)
caddr := "127.0.0.1:32772"
go client.ListenAndServe(caddr)
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
time.Sleep(time.Second * 10)
}
func TestGota_ListenAndServe2(t *testing.T) {
saddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:32771")
// Gota Client
clientConfig := []TunnelActiveConfig{
{
LocalAddr: nil,
RemoteAddr: saddr,
},
}
client := NewGota(clientConfig, nil)
caddr := "127.0.0.1:32770"
go client.ListenAndServe(caddr)
go func() {
log.Println(http.ListenAndServe("localhost:6062", nil))
}()
time.Sleep(time.Second * 10)
}
func TestGota_Serve(t *testing.T) {
go func() {
addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:32773")
if err != nil {
log.Debug(err)
}
l, err := net.ListenTCP("tcp", addr)
if err != nil {
log.Debug(err)
}
conn, _ := l.AcceptTCP()
for {
data := make([]byte, 65536)
n, _ := conn.Read(data)
log.Infof("xxxxx: %s", string(data[:n]))
WriteNBytes(conn, n, data[:n])
}
}()
saddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:32771")
// Gota Server
serverConfig := TunnelPassiveConfig{
TCPAddr: saddr,
}
server := NewGota(serverConfig, nil)
//raddr := "baidu.com:80"
raddr := "127.0.0.1:3000"
go server.Serve(raddr)
go func() {
log.Println(http.ListenAndServe("localhost:6061", nil))
}()
time.Sleep(time.Second * 10)
}