1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/testing/scenarios/vmess_test.go

1524 lines
39 KiB
Go
Raw Normal View History

2017-02-06 09:36:55 -05:00
package scenarios
import (
2018-07-31 07:04:55 -04:00
"os"
2017-02-06 09:36:55 -05:00
"testing"
"time"
2021-10-28 06:34:19 -04:00
"github.com/golang/protobuf/ptypes/any"
2019-01-07 17:27:59 -05:00
"golang.org/x/sync/errgroup"
2021-10-28 06:34:19 -04:00
"google.golang.org/protobuf/types/known/anypb"
2021-02-16 15:31:50 -05:00
core "github.com/v2fly/v2ray-core/v5"
"github.com/v2fly/v2ray-core/v5/app/log"
"github.com/v2fly/v2ray-core/v5/app/proxyman"
"github.com/v2fly/v2ray-core/v5/common"
clog "github.com/v2fly/v2ray-core/v5/common/log"
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/protocol"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/common/uuid"
"github.com/v2fly/v2ray-core/v5/proxy/dokodemo"
"github.com/v2fly/v2ray-core/v5/proxy/freedom"
"github.com/v2fly/v2ray-core/v5/proxy/vmess"
"github.com/v2fly/v2ray-core/v5/proxy/vmess/inbound"
"github.com/v2fly/v2ray-core/v5/proxy/vmess/outbound"
"github.com/v2fly/v2ray-core/v5/testing/servers/tcp"
"github.com/v2fly/v2ray-core/v5/testing/servers/udp"
"github.com/v2fly/v2ray-core/v5/transport/internet"
"github.com/v2fly/v2ray-core/v5/transport/internet/kcp"
2017-02-06 09:36:55 -05:00
)
func TestVMessDynamicPort(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-01-08 17:27:02 -05:00
common.Must(err)
2017-02-06 09:36:55 -05:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
retry := 1
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
for {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-02-06 09:36:55 -05:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
}),
},
2017-02-06 09:36:55 -05:00
},
Detour: &inbound.DetourConfig{
To: "detour",
2017-02-06 09:36:55 -05:00
},
}),
},
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort + 100),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
},
}),
},
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: &net.PortRange{
From: uint32(serverPort + 1),
To: uint32(serverPort + 99),
},
Listen: net.NewIPOrDomain(net.LocalHostIP),
AllocationStrategy: &proxyman.AllocationStrategy{
Type: proxyman.AllocationStrategy_Random,
Concurrency: &proxyman.AllocationStrategy_AllocationStrategyConcurrency{
Value: 2,
},
Refresh: &proxyman.AllocationStrategy_AllocationStrategyRefresh{
Value: 5,
},
},
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{}),
Tag: "detour",
},
2017-02-06 09:36:55 -05:00
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
2017-02-06 09:36:55 -05:00
},
}
server, _ := InitializeServerConfig(serverConfig)
if server != nil && tcpConnAvailableAtPort(t, serverPort+100) {
defer CloseServer(server)
break
}
retry++
if retry > 5 {
t.Fatal("All attempts failed to start server")
}
serverPort = tcp.PickPort()
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2017-02-06 09:36:55 -05:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-02-06 09:36:55 -05:00
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-02-06 09:36:55 -05:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2017-02-06 09:36:55 -05:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
}),
},
},
},
},
}),
},
},
}
server, err := InitializeServerConfig(clientConfig)
2019-01-08 17:27:02 -05:00
common.Must(err)
defer CloseServer(server)
2017-02-06 09:36:55 -05:00
if !tcpConnAvailableAtPort(t, clientPort) {
t.Fail()
}
}
func tcpConnAvailableAtPort(t *testing.T, port net.Port) bool {
for i := 1; ; i++ {
if i > 10 {
t.Log("All attempts failed to test tcp conn")
return false
}
time.Sleep(time.Millisecond * 10)
if err := testTCPConn(port, 1024, time.Second*2)(); err != nil {
t.Log("err ", err)
} else {
t.Log("success with", i, "attempts")
break
2019-01-08 17:27:02 -05:00
}
2017-02-06 09:36:55 -05:00
}
return true
2017-02-06 09:36:55 -05:00
}
func TestVMessGCM(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-01-08 17:27:02 -05:00
common.Must(err)
2017-02-06 09:36:55 -05:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
2017-02-06 09:36:55 -05:00
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-02-06 09:36:55 -05:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2017-02-06 09:36:55 -05:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-02-06 09:36:55 -05:00
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-02-06 09:36:55 -05:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2017-02-06 09:36:55 -05:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-02-06 09:36:55 -05:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2018-07-31 07:04:55 -04:00
if err != nil {
t.Fatal("Failed to initialize all servers: ", err.Error())
}
defer CloseAllServers(servers)
2019-01-08 17:27:02 -05:00
var errg errgroup.Group
2018-07-31 07:04:55 -04:00
for i := 0; i < 10; i++ {
2019-01-08 17:27:02 -05:00
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40))
}
2018-07-31 07:04:55 -04:00
2019-01-08 17:27:02 -05:00
if err := errg.Wait(); err != nil {
t.Error(err)
2018-07-31 07:04:55 -04:00
}
}
func TestVMessGCMReadv(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-01-08 17:27:02 -05:00
common.Must(err)
2018-07-31 07:04:55 -04:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
serverPort := tcp.PickPort()
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2018-07-31 07:04:55 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2018-07-31 07:04:55 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2018-07-31 07:04:55 -04:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2018-07-31 07:04:55 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2018-07-31 07:04:55 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2018-07-31 07:04:55 -04:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
const envName = "V2RAY_BUF_READV"
2018-09-10 14:16:54 -04:00
common.Must(os.Setenv(envName, "enable"))
2018-07-31 07:04:55 -04:00
defer os.Unsetenv(envName)
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
if err != nil {
t.Fatal("Failed to initialize all servers: ", err.Error())
}
2018-07-18 04:40:28 -04:00
defer CloseAllServers(servers)
2017-02-06 09:36:55 -05:00
2019-01-08 17:27:02 -05:00
var errg errgroup.Group
2017-02-06 09:36:55 -05:00
for i := 0; i < 10; i++ {
2019-01-08 17:27:02 -05:00
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40))
}
if err := errg.Wait(); err != nil {
t.Error(err)
2017-02-06 09:36:55 -05:00
}
}
2017-05-01 18:39:10 -04:00
func TestVMessGCMUDP(t *testing.T) {
udpServer := udp.Server{
MsgProcessor: xor,
}
dest, err := udpServer.Start()
2019-02-02 16:19:30 -05:00
common.Must(err)
2017-05-01 18:39:10 -04:00
defer udpServer.Close()
userID := protocol.NewID(uuid.New())
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
2017-05-01 18:39:10 -04:00
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-05-01 18:39:10 -04:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-05-01 18:39:10 -04:00
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-05-01 18:39:10 -04:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-05-01 18:39:10 -04:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
clientPort := udp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2017-05-01 18:39:10 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-05-01 18:39:10 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-05-01 18:39:10 -04:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-05-01 18:39:10 -04:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-05-01 18:39:10 -04:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_UDP},
2017-05-01 18:39:10 -04:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-05-01 18:39:10 -04:00
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-05-01 18:39:10 -04:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-05-01 18:39:10 -04:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2019-02-02 16:19:30 -05:00
common.Must(err)
2019-02-06 05:53:33 -05:00
defer CloseAllServers(servers)
2017-05-01 18:39:10 -04:00
2019-02-03 13:46:53 -05:00
var errg errgroup.Group
2017-05-01 18:39:10 -04:00
for i := 0; i < 10; i++ {
2019-02-06 06:11:09 -05:00
errg.Go(testUDPConn(clientPort, 1024, time.Second*5))
2019-02-03 13:46:53 -05:00
}
if err := errg.Wait(); err != nil {
t.Error(err)
2017-05-01 18:39:10 -04:00
}
}
2017-02-06 09:36:55 -05:00
func TestVMessChacha20(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-01-11 11:17:59 -05:00
common.Must(err)
2017-02-06 09:36:55 -05:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
2017-02-06 09:36:55 -05:00
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-02-06 09:36:55 -05:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2017-02-06 09:36:55 -05:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-02-06 09:36:55 -05:00
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-02-06 09:36:55 -05:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2017-02-06 09:36:55 -05:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-02-06 09:36:55 -05:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_CHACHA20_POLY1305,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2019-01-11 11:17:59 -05:00
common.Must(err)
defer CloseAllServers(servers)
2017-02-06 09:36:55 -05:00
2019-01-11 11:17:59 -05:00
var errg errgroup.Group
2017-02-06 09:36:55 -05:00
for i := 0; i < 10; i++ {
2019-01-11 11:17:59 -05:00
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20))
2017-02-06 09:36:55 -05:00
}
2019-01-11 11:17:59 -05:00
if err := errg.Wait(); err != nil {
t.Error(err)
}
2017-02-06 09:36:55 -05:00
}
func TestVMessNone(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-01-11 11:17:59 -05:00
common.Must(err)
2017-02-06 09:36:55 -05:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
2017-02-06 09:36:55 -05:00
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-02-06 09:36:55 -05:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2017-02-06 09:36:55 -05:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-02-06 09:36:55 -05:00
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-02-06 09:36:55 -05:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2017-02-06 09:36:55 -05:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-02-06 09:36:55 -05:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_NONE,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2019-01-11 11:17:59 -05:00
common.Must(err)
defer CloseAllServers(servers)
2017-02-06 09:36:55 -05:00
2019-01-11 11:17:59 -05:00
var errg errgroup.Group
2017-02-06 09:36:55 -05:00
for i := 0; i < 10; i++ {
2019-01-11 11:17:59 -05:00
errg.Go(testTCPConn(clientPort, 1024*1024, time.Second*30))
}
if err := errg.Wait(); err != nil {
t.Error(err)
2017-02-06 09:36:55 -05:00
}
}
func TestVMessKCP(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-01-11 11:17:59 -05:00
common.Must(err)
2017-02-06 09:36:55 -05:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
2017-11-14 17:45:07 -05:00
serverPort := udp.PickPort()
2017-02-06 09:36:55 -05:00
serverConfig := &core.Config{
App: []*any.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
StreamSettings: &internet.StreamConfig{
Protocol: internet.TransportProtocol_MKCP,
},
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-02-06 09:36:55 -05:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2017-02-06 09:36:55 -05:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-02-06 09:36:55 -05:00
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-02-06 09:36:55 -05:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2017-02-06 09:36:55 -05:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-06 09:36:55 -05:00
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-02-06 09:36:55 -05:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
StreamSettings: &internet.StreamConfig{
Protocol: internet.TransportProtocol_MKCP,
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2019-01-11 11:17:59 -05:00
common.Must(err)
2018-07-28 10:49:03 -04:00
defer CloseAllServers(servers)
2017-02-06 09:36:55 -05:00
2019-01-11 11:17:59 -05:00
var errg errgroup.Group
2017-02-06 09:36:55 -05:00
for i := 0; i < 10; i++ {
2019-01-11 11:17:59 -05:00
errg.Go(testTCPConn(clientPort, 10240*1024, time.Minute*2))
}
if err := errg.Wait(); err != nil {
t.Error(err)
2017-02-06 09:36:55 -05:00
}
}
2017-02-07 18:26:40 -05:00
2018-07-02 17:45:26 -04:00
func TestVMessKCPLarge(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-01-07 17:27:59 -05:00
common.Must(err)
2018-07-02 17:45:26 -04:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
serverPort := udp.PickPort()
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2018-07-02 17:45:26 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2018-07-02 17:45:26 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
StreamSettings: &internet.StreamConfig{
Protocol: internet.TransportProtocol_MKCP,
TransportSettings: []*internet.TransportConfig{
{
Protocol: internet.TransportProtocol_MKCP,
Settings: serial.ToTypedMessage(&kcp.Config{
ReadBuffer: &kcp.ReadBuffer{
2019-11-27 01:40:28 -05:00
Size: 512 * 1024,
2018-07-02 17:45:26 -04:00
},
WriteBuffer: &kcp.WriteBuffer{
2019-11-27 01:40:28 -05:00
Size: 512 * 1024,
2018-07-02 17:45:26 -04:00
},
UplinkCapacity: &kcp.UplinkCapacity{
Value: 20,
},
DownlinkCapacity: &kcp.DownlinkCapacity{
Value: 20,
},
}),
},
},
},
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2018-07-02 17:45:26 -04:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2018-07-02 17:45:26 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2018-07-02 17:45:26 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2018-07-02 17:45:26 -04:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
StreamSettings: &internet.StreamConfig{
Protocol: internet.TransportProtocol_MKCP,
TransportSettings: []*internet.TransportConfig{
{
Protocol: internet.TransportProtocol_MKCP,
Settings: serial.ToTypedMessage(&kcp.Config{
ReadBuffer: &kcp.ReadBuffer{
2019-11-27 01:40:28 -05:00
Size: 512 * 1024,
2018-07-02 17:45:26 -04:00
},
WriteBuffer: &kcp.WriteBuffer{
2019-11-27 01:40:28 -05:00
Size: 512 * 1024,
2018-07-02 17:45:26 -04:00
},
UplinkCapacity: &kcp.UplinkCapacity{
Value: 20,
},
DownlinkCapacity: &kcp.DownlinkCapacity{
Value: 20,
},
}),
},
},
},
}),
},
},
}
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2019-01-07 17:27:59 -05:00
common.Must(err)
2018-07-02 17:45:26 -04:00
2019-01-07 17:27:59 -05:00
var errg errgroup.Group
2018-07-02 17:45:26 -04:00
for i := 0; i < 2; i++ {
2019-01-07 17:27:59 -05:00
errg.Go(testTCPConn(clientPort, 10240*1024, time.Minute*5))
2018-07-02 17:45:26 -04:00
}
2019-01-07 17:27:59 -05:00
if err := errg.Wait(); err != nil {
t.Error(err)
2017-02-07 18:26:40 -05:00
}
2020-08-30 09:17:22 -04:00
defer func() {
<-time.After(5 * time.Second)
CloseAllServers(servers)
}()
2017-02-07 18:26:40 -05:00
}
2017-04-03 09:00:14 -04:00
func TestVMessGCMMux(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-01-07 17:27:59 -05:00
common.Must(err)
2017-04-03 09:00:14 -04:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
2017-04-03 09:00:14 -04:00
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-04-03 09:00:14 -04:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-04-03 09:00:14 -04:00
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-04-03 09:00:14 -04:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-04-03 09:00:14 -04:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2017-04-03 09:00:14 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-04-03 09:00:14 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-04-03 09:00:14 -04:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-04-03 09:00:14 -04:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-04-03 09:00:14 -04:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2017-04-03 09:00:14 -04:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-04-03 09:00:14 -04:00
{
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
MultiplexSettings: &proxyman.MultiplexingConfig{
2017-04-12 06:06:36 -04:00
Enabled: true,
Concurrency: 4,
2017-04-03 09:00:14 -04:00
},
}),
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-04-03 09:00:14 -04:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-04-03 09:00:14 -04:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2019-01-07 17:27:59 -05:00
common.Must(err)
defer CloseAllServers(servers)
2017-04-03 09:00:14 -04:00
2017-04-03 17:43:45 -04:00
for range "abcd" {
2019-01-07 17:27:59 -05:00
var errg errgroup.Group
for i := 0; i < 16; i++ {
errg.Go(testTCPConn(clientPort, 10240, time.Second*20))
}
if err := errg.Wait(); err != nil {
t.Fatal(err)
2017-04-03 17:43:45 -04:00
}
2017-04-04 05:08:06 -04:00
time.Sleep(time.Second)
2017-04-03 09:00:14 -04:00
}
}
2017-05-02 16:56:19 -04:00
func TestVMessGCMMuxUDP(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-02-02 16:19:30 -05:00
common.Must(err)
2017-05-02 16:56:19 -04:00
defer tcpServer.Close()
udpServer := udp.Server{
MsgProcessor: xor,
}
udpDest, err := udpServer.Start()
2019-02-02 16:19:30 -05:00
common.Must(err)
2017-05-02 16:56:19 -04:00
defer udpServer.Close()
userID := protocol.NewID(uuid.New())
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
2017-05-02 16:56:19 -04:00
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-05-02 16:56:19 -04:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-05-02 16:56:19 -04:00
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-05-02 16:56:19 -04:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-05-02 16:56:19 -04:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
2017-11-14 17:45:07 -05:00
clientUDPPort := udp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
2017-05-02 16:56:19 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2017-05-02 16:56:19 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-05-02 16:56:19 -04:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-05-02 16:56:19 -04:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-05-02 16:56:19 -04:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2017-05-02 16:56:19 -04:00
},
}),
},
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientUDPPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-05-02 16:56:19 -04:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(udpDest.Address),
2017-05-02 16:56:19 -04:00
Port: uint32(udpDest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_UDP},
2017-05-02 16:56:19 -04:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-05-02 16:56:19 -04:00
{
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
MultiplexSettings: &proxyman.MultiplexingConfig{
Enabled: true,
Concurrency: 4,
},
}),
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-05-02 16:56:19 -04:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2017-05-02 16:56:19 -04:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2019-02-02 16:19:30 -05:00
common.Must(err)
2017-05-02 16:56:19 -04:00
for range "abcd" {
2019-02-03 13:46:53 -05:00
var errg errgroup.Group
for i := 0; i < 16; i++ {
errg.Go(testTCPConn(clientPort, 10240, time.Second*20))
errg.Go(testUDPConn(clientUDPPort, 1024, time.Second*10))
2017-05-02 16:56:19 -04:00
}
2019-02-03 13:46:53 -05:00
if err := errg.Wait(); err != nil {
t.Error(err)
2017-05-02 16:56:19 -04:00
}
time.Sleep(time.Second)
}
2020-08-30 09:17:22 -04:00
defer func() {
<-time.After(5 * time.Second)
CloseAllServers(servers)
}()
2017-05-02 16:56:19 -04:00
}
func TestVMessZero(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
common.Must(err)
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
serverPort := tcp.PickPort()
serverConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-19 09:36:54 -04:00
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_ZERO,
},
}),
},
},
},
},
}),
},
},
}
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
common.Must(err)
defer CloseAllServers(servers)
var errg errgroup.Group
for i := 0; i < 10; i++ {
errg.Go(testTCPConn(clientPort, 1024*1024, time.Second*30))
}
if err := errg.Wait(); err != nil {
t.Error(err)
}
}
2021-04-28 18:29:42 -04:00
func TestVMessGCMLengthAuth(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
common.Must(err)
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
serverPort := tcp.PickPort()
serverConfig := &core.Config{
2021-06-23 05:27:32 -04:00
App: []*anypb.Any{
2021-04-28 18:29:42 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2021-04-28 18:29:42 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2021-04-28 18:29:42 -04:00
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-23 05:27:32 -04:00
App: []*anypb.Any{
2021-04-28 18:29:42 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2021-04-28 18:29:42 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2021-04-28 18:29:42 -04:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
TestsEnabled: "AuthenticatedLength",
}),
},
},
},
},
}),
},
},
}
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
if err != nil {
t.Fatal("Failed to initialize all servers: ", err.Error())
}
defer CloseAllServers(servers)
var errg errgroup.Group
for i := 0; i < 10; i++ {
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40))
}
if err := errg.Wait(); err != nil {
t.Error(err)
}
}
2021-04-29 09:41:50 -04:00
func TestVMessGCMLengthAuthPlusNoTerminationSignal(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
common.Must(err)
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
serverPort := tcp.PickPort()
serverConfig := &core.Config{
2021-06-23 05:27:32 -04:00
App: []*anypb.Any{
2021-04-29 09:41:50 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2021-04-29 09:41:50 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2021-04-29 09:41:50 -04:00
TestsEnabled: "AuthenticatedLength|NoTerminationSignal",
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2021-06-23 05:27:32 -04:00
App: []*anypb.Any{
2021-04-29 09:41:50 -04:00
serial.ToTypedMessage(&log.Config{
2021-10-02 17:29:37 -04:00
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
2021-04-29 09:41:50 -04:00
}),
},
Inbound: []*core.InboundHandlerConfig{
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIP),
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 0,
2021-04-29 09:41:50 -04:00
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
TestsEnabled: "AuthenticatedLength|NoTerminationSignal",
}),
},
},
},
},
}),
},
},
}
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
if err != nil {
t.Fatal("Failed to initialize all servers: ", err.Error())
}
defer CloseAllServers(servers)
var errg errgroup.Group
for i := 0; i < 10; i++ {
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*40))
}
if err := errg.Wait(); err != nil {
t.Error(err)
}
}