mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
move port allocation to udp package
This commit is contained in:
parent
268d7264e8
commit
a430e2065a
@ -29,18 +29,6 @@ func pickPort() net.Port {
|
|||||||
return net.Port(addr.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 {
|
func xor(b []byte) []byte {
|
||||||
r := make([]byte, len(b))
|
r := make([]byte, len(b))
|
||||||
for i, v := range b {
|
for i, v := range b {
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"v2ray.com/core/proxy/vmess/inbound"
|
"v2ray.com/core/proxy/vmess/inbound"
|
||||||
"v2ray.com/core/proxy/vmess/outbound"
|
"v2ray.com/core/proxy/vmess/outbound"
|
||||||
"v2ray.com/core/testing/servers/tcp"
|
"v2ray.com/core/testing/servers/tcp"
|
||||||
|
"v2ray.com/core/testing/servers/udp"
|
||||||
tlsgen "v2ray.com/core/testing/tls"
|
tlsgen "v2ray.com/core/testing/tls"
|
||||||
"v2ray.com/core/transport/internet"
|
"v2ray.com/core/transport/internet"
|
||||||
"v2ray.com/core/transport/internet/tls"
|
"v2ray.com/core/transport/internet/tls"
|
||||||
@ -149,7 +150,7 @@ func TestTLSOverKCP(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickUDPPort()
|
serverPort := udp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*proxyman.InboundHandlerConfig{
|
Inbound: []*proxyman.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
|
@ -674,7 +674,7 @@ func TestVMessKCP(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickUDPPort()
|
serverPort := udp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -1098,7 +1098,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := pickPort()
|
||||||
clientUDPPort := pickUDPPort()
|
clientUDPPort := udp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
|
18
testing/servers/udp/port.go
Normal file
18
testing/servers/udp/port.go
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user