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