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