diff --git a/testing/scenarios/common.go b/testing/scenarios/common.go index bdeec7a88..ed9d9e04b 100644 --- a/testing/scenarios/common.go +++ b/testing/scenarios/common.go @@ -29,18 +29,6 @@ func pickPort() net.Port { return net.Port(addr.Port) } -func pickUDPPort() net.Port { - conn, err := net.ListenUDP("udp4", &net.UDPAddr{ - IP: net.LocalHostIP.IP(), - Port: 0, - }) - common.Must(err) - defer conn.Close() - - addr := conn.LocalAddr().(*net.UDPAddr) - return net.Port(addr.Port) -} - func xor(b []byte) []byte { r := make([]byte, len(b)) for i, v := range b { diff --git a/testing/scenarios/tls_test.go b/testing/scenarios/tls_test.go index 9186cfd5d..76987d7a3 100644 --- a/testing/scenarios/tls_test.go +++ b/testing/scenarios/tls_test.go @@ -17,6 +17,7 @@ import ( "v2ray.com/core/proxy/vmess/inbound" "v2ray.com/core/proxy/vmess/outbound" "v2ray.com/core/testing/servers/tcp" + "v2ray.com/core/testing/servers/udp" tlsgen "v2ray.com/core/testing/tls" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" @@ -149,7 +150,7 @@ func TestTLSOverKCP(t *testing.T) { defer tcpServer.Close() userID := protocol.NewID(uuid.New()) - serverPort := pickUDPPort() + serverPort := udp.PickPort() serverConfig := &core.Config{ Inbound: []*proxyman.InboundHandlerConfig{ { diff --git a/testing/scenarios/vmess_test.go b/testing/scenarios/vmess_test.go index 04b043560..067d14d57 100644 --- a/testing/scenarios/vmess_test.go +++ b/testing/scenarios/vmess_test.go @@ -674,7 +674,7 @@ func TestVMessKCP(t *testing.T) { defer tcpServer.Close() userID := protocol.NewID(uuid.New()) - serverPort := pickUDPPort() + serverPort := udp.PickPort() serverConfig := &core.Config{ App: []*serial.TypedMessage{ serial.ToTypedMessage(&log.Config{ @@ -1098,7 +1098,7 @@ func TestVMessGCMMuxUDP(t *testing.T) { } clientPort := pickPort() - clientUDPPort := pickUDPPort() + clientUDPPort := udp.PickPort() clientConfig := &core.Config{ App: []*serial.TypedMessage{ serial.ToTypedMessage(&log.Config{ diff --git a/testing/servers/udp/port.go b/testing/servers/udp/port.go new file mode 100644 index 000000000..0c77c4cff --- /dev/null +++ b/testing/servers/udp/port.go @@ -0,0 +1,18 @@ +package udp + +import ( + "v2ray.com/core/common" + "v2ray.com/core/common/net" +) + +func PickPort() net.Port { + conn, err := net.ListenUDP("udp4", &net.UDPAddr{ + IP: net.LocalHostIP.IP(), + Port: 0, + }) + common.Must(err) + defer conn.Close() + + addr := conn.LocalAddr().(*net.UDPAddr) + return net.Port(addr.Port) +}