1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/testing/scenarios/vmess_test.go

1557 lines
38 KiB
Go
Raw Normal View History

2017-02-06 09:36:55 -05:00
package scenarios
import (
"crypto/rand"
2018-07-31 07:04:55 -04:00
"os"
2017-02-07 17:33:21 -05:00
"sync"
2017-02-06 09:36:55 -05:00
"testing"
"time"
"v2ray.com/core"
"v2ray.com/core/app/log"
"v2ray.com/core/app/proxyman"
2018-07-31 07:04:55 -04:00
"v2ray.com/core/common"
2018-07-24 15:48:28 -04:00
"v2ray.com/core/common/compare"
2017-12-19 16:29:56 -05:00
clog "v2ray.com/core/common/log"
"v2ray.com/core/common/net"
2017-02-06 09:36:55 -05:00
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/uuid"
"v2ray.com/core/proxy/dokodemo"
"v2ray.com/core/proxy/freedom"
"v2ray.com/core/proxy/vmess"
"v2ray.com/core/proxy/vmess/inbound"
"v2ray.com/core/proxy/vmess/outbound"
"v2ray.com/core/testing/servers/tcp"
2017-05-01 18:39:10 -04:00
"v2ray.com/core/testing/servers/udp"
2017-02-06 09:36:55 -05:00
"v2ray.com/core/transport/internet"
2018-07-02 17:45:26 -04:00
"v2ray.com/core/transport/internet/kcp"
2017-10-26 15:44:22 -04:00
. "v2ray.com/ext/assert"
2017-02-06 09:36:55 -05:00
)
func TestVMessDynamicPort(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-02-06 09:36:55 -05:00
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
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{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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(),
}),
},
},
Detour: &inbound.DetourConfig{
To: "detour",
},
}),
},
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: &net.PortRange{
2017-02-06 09:36:55 -05:00
From: uint32(serverPort + 1),
To: uint32(serverPort + 100),
},
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-02-06 09:36:55 -05:00
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",
},
},
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{
2017-02-06 09:36:55 -05:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-02-06 09:36:55 -05:00
ErrorLogType: log.LogType_Console,
}),
},
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(),
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-06 09:36:55 -05:00
for i := 0; i < 10; i++ {
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-06 09:36:55 -05:00
payload := "dokodemo request."
nBytes, err := conn.Write([]byte(payload))
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-02-06 09:36:55 -05:00
response := make([]byte, 1024)
nBytes, err = conn.Read(response)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(response[:nBytes], Equals, xor([]byte(payload)))
assert(conn.Close(), IsNil)
2017-02-06 09:36:55 -05:00
}
2017-05-17 18:39:30 -04:00
CloseAllServers(servers)
2017-02-06 09:36:55 -05:00
}
func TestVMessGCM(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-02-06 09:36:55 -05:00
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
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{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
}),
},
},
}),
},
},
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{
2017-02-06 09:36:55 -05:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-02-06 09:36:55 -05:00
ErrorLogType: log.LogType_Console,
}),
},
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: 64,
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2018-07-18 04:40:28 -04:00
/*
const envName = "V2RAY_VMESS_PADDING"
common.Must(os.Setenv(envName, "1"))
defer os.Unsetenv(envName)
*/
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)
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
2018-07-31 10:16:52 -04:00
wg.Add(1)
2018-07-31 07:04:55 -04:00
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 := compare.BytesEqualWithDetail(response, xor([]byte(payload))); err != nil {
t.Error(err)
}
}()
}
wg.Wait()
}
func TestVMessGCMReadv(t *testing.T) {
assert := With(t)
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2018-07-31 07:04:55 -04:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
serverPort := tcp.PickPort()
serverConfig := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
clientPort := tcp.PickPort()
clientConfig := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
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
var wg sync.WaitGroup
wg.Add(10)
for i := 0; i < 10; i++ {
go func() {
2018-07-31 07:04:55 -04:00
defer wg.Done()
2017-02-06 09:36:55 -05:00
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2018-07-24 15:48:28 -04:00
defer conn.Close() // nolint: errcheck
2017-02-06 09:36:55 -05:00
payload := make([]byte, 10240*1024)
rand.Read(payload)
nBytes, err := conn.Write([]byte(payload))
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-02-06 09:36:55 -05:00
2018-07-24 15:48:28 -04:00
response := readFrom(conn, time.Second*40, 10240*1024)
if err := compare.BytesEqualWithDetail(response, xor([]byte(payload))); err != nil {
t.Error(err)
}
2017-02-06 09:36:55 -05:00
}()
}
wg.Wait()
}
2017-05-01 18:39:10 -04:00
func TestVMessGCMUDP(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-05-01 18:39:10 -04:00
udpServer := udp.Server{
MsgProcessor: xor,
}
dest, err := udpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
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{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-05-01 18:39:10 -04:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2017-05-01 18:39:10 -04:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-05-01 18:39:10 -04:00
ErrorLogType: log.LogType_Console,
}),
},
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: 64,
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-05-01 18:39:10 -04:00
var wg sync.WaitGroup
wg.Add(10)
for i := 0; i < 10; i++ {
go func() {
conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-05-01 18:39:10 -04:00
payload := make([]byte, 1024)
rand.Read(payload)
nBytes, err := conn.Write([]byte(payload))
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-05-01 18:39:10 -04:00
payload1 := make([]byte, 1024)
rand.Read(payload1)
nBytes, err = conn.Write([]byte(payload1))
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload1))
2017-05-01 18:39:10 -04:00
response := readFrom(conn, time.Second*5, 1024)
2017-10-24 10:15:35 -04:00
assert(response, Equals, xor([]byte(payload)))
2017-05-01 18:39:10 -04:00
response = readFrom(conn, time.Second*5, 1024)
2017-10-24 10:15:35 -04:00
assert(response, Equals, xor([]byte(payload1)))
2017-05-01 18:39:10 -04:00
2017-10-24 10:15:35 -04:00
assert(conn.Close(), IsNil)
2017-05-01 18:39:10 -04:00
wg.Done()
}()
}
wg.Wait()
2017-05-17 18:39:30 -04:00
CloseAllServers(servers)
2017-05-01 18:39:10 -04:00
}
2017-02-06 09:36:55 -05:00
func TestVMessChacha20(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-02-06 09:36:55 -05:00
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
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{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
}),
},
},
}),
},
},
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{
2017-02-06 09:36:55 -05:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-02-06 09:36:55 -05:00
ErrorLogType: log.LogType_Console,
}),
},
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: 64,
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_CHACHA20_POLY1305,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-06 09:36:55 -05:00
var wg sync.WaitGroup
wg.Add(10)
for i := 0; i < 10; i++ {
go func() {
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-06 09:36:55 -05:00
payload := make([]byte, 10240*1024)
rand.Read(payload)
nBytes, err := conn.Write([]byte(payload))
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-02-06 09:36:55 -05:00
2017-04-16 15:31:33 -04:00
response := readFrom(conn, time.Second*20, 10240*1024)
2017-10-24 10:15:35 -04:00
assert(response, Equals, xor([]byte(payload)))
assert(conn.Close(), IsNil)
2017-02-06 09:36:55 -05:00
wg.Done()
}()
}
wg.Wait()
2017-05-17 18:39:30 -04:00
CloseAllServers(servers)
2017-02-06 09:36:55 -05:00
}
func TestVMessNone(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-02-06 09:36:55 -05:00
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
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{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
}),
},
},
}),
},
},
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{
2017-02-06 09:36:55 -05:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-02-06 09:36:55 -05:00
ErrorLogType: log.LogType_Console,
}),
},
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: 64,
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_NONE,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-06 09:36:55 -05:00
var wg sync.WaitGroup
wg.Add(10)
for i := 0; i < 10; i++ {
go func() {
2017-11-07 08:40:51 -05:00
defer wg.Done()
2017-02-06 09:36:55 -05:00
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-06 09:36:55 -05:00
2017-05-04 07:17:07 -04:00
payload := make([]byte, 1024*1024)
2017-02-06 09:36:55 -05:00
rand.Read(payload)
2017-05-02 16:50:27 -04:00
nBytes, err := conn.Write(payload)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-02-06 09:36:55 -05:00
2017-11-26 08:18:48 -05:00
response := readFrom(conn, time.Second*30, 1024*1024)
2017-11-07 08:40:51 -05:00
2017-10-24 10:15:35 -04:00
assert(response, Equals, xor(payload))
assert(conn.Close(), IsNil)
2017-02-06 09:36:55 -05:00
}()
}
wg.Wait()
2017-05-17 18:39:30 -04:00
CloseAllServers(servers)
2017-02-06 09:36:55 -05:00
}
func TestVMessKCP(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-02-06 09:36:55 -05:00
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
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: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
}),
},
},
}),
},
},
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{
2017-02-06 09:36:55 -05:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-02-06 09:36:55 -05:00
ErrorLogType: log.LogType_Console,
}),
},
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: 64,
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)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2018-07-28 10:49:03 -04:00
defer CloseAllServers(servers)
2017-02-06 09:36:55 -05:00
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
2017-02-07 17:33:21 -05:00
wg.Add(1)
2017-02-06 09:36:55 -05:00
go func() {
2018-07-28 10:49:03 -04:00
defer wg.Done()
2017-02-06 09:36:55 -05:00
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2018-07-28 10:49:03 -04:00
defer conn.Close()
2017-02-06 09:36:55 -05:00
payload := make([]byte, 10240*1024)
rand.Read(payload)
2017-05-03 05:14:05 -04:00
nBytes, err := conn.Write(payload)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-02-06 09:36:55 -05:00
2018-05-27 09:19:09 -04:00
response := readFrom(conn, time.Minute*2, 10240*1024)
2018-07-28 10:49:03 -04:00
if err := compare.BytesEqualWithDetail(response, xor(payload)); err != nil {
t.Error(err)
}
2017-02-06 09:36:55 -05:00
}()
}
wg.Wait()
}
2017-02-07 18:26:40 -05:00
2018-07-02 17:45:26 -04:00
func TestVMessKCPLarge(t *testing.T) {
assert := With(t)
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
assert(err, IsNil)
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
serverPort := udp.PickPort()
serverConfig := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
}),
},
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{
Size: 4096,
},
WriteBuffer: &kcp.WriteBuffer{
Size: 4096,
},
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: 64,
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
clientPort := tcp.PickPort()
clientConfig := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
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{
Size: 4096,
},
WriteBuffer: &kcp.WriteBuffer{
Size: 4096,
},
UplinkCapacity: &kcp.UplinkCapacity{
Value: 20,
},
DownlinkCapacity: &kcp.DownlinkCapacity{
Value: 20,
},
}),
},
},
},
}),
},
},
}
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
assert(err, IsNil)
2018-07-28 10:57:42 -04:00
defer CloseAllServers(servers)
2018-07-02 17:45:26 -04:00
var wg sync.WaitGroup
for i := 0; i < 2; i++ {
wg.Add(1)
go func() {
2018-07-28 10:57:42 -04:00
defer wg.Done()
2018-07-02 17:45:26 -04:00
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
assert(err, IsNil)
2018-07-28 10:57:42 -04:00
defer conn.Close()
2018-07-02 17:45:26 -04:00
payload := make([]byte, 10240*1024)
rand.Read(payload)
nBytes, err := conn.Write(payload)
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
response := readFrom(conn, time.Minute*10, 10240*1024)
2018-07-28 10:57:42 -04:00
if err := compare.BytesEqualWithDetail(response, xor(payload)); err != nil {
t.Error(err)
}
2018-07-02 17:45:26 -04:00
}()
}
wg.Wait()
}
2017-02-07 18:26:40 -05:00
func TestVMessIPv6(t *testing.T) {
2017-02-07 18:45:29 -05:00
t.SkipNow() // No IPv6 on travis-ci.
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-02-07 18:26:40 -05:00
tcpServer := tcp.Server{
MsgProcessor: xor,
Listen: net.LocalHostIPv6,
2017-02-07 18:26:40 -05:00
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-07 18:26:40 -05:00
defer tcpServer.Close()
userID := protocol.NewID(uuid.New())
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
2017-02-07 18:26:40 -05:00
serverConfig := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-07 18:26:40 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIPv6),
2017-02-07 18:26:40 -05:00
}),
ProxySettings: serial.ToTypedMessage(&inbound.Config{
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 64,
}),
},
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-07 18:26:40 -05:00
{
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
},
},
}
2018-03-01 05:53:39 -05:00
clientPort := tcp.PickPort()
clientConfig := &core.Config{
2017-02-07 18:26:40 -05:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-02-07 18:26:40 -05:00
ErrorLogType: log.LogType_Console,
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-02-07 18:26:40 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(clientPort),
Listen: net.NewIPOrDomain(net.LocalHostIPv6),
2017-02-07 18:26:40 -05:00
}),
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
Address: net.NewIPOrDomain(dest.Address),
2017-02-07 18:26:40 -05:00
Port: uint32(dest.Port),
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2017-02-07 18:26:40 -05:00
},
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-02-07 18:26:40 -05:00
{
ProxySettings: serial.ToTypedMessage(&outbound.Config{
Receiver: []*protocol.ServerEndpoint{
{
Address: net.NewIPOrDomain(net.LocalHostIPv6),
2017-02-07 18:26:40 -05:00
Port: uint32(serverPort),
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vmess.Account{
Id: userID.String(),
AlterId: 64,
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-07 18:26:40 -05:00
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: net.LocalHostIPv6.IP(),
2017-02-07 18:26:40 -05:00
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-02-07 18:26:40 -05:00
payload := make([]byte, 1024)
rand.Read(payload)
2017-05-03 05:14:05 -04:00
nBytes, err := conn.Write(payload)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-02-07 18:26:40 -05:00
2017-04-16 15:31:33 -04:00
response := readFrom(conn, time.Second*20, 1024)
2017-10-24 10:15:35 -04:00
assert(response, Equals, xor(payload))
assert(conn.Close(), IsNil)
2017-02-07 18:26:40 -05:00
2017-05-17 18:39:30 -04:00
CloseAllServers(servers)
2017-02-07 18:26:40 -05:00
}
2017-04-03 09:00:14 -04:00
func TestVMessGCMMux(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-04-03 09:00:14 -04:00
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
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{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
}),
},
},
}),
},
},
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{
2017-04-03 09:00:14 -04:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-04-03 09:00:14 -04:00
ErrorLogType: log.LogType_Console,
}),
},
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: 64,
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-04-03 09:00:14 -04:00
2017-04-03 17:43:45 -04:00
for range "abcd" {
var wg sync.WaitGroup
2017-04-04 05:08:06 -04:00
const nConnection = 16
2017-04-03 17:43:45 -04:00
wg.Add(nConnection)
for i := 0; i < nConnection; i++ {
go func() {
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-04-03 17:43:45 -04:00
payload := make([]byte, 10240)
rand.Read(payload)
2017-05-03 05:14:05 -04:00
xorpayload := xor(payload)
nBytes, err := conn.Write(payload)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-04-03 17:43:45 -04:00
2017-04-16 15:31:33 -04:00
response := readFrom(conn, time.Second*20, 10240)
2017-10-24 10:15:35 -04:00
assert(response, Equals, xorpayload)
assert(conn.Close(), IsNil)
2017-04-03 17:43:45 -04:00
wg.Done()
}()
}
wg.Wait()
2017-04-04 05:08:06 -04:00
time.Sleep(time.Second)
2017-04-03 09:00:14 -04:00
}
2017-05-17 18:39:30 -04:00
CloseAllServers(servers)
2017-04-03 09:00:14 -04:00
}
2017-05-02 16:56:19 -04:00
func TestVMessGCMMuxUDP(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-05-02 16:56:19 -04:00
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-05-02 16:56:19 -04:00
defer tcpServer.Close()
udpServer := udp.Server{
MsgProcessor: xor,
}
udpDest, err := udpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
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{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: 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: 64,
}),
},
},
}),
},
},
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{
2017-05-02 16:56:19 -04:00
App: []*serial.TypedMessage{
serial.ToTypedMessage(&log.Config{
2017-12-19 16:29:56 -05:00
ErrorLogLevel: clog.Severity_Debug,
2017-05-02 16:56:19 -04:00
ErrorLogType: log.LogType_Console,
}),
},
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: 64,
SecuritySettings: &protocol.SecurityConfig{
Type: protocol.SecurityType_AES128_GCM,
},
}),
},
},
},
},
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-05-02 16:56:19 -04:00
for range "abcd" {
var wg sync.WaitGroup
const nConnection = 16
wg.Add(nConnection * 2)
for i := 0; i < nConnection; i++ {
go func() {
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-05-02 16:56:19 -04:00
payload := make([]byte, 10240)
rand.Read(payload)
2017-05-03 05:12:26 -04:00
xorpayload := xor(payload)
nBytes, err := conn.Write(payload)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-05-02 16:56:19 -04:00
response := readFrom(conn, time.Second*20, 10240)
2017-10-24 10:15:35 -04:00
assert(response, Equals, xorpayload)
assert(conn.Close(), IsNil)
2017-05-02 16:56:19 -04:00
wg.Done()
}()
}
for i := 0; i < nConnection; i++ {
go func() {
conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(clientUDPPort),
})
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-05-02 16:56:19 -04:00
2017-05-02 17:36:37 -04:00
conn.SetDeadline(time.Now().Add(time.Second * 10))
2017-05-02 16:56:19 -04:00
payload := make([]byte, 1024)
rand.Read(payload)
2017-05-03 05:12:26 -04:00
xorpayload := xor(payload)
2017-05-03 05:33:42 -04:00
for j := 0; j < 2; j++ {
2017-05-02 17:36:37 -04:00
nBytes, _, err := conn.WriteMsgUDP(payload, nil, nil)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, len(payload))
2017-05-02 17:36:37 -04:00
}
response := make([]byte, 1024)
oob := make([]byte, 16)
2017-05-03 05:33:42 -04:00
for j := 0; j < 2; j++ {
2017-05-02 17:36:37 -04:00
nBytes, _, _, _, err := conn.ReadMsgUDP(response, oob)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(nBytes, Equals, 1024)
assert(response, Equals, xorpayload)
2017-05-02 17:36:37 -04:00
}
2017-05-02 16:56:19 -04:00
2017-10-24 10:15:35 -04:00
assert(conn.Close(), IsNil)
2017-05-02 16:56:19 -04:00
wg.Done()
}()
}
wg.Wait()
time.Sleep(time.Second)
}
2017-05-17 18:39:30 -04:00
CloseAllServers(servers)
2017-05-02 16:56:19 -04:00
}