|
|
|
@ -36,7 +36,10 @@ func TestVMessDynamicPort(t *testing.T) {
|
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
|
|
|
|
|
|
retry := 1
|
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
|
for {
|
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
|
App: []*serial.TypedMessage{
|
|
|
|
|
serial.ToTypedMessage(&log.Config{
|
|
|
|
@ -63,11 +66,24 @@ func TestVMessDynamicPort(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
|
PortRange: net.SinglePortRange(serverPort + 100),
|
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
|
}),
|
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
|
PortRange: &net.PortRange{
|
|
|
|
|
From: uint32(serverPort + 1),
|
|
|
|
|
To: uint32(serverPort + 100),
|
|
|
|
|
To: uint32(serverPort + 99),
|
|
|
|
|
},
|
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
|
AllocationStrategy: &proxyman.AllocationStrategy{
|
|
|
|
@ -91,6 +107,18 @@ func TestVMessDynamicPort(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server, _ := InitializeServerConfig(serverConfig)
|
|
|
|
|
if server != nil && tcpConnAvailableAtPort(t, serverPort + 100) {
|
|
|
|
|
defer CloseServer(server)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
retry += 1
|
|
|
|
|
if (retry > 5) {
|
|
|
|
|
t.Fatal("All attempts failed to start server")
|
|
|
|
|
}
|
|
|
|
|
serverPort = tcp.PickPort()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clientPort := tcp.PickPort()
|
|
|
|
|
clientConfig := &core.Config{
|
|
|
|
|
App: []*serial.TypedMessage{
|
|
|
|
@ -135,15 +163,30 @@ func TestVMessDynamicPort(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
|
server, err := InitializeServerConfig(clientConfig)
|
|
|
|
|
common.Must(err)
|
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
defer CloseServer(server)
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
if !tcpConnAvailableAtPort(t, clientPort) {
|
|
|
|
|
t.Fail()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func tcpConnAvailableAtPort(t *testing.T, port net.Port) bool {
|
|
|
|
|
for i := 1; ; i++ {
|
|
|
|
|
if (i > 10) {
|
|
|
|
|
t.Log("All attempts failed to test tcp conn")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
time.Sleep(time.Millisecond * 10)
|
|
|
|
|
if err := testTCPConn(port, 1024, time.Second*2)(); err != nil {
|
|
|
|
|
t.Log("err ", err)
|
|
|
|
|
} else {
|
|
|
|
|
t.Log("success with", i, "attempts")
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestVMessGCM(t *testing.T) {
|
|
|
|
|