move port allocation to udp package

This commit is contained in:
Darien Raymond committed 2017-11-14 23:45:07 +01:00
1 parent 268d7264e8
commit a430e2065a
4 files changed
+22 -15

No files matched your search

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