mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-04 16:37:12 -05:00
move tcp.PickPort to its own package
This commit is contained in:
parent
a7d467992d
commit
af29e42771
@ -37,8 +37,8 @@ func TestCommanderRemoveHandler(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
cmdPort := pickPort()
|
cmdPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&commander.Config{
|
serial.ToTypedMessage(&commander.Config{
|
||||||
@ -150,8 +150,8 @@ func TestCommanderAddRemoveUser(t *testing.T) {
|
|||||||
u1 := protocol.NewID(uuid.New())
|
u1 := protocol.NewID(uuid.New())
|
||||||
u2 := protocol.NewID(uuid.New())
|
u2 := protocol.NewID(uuid.New())
|
||||||
|
|
||||||
cmdPort := pickPort()
|
cmdPort := tcp.PickPort()
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&commander.Config{
|
serial.ToTypedMessage(&commander.Config{
|
||||||
@ -219,7 +219,7 @@ func TestCommanderAddRemoveUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&policy.Config{
|
serial.ToTypedMessage(&policy.Config{
|
||||||
|
@ -22,15 +22,6 @@ import (
|
|||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pickPort() net.Port {
|
|
||||||
listener, err := net.Listen("tcp4", "127.0.0.1:0")
|
|
||||||
common.Must(err)
|
|
||||||
defer listener.Close()
|
|
||||||
|
|
||||||
addr := listener.Addr().(*net.TCPAddr)
|
|
||||||
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 {
|
||||||
|
@ -28,7 +28,7 @@ func TestResolveIP(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&dns.Config{
|
serial.ToTypedMessage(&dns.Config{
|
||||||
|
@ -32,7 +32,7 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -64,7 +64,7 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := uint32(pickPort())
|
clientPort := uint32(tcp.PickPort())
|
||||||
clientPortRange := uint32(5)
|
clientPortRange := uint32(5)
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
@ -145,7 +145,7 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
defer udpServer.Close()
|
defer udpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -171,7 +171,7 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := uint32(pickPort())
|
clientPort := uint32(tcp.PickPort())
|
||||||
clientPortRange := uint32(5)
|
clientPortRange := uint32(5)
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
|
@ -46,7 +46,7 @@ func TestPassiveConnection(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -117,7 +117,7 @@ func TestProxy(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
serverUserID := protocol.NewID(uuid.New())
|
serverUserID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -144,7 +144,7 @@ func TestProxy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proxyUserID := protocol.NewID(uuid.New())
|
proxyUserID := protocol.NewID(uuid.New())
|
||||||
proxyPort := pickPort()
|
proxyPort := tcp.PickPort()
|
||||||
proxyConfig := &core.Config{
|
proxyConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -170,7 +170,7 @@ func TestProxy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -265,7 +265,7 @@ func TestProxyOverKCP(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
serverUserID := protocol.NewID(uuid.New())
|
serverUserID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -295,7 +295,7 @@ func TestProxyOverKCP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proxyUserID := protocol.NewID(uuid.New())
|
proxyUserID := protocol.NewID(uuid.New())
|
||||||
proxyPort := pickPort()
|
proxyPort := tcp.PickPort()
|
||||||
proxyConfig := &core.Config{
|
proxyConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -326,7 +326,7 @@ func TestProxyOverKCP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -430,8 +430,8 @@ func TestBlackhole(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer tcpServer2.Close()
|
defer tcpServer2.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverPort2 := pickPort()
|
serverPort2 := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -521,7 +521,7 @@ func TestForward(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -587,7 +587,7 @@ func TestUDPConnection(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer udpServer.Close()
|
defer udpServer.Close()
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -663,8 +663,8 @@ func TestUDPConnection(t *testing.T) {
|
|||||||
func TestDomainSniffing(t *testing.T) {
|
func TestDomainSniffing(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
sniffingPort := pickPort()
|
sniffingPort := tcp.PickPort()
|
||||||
httpPort := pickPort()
|
httpPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -764,7 +764,7 @@ func TestDialV2Ray(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
func TestHttpConformance(t *testing.T) {
|
func TestHttpConformance(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
httpServerPort := pickPort()
|
httpServerPort := tcp.PickPort()
|
||||||
httpServer := &v2httptest.Server{
|
httpServer := &v2httptest.Server{
|
||||||
Port: httpServerPort,
|
Port: httpServerPort,
|
||||||
PathHandler: make(map[string]http.HandlerFunc),
|
PathHandler: make(map[string]http.HandlerFunc),
|
||||||
@ -35,7 +35,7 @@ func TestHttpConformance(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer httpServer.Close()
|
defer httpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -90,7 +90,7 @@ func TestHttpConnectMethod(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -146,7 +146,7 @@ func TestHttpConnectMethod(t *testing.T) {
|
|||||||
func TestHttpPost(t *testing.T) {
|
func TestHttpPost(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
httpServerPort := pickPort()
|
httpServerPort := tcp.PickPort()
|
||||||
httpServer := &v2httptest.Server{
|
httpServer := &v2httptest.Server{
|
||||||
Port: httpServerPort,
|
Port: httpServerPort,
|
||||||
PathHandler: map[string]http.HandlerFunc{
|
PathHandler: map[string]http.HandlerFunc{
|
||||||
@ -169,7 +169,7 @@ func TestHttpPost(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer httpServer.Close()
|
defer httpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -226,7 +226,7 @@ func setProxyBasicAuth(req *http.Request, user, pass string) {
|
|||||||
func TestHttpBasicAuth(t *testing.T) {
|
func TestHttpBasicAuth(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
httpServerPort := pickPort()
|
httpServerPort := tcp.PickPort()
|
||||||
httpServer := &v2httptest.Server{
|
httpServer := &v2httptest.Server{
|
||||||
Port: httpServerPort,
|
Port: httpServerPort,
|
||||||
PathHandler: make(map[string]http.HandlerFunc),
|
PathHandler: make(map[string]http.HandlerFunc),
|
||||||
@ -235,7 +235,7 @@ func TestHttpBasicAuth(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer httpServer.Close()
|
defer httpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"v2ray.com/core/proxy/vmess"
|
"v2ray.com/core/proxy/vmess"
|
||||||
"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/ext/assert"
|
. "v2ray.com/ext/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ func TestVMessClosing(t *testing.T) {
|
|||||||
dest := net.DestinationFromAddr(tcpServer.Addr())
|
dest := net.DestinationFromAddr(tcpServer.Addr())
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&policy.Config{
|
serial.ToTypedMessage(&policy.Config{
|
||||||
@ -88,7 +89,7 @@ func TestVMessClosing(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&policy.Config{
|
serial.ToTypedMessage(&policy.Config{
|
||||||
|
@ -41,7 +41,7 @@ func TestShadowsocksAES256TCP(t *testing.T) {
|
|||||||
Ota: shadowsocks.Account_Enabled,
|
Ota: shadowsocks.Account_Enabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -70,7 +70,7 @@ func TestShadowsocksAES256TCP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -159,7 +159,7 @@ func TestShadowsocksAES128UDP(t *testing.T) {
|
|||||||
Ota: shadowsocks.Account_Enabled,
|
Ota: shadowsocks.Account_Enabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -189,7 +189,7 @@ func TestShadowsocksAES128UDP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -278,7 +278,7 @@ func TestShadowsocksChacha20TCP(t *testing.T) {
|
|||||||
Ota: shadowsocks.Account_Enabled,
|
Ota: shadowsocks.Account_Enabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -307,7 +307,7 @@ func TestShadowsocksChacha20TCP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -395,7 +395,7 @@ func TestShadowsocksAES256GCMTCP(t *testing.T) {
|
|||||||
CipherType: shadowsocks.CipherType_AES_256_GCM,
|
CipherType: shadowsocks.CipherType_AES_256_GCM,
|
||||||
})
|
})
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -424,7 +424,7 @@ func TestShadowsocksAES256GCMTCP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -512,7 +512,7 @@ func TestShadowsocksAES128GCMUDP(t *testing.T) {
|
|||||||
CipherType: shadowsocks.CipherType_AES_128_GCM,
|
CipherType: shadowsocks.CipherType_AES_128_GCM,
|
||||||
})
|
})
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -542,7 +542,7 @@ func TestShadowsocksAES128GCMUDP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -630,7 +630,7 @@ func TestShadowsocksAES256GCMConformance(t *testing.T) {
|
|||||||
CipherType: shadowsocks.CipherType_AES_256_GCM,
|
CipherType: shadowsocks.CipherType_AES_256_GCM,
|
||||||
})
|
})
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -708,7 +708,7 @@ func TestShadowsocksChacha20Poly1305UDPConformance(t *testing.T) {
|
|||||||
CipherType: shadowsocks.CipherType_CHACHA20_POLY1305,
|
CipherType: shadowsocks.CipherType_CHACHA20_POLY1305,
|
||||||
})
|
})
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -791,7 +791,7 @@ func TestShadowsocksChacha20Conformance(t *testing.T) {
|
|||||||
Ota: shadowsocks.Account_Disabled,
|
Ota: shadowsocks.Account_Disabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
|
@ -28,7 +28,7 @@ func TestSocksBridgeTCP(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -53,7 +53,7 @@ func TestSocksBridgeTCP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -125,7 +125,7 @@ func TestSocksBridageUDP(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer udpServer.Close()
|
defer udpServer.Close()
|
||||||
|
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -150,7 +150,7 @@ func TestSocksBridageUDP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -222,8 +222,8 @@ func TestSocksConformance(t *testing.T) {
|
|||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
authPort := pickPort()
|
authPort := tcp.PickPort()
|
||||||
noAuthPort := pickPort()
|
noAuthPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ func TestSimpleTLSConnection(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ func TestSimpleTLSConnection(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -185,7 +185,7 @@ func TestTLSOverKCP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -266,7 +266,7 @@ func TestTLSOverWebSocket(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -301,7 +301,7 @@ func TestTLSOverWebSocket(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ func TestHttpConnectionHeader(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
@ -69,7 +69,7 @@ func TestHttpConnectionHeader(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ func TestVMessDynamicPort(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -91,7 +91,7 @@ func TestVMessDynamicPort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -171,7 +171,7 @@ func TestVMessGCM(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -204,7 +204,7 @@ func TestVMessGCM(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -294,7 +294,7 @@ func TestVMessGCMUDP(t *testing.T) {
|
|||||||
defer udpServer.Close()
|
defer udpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -327,7 +327,7 @@ func TestVMessGCMUDP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -427,7 +427,7 @@ func TestVMessChacha20(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -460,7 +460,7 @@ func TestVMessChacha20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -550,7 +550,7 @@ func TestVMessNone(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -583,7 +583,7 @@ func TestVMessNone(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -711,7 +711,7 @@ func TestVMessKCP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -808,7 +808,7 @@ func TestVMessIPv6(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -841,7 +841,7 @@ func TestVMessIPv6(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -923,7 +923,7 @@ func TestVMessGCMMux(t *testing.T) {
|
|||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -956,7 +956,7 @@ func TestVMessGCMMux(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
clientPort := pickPort()
|
clientPort := tcp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
serial.ToTypedMessage(&log.Config{
|
serial.ToTypedMessage(&log.Config{
|
||||||
@ -1065,7 +1065,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
|
|||||||
defer udpServer.Close()
|
defer udpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
serverPort := pickPort()
|
serverPort := tcp.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 := tcp.PickPort()
|
||||||
clientUDPPort := udp.PickPort()
|
clientUDPPort := udp.PickPort()
|
||||||
clientConfig := &core.Config{
|
clientConfig := &core.Config{
|
||||||
App: []*serial.TypedMessage{
|
App: []*serial.TypedMessage{
|
||||||
|
16
testing/servers/tcp/port.go
Normal file
16
testing/servers/tcp/port.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package tcp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"v2ray.com/core/common"
|
||||||
|
"v2ray.com/core/common/net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PickPort returns an unused TCP port in the system. The port returned is highly likely to be unused, but not guaranteed.
|
||||||
|
func PickPort() net.Port {
|
||||||
|
listener, err := net.Listen("tcp4", "127.0.0.1:0")
|
||||||
|
common.Must(err)
|
||||||
|
defer listener.Close()
|
||||||
|
|
||||||
|
addr := listener.Addr().(*net.TCPAddr)
|
||||||
|
return net.Port(addr.Port)
|
||||||
|
}
|
@ -5,6 +5,7 @@ import (
|
|||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PickPort returns an unused UDP port in the system. The port returned is highly likely to be unused, but not guaranteed.
|
||||||
func PickPort() net.Port {
|
func PickPort() net.Port {
|
||||||
conn, err := net.ListenUDP("udp4", &net.UDPAddr{
|
conn, err := net.ListenUDP("udp4", &net.UDPAddr{
|
||||||
IP: net.LocalHostIP.IP(),
|
IP: net.LocalHostIP.IP(),
|
||||||
|
Loading…
Reference in New Issue
Block a user