mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
Break shadowsocks2022 test into Tcp and Udp
- make test smaller - pickPort is more reliable for only Tcp or Udp
This commit is contained in:
parent
7b72e19e16
commit
d56f38d38e
@ -490,17 +490,27 @@ func TestShadowsocksNone(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestShadowsocks2022(t *testing.T) {
|
||||
func TestShadowsocks2022Tcp(t *testing.T) {
|
||||
for _, method := range shadowaead_2022.List {
|
||||
password := make([]byte, 32)
|
||||
rand.Read(password)
|
||||
t.Run(method, func(t *testing.T) {
|
||||
testShadowsocks2022(t, method, base64.StdEncoding.EncodeToString(password))
|
||||
testShadowsocks2022Tcp(t, method, base64.StdEncoding.EncodeToString(password))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testShadowsocks2022(t *testing.T, method string, password string) {
|
||||
func TestShadowsocks2022Udp(t *testing.T) {
|
||||
for _, method := range shadowaead_2022.List {
|
||||
password := make([]byte, 32)
|
||||
rand.Read(password)
|
||||
t.Run(method, func(t *testing.T) {
|
||||
testShadowsocks2022Udp(t, method, base64.StdEncoding.EncodeToString(password))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testShadowsocks2022Tcp(t *testing.T, method string, password string) {
|
||||
tcpServer := tcp.Server{
|
||||
MsgProcessor: xor,
|
||||
}
|
||||
@ -508,13 +518,6 @@ func testShadowsocks2022(t *testing.T, method string, password string) {
|
||||
common.Must(err)
|
||||
defer tcpServer.Close()
|
||||
|
||||
udpServer := udp.Server{
|
||||
MsgProcessor: xor,
|
||||
}
|
||||
udpDest, err := udpServer.Start()
|
||||
common.Must(err)
|
||||
defer udpServer.Close()
|
||||
|
||||
serverPort := tcp.PickPort()
|
||||
serverConfig := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
@ -532,7 +535,7 @@ func testShadowsocks2022(t *testing.T, method string, password string) {
|
||||
ProxySettings: serial.ToTypedMessage(&shadowsocks_2022.ServerConfig{
|
||||
Method: method,
|
||||
Key: password,
|
||||
Network: []net.Network{net.Network_TCP, net.Network_UDP},
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
}),
|
||||
},
|
||||
},
|
||||
@ -544,7 +547,6 @@ func testShadowsocks2022(t *testing.T, method string, password string) {
|
||||
}
|
||||
|
||||
clientPort := tcp.PickPort()
|
||||
udpClientPort := udp.PickPort()
|
||||
clientConfig := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&log.Config{
|
||||
@ -564,6 +566,78 @@ func testShadowsocks2022(t *testing.T, method string, password string) {
|
||||
Networks: []net.Network{net.Network_TCP},
|
||||
}),
|
||||
},
|
||||
},
|
||||
Outbound: []*core.OutboundHandlerConfig{
|
||||
{
|
||||
ProxySettings: serial.ToTypedMessage(&shadowsocks_2022.ClientConfig{
|
||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
||||
Port: uint32(serverPort),
|
||||
Method: method,
|
||||
Key: password,
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
||||
common.Must(err)
|
||||
defer CloseAllServers(servers)
|
||||
|
||||
var errGroup errgroup.Group
|
||||
for i := 0; i < 10; i++ {
|
||||
errGroup.Go(testTCPConn(clientPort, 10240*1024, time.Second*20))
|
||||
}
|
||||
|
||||
if err := errGroup.Wait(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testShadowsocks2022Udp(t *testing.T, method string, password string) {
|
||||
udpServer := udp.Server{
|
||||
MsgProcessor: xor,
|
||||
}
|
||||
udpDest, err := udpServer.Start()
|
||||
common.Must(err)
|
||||
defer udpServer.Close()
|
||||
|
||||
serverPort := udp.PickPort()
|
||||
serverConfig := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&log.Config{
|
||||
ErrorLogLevel: clog.Severity_Debug,
|
||||
ErrorLogType: log.LogType_Console,
|
||||
}),
|
||||
},
|
||||
Inbound: []*core.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&shadowsocks_2022.ServerConfig{
|
||||
Method: method,
|
||||
Key: password,
|
||||
Network: []net.Network{net.Network_UDP},
|
||||
}),
|
||||
},
|
||||
},
|
||||
Outbound: []*core.OutboundHandlerConfig{
|
||||
{
|
||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
udpClientPort := udp.PickPort()
|
||||
clientConfig := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&log.Config{
|
||||
ErrorLogLevel: clog.Severity_Debug,
|
||||
ErrorLogType: log.LogType_Console,
|
||||
}),
|
||||
},
|
||||
Inbound: []*core.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(udpClientPort)}},
|
||||
@ -593,9 +667,6 @@ func testShadowsocks2022(t *testing.T, method string, password string) {
|
||||
defer CloseAllServers(servers)
|
||||
|
||||
var errGroup errgroup.Group
|
||||
for i := 0; i < 10; i++ {
|
||||
errGroup.Go(testTCPConn(clientPort, 10240*1024, time.Second*20))
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
errGroup.Go(testUDPConn(udpClientPort, 1024, time.Second*5))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user