|
|
|
@ -1,19 +1,17 @@
|
|
|
|
|
package scenarios |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"crypto/rand" |
|
|
|
|
"os" |
|
|
|
|
"runtime" |
|
|
|
|
"sync" |
|
|
|
|
"testing" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp" |
|
|
|
|
"v2ray.com/core/transport/internet/headers/wechat" |
|
|
|
|
"golang.org/x/sync/errgroup" |
|
|
|
|
|
|
|
|
|
"v2ray.com/core" |
|
|
|
|
"v2ray.com/core/app/log" |
|
|
|
|
"v2ray.com/core/app/proxyman" |
|
|
|
|
"v2ray.com/core/common" |
|
|
|
|
clog "v2ray.com/core/common/log" |
|
|
|
|
"v2ray.com/core/common/net" |
|
|
|
|
"v2ray.com/core/common/protocol" |
|
|
|
@ -28,19 +26,17 @@ import (
|
|
|
|
|
"v2ray.com/core/transport/internet" |
|
|
|
|
"v2ray.com/core/transport/internet/domainsocket" |
|
|
|
|
"v2ray.com/core/transport/internet/headers/http" |
|
|
|
|
"v2ray.com/core/transport/internet/headers/wechat" |
|
|
|
|
"v2ray.com/core/transport/internet/quic" |
|
|
|
|
tcptransport "v2ray.com/core/transport/internet/tcp" |
|
|
|
|
. "v2ray.com/ext/assert" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func TestHttpConnectionHeader(t *testing.T) { |
|
|
|
|
assert := With(t) |
|
|
|
|
|
|
|
|
|
tcpServer := tcp.Server{ |
|
|
|
|
MsgProcessor: xor, |
|
|
|
|
} |
|
|
|
|
dest, err := tcpServer.Start() |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
common.Must(err) |
|
|
|
|
defer tcpServer.Close() |
|
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New()) |
|
|
|
@ -131,24 +127,12 @@ func TestHttpConnectionHeader(t *testing.T) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig) |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
|
|
|
|
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{ |
|
|
|
|
IP: []byte{127, 0, 0, 1}, |
|
|
|
|
Port: int(clientPort), |
|
|
|
|
}) |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
|
|
|
|
|
payload := "dokodemo request." |
|
|
|
|
nBytes, err := conn.Write([]byte(payload)) |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
assert(nBytes, Equals, len(payload)) |
|
|
|
|
|
|
|
|
|
response := readFrom(conn, time.Second*2, len(payload)) |
|
|
|
|
assert(response, Equals, xor([]byte(payload))) |
|
|
|
|
assert(conn.Close(), IsNil) |
|
|
|
|
common.Must(err) |
|
|
|
|
defer CloseAllServers(servers) |
|
|
|
|
|
|
|
|
|
CloseAllServers(servers) |
|
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil { |
|
|
|
|
t.Error(err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDomainSocket(t *testing.T) { |
|
|
|
@ -156,13 +140,11 @@ func TestDomainSocket(t *testing.T) {
|
|
|
|
|
t.Skip("Not supported on windows") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
assert := With(t) |
|
|
|
|
|
|
|
|
|
tcpServer := tcp.Server{ |
|
|
|
|
MsgProcessor: xor, |
|
|
|
|
} |
|
|
|
|
dest, err := tcpServer.Start() |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
common.Must(err) |
|
|
|
|
defer tcpServer.Close() |
|
|
|
|
|
|
|
|
|
const dsPath = "/tmp/ds_scenario" |
|
|
|
@ -258,34 +240,20 @@ func TestDomainSocket(t *testing.T) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig) |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
|
|
|
|
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{ |
|
|
|
|
IP: []byte{127, 0, 0, 1}, |
|
|
|
|
Port: int(clientPort), |
|
|
|
|
}) |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
|
|
|
|
|
payload := "dokodemo request." |
|
|
|
|
nBytes, err := conn.Write([]byte(payload)) |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
assert(nBytes, Equals, len(payload)) |
|
|
|
|
|
|
|
|
|
response := readFrom(conn, time.Second*2, len(payload)) |
|
|
|
|
assert(response, Equals, xor([]byte(payload))) |
|
|
|
|
assert(conn.Close(), IsNil) |
|
|
|
|
common.Must(err) |
|
|
|
|
defer CloseAllServers(servers) |
|
|
|
|
|
|
|
|
|
CloseAllServers(servers) |
|
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil { |
|
|
|
|
t.Error(err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestVMessQuic(t *testing.T) { |
|
|
|
|
assert := With(t) |
|
|
|
|
|
|
|
|
|
tcpServer := tcp.Server{ |
|
|
|
|
MsgProcessor: xor, |
|
|
|
|
} |
|
|
|
|
dest, err := tcpServer.Start() |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
common.Must(err) |
|
|
|
|
defer tcpServer.Close() |
|
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New()) |
|
|
|
@ -406,31 +374,12 @@ func TestVMessQuic(t *testing.T) {
|
|
|
|
|
} |
|
|
|
|
defer CloseAllServers(servers) |
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup |
|
|
|
|
var errg errgroup.Group |
|
|
|
|
for i := 0; i < 10; i++ { |
|
|
|
|
wg.Add(1) |
|
|
|
|
go func() { |
|
|
|
|
defer wg.Done() |
|
|
|
|
|
|
|
|
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{ |
|
|
|
|
IP: []byte{127, 0, 0, 1}, |
|
|
|
|
Port: int(clientPort), |
|
|
|
|
}) |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
defer conn.Close() // nolint: errcheck
|
|
|
|
|
|
|
|
|
|
payload := make([]byte, 10240*1024) |
|
|
|
|
rand.Read(payload) |
|
|
|
|
|
|
|
|
|
nBytes, err := conn.Write([]byte(payload)) |
|
|
|
|
assert(err, IsNil) |
|
|
|
|
assert(nBytes, Equals, len(payload)) |
|
|
|
|
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
response := readFrom(conn, time.Second*40, 10240*1024) |
|
|
|
|
if r := cmp.Diff(response, xor([]byte(payload))); r != "" { |
|
|
|
|
t.Error(r) |
|
|
|
|
} |
|
|
|
|
}() |
|
|
|
|
if err := errg.Wait(); err != nil { |
|
|
|
|
t.Error(err) |
|
|
|
|
} |
|
|
|
|
wg.Wait() |
|
|
|
|
} |
|
|
|
|