mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 07:26:24 -05:00
remove port testing
This commit is contained in:
parent
338dc1ebb6
commit
a5a70afdb8
@ -1,10 +0,0 @@
|
|||||||
package testing
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/v2ray/v2ray-core/common/dice"
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
||||||
)
|
|
||||||
|
|
||||||
func PickPort() v2net.Port {
|
|
||||||
return v2net.Port(30000 + dice.Roll(20000))
|
|
||||||
}
|
|
@ -8,8 +8,8 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/app/dispatcher"
|
"github.com/v2ray/v2ray-core/app/dispatcher"
|
||||||
dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
|
dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
|
||||||
"github.com/v2ray/v2ray-core/app/proxyman"
|
"github.com/v2ray/v2ray-core/app/proxyman"
|
||||||
|
"github.com/v2ray/v2ray-core/common/dice"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
. "github.com/v2ray/v2ray-core/proxy/dokodemo"
|
. "github.com/v2ray/v2ray-core/proxy/dokodemo"
|
||||||
"github.com/v2ray/v2ray-core/proxy/freedom"
|
"github.com/v2ray/v2ray-core/proxy/freedom"
|
||||||
@ -23,7 +23,6 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
tcpServer := &tcp.Server{
|
tcpServer := &tcp.Server{
|
||||||
Port: v2nettesting.PickPort(),
|
|
||||||
MsgProcessor: func(data []byte) []byte {
|
MsgProcessor: func(data []byte) []byte {
|
||||||
buffer := make([]byte, 0, 2048)
|
buffer := make([]byte, 0, 2048)
|
||||||
buffer = append(buffer, []byte("Processed: ")...)
|
buffer = append(buffer, []byte("Processed: ")...)
|
||||||
@ -53,7 +52,7 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
|
|
||||||
data2Send := "Data to be sent to remote."
|
data2Send := "Data to be sent to remote."
|
||||||
|
|
||||||
port := v2nettesting.PickPort()
|
port := v2net.Port(dice.Roll(20000) + 10000)
|
||||||
dokodemo := NewDokodemoDoor(&Config{
|
dokodemo := NewDokodemoDoor(&Config{
|
||||||
Address: v2net.LocalHostIP,
|
Address: v2net.LocalHostIP,
|
||||||
Port: tcpServer.Port,
|
Port: tcpServer.Port,
|
||||||
@ -95,7 +94,6 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
udpServer := &udp.Server{
|
udpServer := &udp.Server{
|
||||||
Port: v2nettesting.PickPort(),
|
|
||||||
MsgProcessor: func(data []byte) []byte {
|
MsgProcessor: func(data []byte) []byte {
|
||||||
buffer := make([]byte, 0, 2048)
|
buffer := make([]byte, 0, 2048)
|
||||||
buffer = append(buffer, []byte("Processed: ")...)
|
buffer = append(buffer, []byte("Processed: ")...)
|
||||||
@ -124,7 +122,7 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
|
|
||||||
data2Send := "Data to be sent to remote."
|
data2Send := "Data to be sent to remote."
|
||||||
|
|
||||||
port := v2nettesting.PickPort()
|
port := v2net.Port(dice.Roll(20000) + 10000)
|
||||||
dokodemo := NewDokodemoDoor(&Config{
|
dokodemo := NewDokodemoDoor(&Config{
|
||||||
Address: v2net.LocalHostIP,
|
Address: v2net.LocalHostIP,
|
||||||
Port: udpServer.Port,
|
Port: udpServer.Port,
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/app/router/rules"
|
"github.com/v2ray/v2ray-core/app/router/rules"
|
||||||
"github.com/v2ray/v2ray-core/common/alloc"
|
"github.com/v2ray/v2ray-core/common/alloc"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
. "github.com/v2ray/v2ray-core/proxy/freedom"
|
. "github.com/v2ray/v2ray-core/proxy/freedom"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
@ -24,10 +23,8 @@ import (
|
|||||||
|
|
||||||
func TestSinglePacket(t *testing.T) {
|
func TestSinglePacket(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
port := v2nettesting.PickPort()
|
|
||||||
|
|
||||||
tcpServer := &tcp.Server{
|
tcpServer := &tcp.Server{
|
||||||
Port: port,
|
|
||||||
MsgProcessor: func(data []byte) []byte {
|
MsgProcessor: func(data []byte) []byte {
|
||||||
buffer := make([]byte, 0, 2048)
|
buffer := make([]byte, 0, 2048)
|
||||||
buffer = append(buffer, []byte("Processed: ")...)
|
buffer = append(buffer, []byte("Processed: ")...)
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing"
|
testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing"
|
||||||
|
"github.com/v2ray/v2ray-core/common/dice"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
|
||||||
"github.com/v2ray/v2ray-core/proxy"
|
"github.com/v2ray/v2ray-core/proxy"
|
||||||
. "github.com/v2ray/v2ray-core/proxy/http"
|
. "github.com/v2ray/v2ray-core/proxy/http"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
@ -56,7 +56,7 @@ func TestNormalGetRequest(t *testing.T) {
|
|||||||
|
|
||||||
testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)
|
testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)
|
||||||
|
|
||||||
port := v2nettesting.PickPort()
|
port := v2net.Port(dice.Roll(20000) + 10000)
|
||||||
httpProxy := NewServer(
|
httpProxy := NewServer(
|
||||||
&Config{},
|
&Config{},
|
||||||
testPacketDispatcher,
|
testPacketDispatcher,
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
||||||
"github.com/v2ray/v2ray-core/testing/servers/udp"
|
"github.com/v2ray/v2ray-core/testing/servers/udp"
|
||||||
@ -14,9 +13,7 @@ import (
|
|||||||
func TestTCPConnection(t *testing.T) {
|
func TestTCPConnection(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
targetPort := v2nettesting.PickPort()
|
|
||||||
tcpServer := &tcp.Server{
|
tcpServer := &tcp.Server{
|
||||||
Port: targetPort,
|
|
||||||
MsgProcessor: func(data []byte) []byte {
|
MsgProcessor: func(data []byte) []byte {
|
||||||
buffer := make([]byte, 0, 2048)
|
buffer := make([]byte, 0, 2048)
|
||||||
buffer = append(buffer, []byte("Processed: ")...)
|
buffer = append(buffer, []byte("Processed: ")...)
|
||||||
@ -49,7 +46,7 @@ func TestTCPConnection(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
|
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
|
||||||
|
|
||||||
connectRequest := socks5Request(byte(1), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), targetPort))
|
connectRequest := socks5Request(byte(1), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), tcpServer.Port))
|
||||||
nBytes, err = conn.Write(connectRequest)
|
nBytes, err = conn.Write(connectRequest)
|
||||||
assert.Int(nBytes).Equals(len(connectRequest))
|
assert.Int(nBytes).Equals(len(connectRequest))
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
@ -89,9 +86,7 @@ func TestTCPConnection(t *testing.T) {
|
|||||||
func TestTCPBind(t *testing.T) {
|
func TestTCPBind(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
targetPort := v2nettesting.PickPort()
|
|
||||||
tcpServer := &tcp.Server{
|
tcpServer := &tcp.Server{
|
||||||
Port: targetPort,
|
|
||||||
MsgProcessor: func(data []byte) []byte {
|
MsgProcessor: func(data []byte) []byte {
|
||||||
buffer := make([]byte, 0, 2048)
|
buffer := make([]byte, 0, 2048)
|
||||||
buffer = append(buffer, []byte("Processed: ")...)
|
buffer = append(buffer, []byte("Processed: ")...)
|
||||||
@ -122,7 +117,7 @@ func TestTCPBind(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
|
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
|
||||||
|
|
||||||
connectRequest := socks5Request(byte(2), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), targetPort))
|
connectRequest := socks5Request(byte(2), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), tcpServer.Port))
|
||||||
nBytes, err = conn.Write(connectRequest)
|
nBytes, err = conn.Write(connectRequest)
|
||||||
assert.Int(nBytes).Equals(len(connectRequest))
|
assert.Int(nBytes).Equals(len(connectRequest))
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
@ -140,9 +135,7 @@ func TestTCPBind(t *testing.T) {
|
|||||||
func TestUDPAssociate(t *testing.T) {
|
func TestUDPAssociate(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
targetPort := v2nettesting.PickPort()
|
|
||||||
udpServer := &udp.Server{
|
udpServer := &udp.Server{
|
||||||
Port: targetPort,
|
|
||||||
MsgProcessor: func(data []byte) []byte {
|
MsgProcessor: func(data []byte) []byte {
|
||||||
buffer := make([]byte, 0, 2048)
|
buffer := make([]byte, 0, 2048)
|
||||||
buffer = append(buffer, []byte("Processed: ")...)
|
buffer = append(buffer, []byte("Processed: ")...)
|
||||||
@ -173,7 +166,7 @@ func TestUDPAssociate(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
|
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
|
||||||
|
|
||||||
connectRequest := socks5Request(byte(3), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), targetPort))
|
connectRequest := socks5Request(byte(3), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), udpServer.Port))
|
||||||
nBytes, err = conn.Write(connectRequest)
|
nBytes, err = conn.Write(connectRequest)
|
||||||
assert.Int(nBytes).Equals(len(connectRequest))
|
assert.Int(nBytes).Equals(len(connectRequest))
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
@ -191,7 +184,7 @@ func TestUDPAssociate(t *testing.T) {
|
|||||||
|
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
udpPayload := "UDP request to udp server."
|
udpPayload := "UDP request to udp server."
|
||||||
udpRequest := socks5UDPRequest(v2net.UDPDestination(v2net.LocalHostIP, targetPort), []byte(udpPayload))
|
udpRequest := socks5UDPRequest(v2net.UDPDestination(v2net.LocalHostIP, udpServer.Port), []byte(udpPayload))
|
||||||
|
|
||||||
nBytes, err = udpConn.Write(udpRequest)
|
nBytes, err = udpConn.Write(udpRequest)
|
||||||
assert.Int(nBytes).Equals(len(udpRequest))
|
assert.Int(nBytes).Equals(len(udpRequest))
|
||||||
@ -201,7 +194,7 @@ func TestUDPAssociate(t *testing.T) {
|
|||||||
nBytes, err = udpConn.Read(udpResponse)
|
nBytes, err = udpConn.Read(udpResponse)
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
assert.Bytes(udpResponse[:nBytes]).Equals(
|
assert.Bytes(udpResponse[:nBytes]).Equals(
|
||||||
socks5UDPRequest(v2net.UDPDestination(v2net.LocalHostIP, targetPort), []byte("Processed: UDP request to udp server.")))
|
socks5UDPRequest(v2net.UDPDestination(v2net.LocalHostIP, udpServer.Port), []byte("Processed: UDP request to udp server.")))
|
||||||
}
|
}
|
||||||
|
|
||||||
udpConn.Close()
|
udpConn.Close()
|
||||||
|
@ -23,6 +23,7 @@ func (server *Server) Start() (v2net.Destination, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
server.Port = v2net.Port(listener.Addr().(*net.TCPAddr).Port)
|
||||||
server.listener = listener
|
server.listener = listener
|
||||||
go server.acceptConnections(listener)
|
go server.acceptConnections(listener)
|
||||||
localAddr := listener.Addr().(*net.TCPAddr)
|
localAddr := listener.Addr().(*net.TCPAddr)
|
||||||
|
@ -23,6 +23,7 @@ func (server *Server) Start() (v2net.Destination, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
server.Port = v2net.Port(conn.LocalAddr().(*net.UDPAddr).Port)
|
||||||
server.conn = conn
|
server.conn = conn
|
||||||
go server.handleConnection(conn)
|
go server.handleConnection(conn)
|
||||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
||||||
. "github.com/v2ray/v2ray-core/transport/internet"
|
. "github.com/v2ray/v2ray-core/transport/internet"
|
||||||
@ -13,9 +12,7 @@ import (
|
|||||||
func TestDialDomain(t *testing.T) {
|
func TestDialDomain(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
server := &tcp.Server{
|
server := &tcp.Server{}
|
||||||
Port: v2nettesting.PickPort(),
|
|
||||||
}
|
|
||||||
dest, err := server.Start()
|
dest, err := server.Start()
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
@ -29,9 +26,7 @@ func TestDialDomain(t *testing.T) {
|
|||||||
func TestDialWithLocalAddr(t *testing.T) {
|
func TestDialWithLocalAddr(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
server := &tcp.Server{
|
server := &tcp.Server{}
|
||||||
Port: v2nettesting.PickPort(),
|
|
||||||
}
|
|
||||||
dest, err := server.Start()
|
dest, err := server.Start()
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
@ -3,12 +3,12 @@ package kcp_test
|
|||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
. "github.com/v2ray/v2ray-core/transport/internet/kcp"
|
. "github.com/v2ray/v2ray-core/transport/internet/kcp"
|
||||||
)
|
)
|
||||||
@ -16,9 +16,9 @@ import (
|
|||||||
func TestDialAndListen(t *testing.T) {
|
func TestDialAndListen(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
port := v2nettesting.PickPort()
|
listerner, err := NewListener(v2net.LocalHostIP, v2net.Port(0))
|
||||||
listerner, err := NewListener(v2net.LocalHostIP, port)
|
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
port := v2net.Port(listerner.Addr().(*net.UDPAddr).Port)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user