Explorar o código

move port allocation to udp package

Darien Raymond %!s(int64=8) %!d(string=hai) anos
pai
achega
a430e2065a

+ 0 - 12
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 {

+ 2 - 1
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{
 			{

+ 2 - 2
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{

+ 18 - 0
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)
+}