1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -05:00

move port allocation to udp package

This commit is contained in:
Darien Raymond 2017-11-14 23:45:07 +01:00
parent 268d7264e8
commit a430e2065a
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 22 additions and 15 deletions

View File

@ -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 {

View File

@ -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{
{

View File

@ -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{

View 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)
}