mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 14:57:44 -05:00
remove dependency on assert lib
This commit is contained in:
parent
5f53530cc1
commit
edd71de1c3
@ -5,12 +5,9 @@ import (
|
|||||||
|
|
||||||
. "v2ray.com/core/app/proxyman/outbound"
|
. "v2ray.com/core/app/proxyman/outbound"
|
||||||
"v2ray.com/core/features/outbound"
|
"v2ray.com/core/features/outbound"
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInterfaces(t *testing.T) {
|
func TestInterfaces(t *testing.T) {
|
||||||
assert := With(t)
|
_ = (outbound.Handler)(new(Handler))
|
||||||
|
_ = (outbound.Manager)(new(Manager))
|
||||||
assert((*Handler)(nil), Implements, (*outbound.Handler)(nil))
|
|
||||||
assert((*Manager)(nil), Implements, (*outbound.Manager)(nil))
|
|
||||||
}
|
}
|
||||||
|
@ -4,102 +4,158 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
. "v2ray.com/core/common/net"
|
. "v2ray.com/core/common/net"
|
||||||
. "v2ray.com/core/common/net/testing"
|
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIPv4Address(t *testing.T) {
|
func TestAddressProperty(t *testing.T) {
|
||||||
assert := With(t)
|
type addrProprty struct {
|
||||||
|
IP []byte
|
||||||
ip := []byte{byte(1), byte(2), byte(3), byte(4)}
|
Domain string
|
||||||
addr := IPAddress(ip)
|
Family AddressFamily
|
||||||
|
String string
|
||||||
assert(addr, IsIPv4)
|
|
||||||
assert(addr, Not(IsIPv6))
|
|
||||||
assert(addr, Not(IsDomain))
|
|
||||||
assert([]byte(addr.IP()), Equals, ip)
|
|
||||||
assert(addr.String(), Equals, "1.2.3.4")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIPv6Address(t *testing.T) {
|
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
ip := []byte{
|
|
||||||
byte(1), byte(2), byte(3), byte(4),
|
|
||||||
byte(1), byte(2), byte(3), byte(4),
|
|
||||||
byte(1), byte(2), byte(3), byte(4),
|
|
||||||
byte(1), byte(2), byte(3), byte(4),
|
|
||||||
}
|
}
|
||||||
addr := IPAddress(ip)
|
|
||||||
|
|
||||||
assert(addr, IsIPv6)
|
testCases := []struct {
|
||||||
assert(addr, Not(IsIPv4))
|
Input Address
|
||||||
assert(addr, Not(IsDomain))
|
Output addrProprty
|
||||||
assert(addr.IP(), Equals, net.IP(ip))
|
}{
|
||||||
assert(addr.String(), Equals, "[102:304:102:304:102:304:102:304]")
|
{
|
||||||
}
|
Input: IPAddress([]byte{byte(1), byte(2), byte(3), byte(4)}),
|
||||||
|
Output: addrProprty{
|
||||||
func TestIPv4Asv6(t *testing.T) {
|
IP: []byte{byte(1), byte(2), byte(3), byte(4)},
|
||||||
assert := With(t)
|
Family: AddressFamilyIPv4,
|
||||||
ip := []byte{
|
String: "1.2.3.4",
|
||||||
byte(0), byte(0), byte(0), byte(0),
|
},
|
||||||
byte(0), byte(0), byte(0), byte(0),
|
},
|
||||||
byte(0), byte(0), byte(255), byte(255),
|
{
|
||||||
byte(1), byte(2), byte(3), byte(4),
|
Input: IPAddress([]byte{
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
}),
|
||||||
|
Output: addrProprty{
|
||||||
|
IP: []byte{
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
},
|
||||||
|
Family: AddressFamilyIPv6,
|
||||||
|
String: "[102:304:102:304:102:304:102:304]",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: IPAddress([]byte{
|
||||||
|
byte(0), byte(0), byte(0), byte(0),
|
||||||
|
byte(0), byte(0), byte(0), byte(0),
|
||||||
|
byte(0), byte(0), byte(255), byte(255),
|
||||||
|
byte(1), byte(2), byte(3), byte(4),
|
||||||
|
}),
|
||||||
|
Output: addrProprty{
|
||||||
|
IP: []byte{byte(1), byte(2), byte(3), byte(4)},
|
||||||
|
Family: AddressFamilyIPv4,
|
||||||
|
String: "1.2.3.4",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: DomainAddress("v2ray.com"),
|
||||||
|
Output: addrProprty{
|
||||||
|
Domain: "v2ray.com",
|
||||||
|
Family: AddressFamilyDomain,
|
||||||
|
String: "v2ray.com",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: IPAddress(net.IPv4(1, 2, 3, 4)),
|
||||||
|
Output: addrProprty{
|
||||||
|
IP: []byte{byte(1), byte(2), byte(3), byte(4)},
|
||||||
|
Family: AddressFamilyIPv4,
|
||||||
|
String: "1.2.3.4",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: ParseAddress("[2001:4860:0:2001::68]"),
|
||||||
|
Output: addrProprty{
|
||||||
|
IP: []byte{0x20, 0x01, 0x48, 0x60, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68},
|
||||||
|
Family: AddressFamilyIPv6,
|
||||||
|
String: "[2001:4860:0:2001::68]",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: ParseAddress("[::ffff:123.151.71.143]"),
|
||||||
|
Output: addrProprty{
|
||||||
|
IP: []byte{123, 151, 71, 143},
|
||||||
|
Family: AddressFamilyIPv4,
|
||||||
|
String: "123.151.71.143",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: NewIPOrDomain(ParseAddress("v2ray.com")).AsAddress(),
|
||||||
|
Output: addrProprty{
|
||||||
|
Domain: "v2ray.com",
|
||||||
|
Family: AddressFamilyDomain,
|
||||||
|
String: "v2ray.com",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: NewIPOrDomain(ParseAddress("8.8.8.8")).AsAddress(),
|
||||||
|
Output: addrProprty{
|
||||||
|
IP: []byte{8, 8, 8, 8},
|
||||||
|
Family: AddressFamilyIPv4,
|
||||||
|
String: "8.8.8.8",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: NewIPOrDomain(ParseAddress("[2001:4860:0:2001::68]")).AsAddress(),
|
||||||
|
Output: addrProprty{
|
||||||
|
IP: []byte{0x20, 0x01, 0x48, 0x60, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68},
|
||||||
|
Family: AddressFamilyIPv6,
|
||||||
|
String: "[2001:4860:0:2001::68]",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
addr := IPAddress(ip)
|
|
||||||
assert(addr.String(), Equals, "1.2.3.4")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDomainAddress(t *testing.T) {
|
for _, testCase := range testCases {
|
||||||
assert := With(t)
|
actual := addrProprty{
|
||||||
|
Family: testCase.Input.Family(),
|
||||||
|
String: testCase.Input.String(),
|
||||||
|
}
|
||||||
|
if testCase.Input.Family().IsIP() {
|
||||||
|
actual.IP = testCase.Input.IP()
|
||||||
|
} else {
|
||||||
|
actual.Domain = testCase.Input.Domain()
|
||||||
|
}
|
||||||
|
|
||||||
domain := "v2ray.com"
|
if r := cmp.Diff(actual, testCase.Output); r != "" {
|
||||||
addr := DomainAddress(domain)
|
t.Error("for input: ", testCase.Input, ":", r)
|
||||||
|
}
|
||||||
assert(addr, IsDomain)
|
}
|
||||||
assert(addr, Not(IsIPv6))
|
|
||||||
assert(addr, Not(IsIPv4))
|
|
||||||
assert(addr.Domain(), Equals, domain)
|
|
||||||
assert(addr.String(), Equals, "v2ray.com")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNetIPv4Address(t *testing.T) {
|
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
ip := net.IPv4(1, 2, 3, 4)
|
|
||||||
addr := IPAddress(ip)
|
|
||||||
assert(addr, IsIPv4)
|
|
||||||
assert(addr.String(), Equals, "1.2.3.4")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseIPv6Address(t *testing.T) {
|
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
ip := ParseAddress("[2001:4860:0:2001::68]")
|
|
||||||
assert(ip, IsIPv6)
|
|
||||||
assert(ip.String(), Equals, "[2001:4860:0:2001::68]")
|
|
||||||
|
|
||||||
ip = ParseAddress("[::ffff:123.151.71.143]")
|
|
||||||
assert(ip, IsIPv4)
|
|
||||||
assert(ip.String(), Equals, "123.151.71.143")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidAddressConvertion(t *testing.T) {
|
func TestInvalidAddressConvertion(t *testing.T) {
|
||||||
assert := With(t)
|
panics := func(f func()) (ret bool) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ret = true
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
f()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
assert(func() { ParseAddress("8.8.8.8").Domain() }, Panics)
|
testCases := []func(){
|
||||||
assert(func() { ParseAddress("2001:4860:0:2001::68").Domain() }, Panics)
|
func() { ParseAddress("8.8.8.8").Domain() },
|
||||||
assert(func() { ParseAddress("v2ray.com").IP() }, Panics)
|
func() { ParseAddress("2001:4860:0:2001::68").Domain() },
|
||||||
}
|
func() { ParseAddress("v2ray.com").IP() },
|
||||||
|
}
|
||||||
func TestIPOrDomain(t *testing.T) {
|
for idx, testCase := range testCases {
|
||||||
assert := With(t)
|
if !panics(testCase) {
|
||||||
|
t.Error("case ", idx, " failed")
|
||||||
assert(NewIPOrDomain(ParseAddress("v2ray.com")).AsAddress(), Equals, ParseAddress("v2ray.com"))
|
}
|
||||||
assert(NewIPOrDomain(ParseAddress("8.8.8.8")).AsAddress(), Equals, ParseAddress("8.8.8.8"))
|
}
|
||||||
assert(NewIPOrDomain(ParseAddress("2001:4860:0:2001::68")).AsAddress(), Equals, ParseAddress("2001:4860:0:2001::68"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkParseAddressIPv4(b *testing.B) {
|
func BenchmarkParseAddressIPv4(b *testing.B) {
|
||||||
|
@ -3,32 +3,47 @@ package net_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
. "v2ray.com/core/common/net"
|
. "v2ray.com/core/common/net"
|
||||||
. "v2ray.com/core/common/net/testing"
|
|
||||||
. "v2ray.com/ext/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTCPDestination(t *testing.T) {
|
func TestDestinationProperty(t *testing.T) {
|
||||||
assert := With(t)
|
testCases := []struct {
|
||||||
|
Input Destination
|
||||||
|
Network Network
|
||||||
|
String string
|
||||||
|
NetString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Input: TCPDestination(IPAddress([]byte{1, 2, 3, 4}), 80),
|
||||||
|
Network: Network_TCP,
|
||||||
|
String: "tcp:1.2.3.4:80",
|
||||||
|
NetString: "1.2.3.4:80",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: UDPDestination(IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53),
|
||||||
|
Network: Network_UDP,
|
||||||
|
String: "udp:[2001:4860:4860::8888]:53",
|
||||||
|
NetString: "[2001:4860:4860::8888]:53",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
dest := TCPDestination(IPAddress([]byte{1, 2, 3, 4}), 80)
|
for _, testCase := range testCases {
|
||||||
assert(dest, IsTCP)
|
dest := testCase.Input
|
||||||
assert(dest, Not(IsUDP))
|
if r := cmp.Diff(dest.Network, testCase.Network); r != "" {
|
||||||
assert(dest.String(), Equals, "tcp:1.2.3.4:80")
|
t.Error("unexpected Network in ", dest.String(), ": ", r)
|
||||||
}
|
}
|
||||||
|
if r := cmp.Diff(dest.String(), testCase.String); r != "" {
|
||||||
func TestUDPDestination(t *testing.T) {
|
t.Error(r)
|
||||||
assert := With(t)
|
}
|
||||||
|
if r := cmp.Diff(dest.NetAddr(), testCase.NetString); r != "" {
|
||||||
dest := UDPDestination(IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53)
|
t.Error(r)
|
||||||
assert(dest, Not(IsTCP))
|
}
|
||||||
assert(dest, IsUDP)
|
}
|
||||||
assert(dest.String(), Equals, "udp:[2001:4860:4860::8888]:53")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDestinationParse(t *testing.T) {
|
func TestDestinationParse(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Input string
|
Input string
|
||||||
Output Destination
|
Output Destination
|
||||||
@ -69,10 +84,16 @@ func TestDestinationParse(t *testing.T) {
|
|||||||
for _, testcase := range cases {
|
for _, testcase := range cases {
|
||||||
d, err := ParseDestination(testcase.Input)
|
d, err := ParseDestination(testcase.Input)
|
||||||
if !testcase.Error {
|
if !testcase.Error {
|
||||||
assert(err, IsNil)
|
if err != nil {
|
||||||
assert(d, Equals, testcase.Output)
|
t.Error("for test case: ", testcase.Input, " expected no error, but got ", err)
|
||||||
|
}
|
||||||
|
if d != testcase.Output {
|
||||||
|
t.Error("for test case: ", testcase.Input, " expected output: ", testcase.Output.String(), " but got ", d.String())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(err, IsNotNil)
|
if err == nil {
|
||||||
|
t.Error("for test case: ", testcase.Input, " expected error, but got nil")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -12,10 +13,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
"v2ray.com/core"
|
"v2ray.com/core"
|
||||||
"v2ray.com/core/app/dispatcher"
|
"v2ray.com/core/app/dispatcher"
|
||||||
"v2ray.com/core/app/proxyman"
|
"v2ray.com/core/app/proxyman"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/retry"
|
"v2ray.com/core/common/retry"
|
||||||
@ -134,3 +137,33 @@ func withDefaultApps(config *core.Config) *core.Config {
|
|||||||
config.App = append(config.App, serial.ToTypedMessage(&proxyman.OutboundConfig{}))
|
config.App = append(config.App, serial.ToTypedMessage(&proxyman.OutboundConfig{}))
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testTCPConn(port net.Port, payloadSize int, timeout time.Duration) func() error {
|
||||||
|
return func() error {
|
||||||
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
||||||
|
IP: []byte{127, 0, 0, 1},
|
||||||
|
Port: int(port),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
payload := make([]byte, payloadSize)
|
||||||
|
common.Must2(rand.Read(payload))
|
||||||
|
|
||||||
|
nBytes, err := conn.Write(payload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if nBytes != len(payload) {
|
||||||
|
return errors.New("expect ", len(payload), " written, but actually ", nBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
response := readFrom(conn, timeout, payloadSize)
|
||||||
|
if r := cmp.Diff(response, xor(payload)); r != "" {
|
||||||
|
return errors.New(r)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -118,33 +118,7 @@ func TestShadowsocksAES256TCP(t *testing.T) {
|
|||||||
|
|
||||||
var errg errgroup.Group
|
var errg errgroup.Group
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
errg.Go(func() error {
|
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20))
|
||||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
|
||||||
IP: []byte{127, 0, 0, 1},
|
|
||||||
Port: int(clientPort),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
payload := make([]byte, 10240*1024)
|
|
||||||
common.Must2(rand.Read(payload))
|
|
||||||
|
|
||||||
nBytes, err := conn.Write([]byte(payload))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if nBytes != len(payload) {
|
|
||||||
return errors.New("expect ", len(payload), " written, but actually ", nBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
response := readFrom(conn, time.Second*20, 10240*1024)
|
|
||||||
if r := cmp.Diff(response, xor([]byte(payload))); r != "" {
|
|
||||||
return errors.New(r)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if err := errg.Wait(); err != nil {
|
if err := errg.Wait(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -278,7 +252,6 @@ func TestShadowsocksAES128UDP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestShadowsocksChacha20TCP(t *testing.T) {
|
func TestShadowsocksChacha20TCP(t *testing.T) {
|
||||||
|
|
||||||
tcpServer := tcp.Server{
|
tcpServer := tcp.Server{
|
||||||
MsgProcessor: xor,
|
MsgProcessor: xor,
|
||||||
}
|
}
|
||||||
@ -367,39 +340,16 @@ func TestShadowsocksChacha20TCP(t *testing.T) {
|
|||||||
|
|
||||||
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
defer CloseAllServers(servers)
|
defer CloseAllServers(servers)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var errg errgroup.Group
|
||||||
wg.Add(10)
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
go func() {
|
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20))
|
||||||
defer wg.Done()
|
}
|
||||||
|
|
||||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
if err := errg.Wait(); err != nil {
|
||||||
IP: []byte{127, 0, 0, 1},
|
t.Error(err)
|
||||||
Port: int(clientPort),
|
|
||||||
})
|
|
||||||
common.Must(err)
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
payload := make([]byte, 10240*1024)
|
|
||||||
rand.Read(payload)
|
|
||||||
|
|
||||||
nBytes, err := conn.Write([]byte(payload))
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
if nBytes != len(payload) {
|
|
||||||
t.Error("only part of payload is written: ", nBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
response := readFrom(conn, time.Second*20, 10240*1024)
|
|
||||||
if r := cmp.Diff(response, xor([]byte(payload))); r != "" {
|
|
||||||
t.Error(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
wg.Wait()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShadowsocksChacha20Poly1305TCP(t *testing.T) {
|
func TestShadowsocksChacha20Poly1305TCP(t *testing.T) {
|
||||||
@ -408,7 +358,6 @@ func TestShadowsocksChacha20Poly1305TCP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
dest, err := tcpServer.Start()
|
dest, err := tcpServer.Start()
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
account := serial.ToTypedMessage(&shadowsocks.Account{
|
account := serial.ToTypedMessage(&shadowsocks.Account{
|
||||||
@ -478,39 +427,15 @@ func TestShadowsocksChacha20Poly1305TCP(t *testing.T) {
|
|||||||
|
|
||||||
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
defer CloseAllServers(servers)
|
defer CloseAllServers(servers)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var errg errgroup.Group
|
||||||
wg.Add(10)
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
go func() {
|
errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20))
|
||||||
defer wg.Done()
|
}
|
||||||
|
if err := errg.Wait(); err != nil {
|
||||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
t.Error(err)
|
||||||
IP: []byte{127, 0, 0, 1},
|
|
||||||
Port: int(clientPort),
|
|
||||||
})
|
|
||||||
common.Must(err)
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
payload := make([]byte, 10240*1024)
|
|
||||||
rand.Read(payload)
|
|
||||||
|
|
||||||
nBytes, err := conn.Write([]byte(payload))
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
if nBytes != len(payload) {
|
|
||||||
t.Error("only part of payload is written: ", nBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
response := readFrom(conn, time.Second*20, 10240*1024)
|
|
||||||
if r := cmp.Diff(response, xor([]byte(payload))); r != "" {
|
|
||||||
t.Error(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
wg.Wait()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShadowsocksAES256GCMTCP(t *testing.T) {
|
func TestShadowsocksAES256GCMTCP(t *testing.T) {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
"v2ray.com/core"
|
"v2ray.com/core"
|
||||||
"v2ray.com/core/app/log"
|
"v2ray.com/core/app/log"
|
||||||
"v2ray.com/core/app/proxyman"
|
"v2ray.com/core/app/proxyman"
|
||||||
@ -943,13 +944,11 @@ func TestVMessKCP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVMessKCPLarge(t *testing.T) {
|
func TestVMessKCPLarge(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
tcpServer := tcp.Server{
|
tcpServer := tcp.Server{
|
||||||
MsgProcessor: xor,
|
MsgProcessor: xor,
|
||||||
}
|
}
|
||||||
dest, err := tcpServer.Start()
|
dest, err := tcpServer.Start()
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
@ -1081,163 +1080,24 @@ func TestVMessKCPLarge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
defer CloseAllServers(servers)
|
defer CloseAllServers(servers)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var errg errgroup.Group
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
wg.Add(1)
|
errg.Go(testTCPConn(clientPort, 10240*1024, time.Minute*5))
|
||||||
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()
|
|
||||||
|
|
||||||
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)
|
|
||||||
if r := cmp.Diff(response, xor(payload)); r != "" {
|
|
||||||
t.Error(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
wg.Wait()
|
if err := errg.Wait(); err != nil {
|
||||||
}
|
t.Error(err)
|
||||||
|
|
||||||
func TestVMessIPv6(t *testing.T) {
|
|
||||||
t.SkipNow() // No IPv6 on travis-ci.
|
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
tcpServer := tcp.Server{
|
|
||||||
MsgProcessor: xor,
|
|
||||||
Listen: net.LocalHostIPv6,
|
|
||||||
}
|
}
|
||||||
dest, err := tcpServer.Start()
|
|
||||||
assert(err, IsNil)
|
|
||||||
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.LocalHostIPv6),
|
|
||||||
}),
|
|
||||||
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.LocalHostIPv6),
|
|
||||||
}),
|
|
||||||
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.LocalHostIPv6),
|
|
||||||
Port: uint32(serverPort),
|
|
||||||
User: []*protocol.User{
|
|
||||||
{
|
|
||||||
Account: serial.ToTypedMessage(&vmess.Account{
|
|
||||||
Id: userID.String(),
|
|
||||||
AlterId: 64,
|
|
||||||
SecuritySettings: &protocol.SecurityConfig{
|
|
||||||
Type: protocol.SecurityType_AES128_GCM,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
||||||
assert(err, IsNil)
|
|
||||||
|
|
||||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
|
||||||
IP: net.LocalHostIPv6.IP(),
|
|
||||||
Port: int(clientPort),
|
|
||||||
})
|
|
||||||
assert(err, IsNil)
|
|
||||||
|
|
||||||
payload := make([]byte, 1024)
|
|
||||||
rand.Read(payload)
|
|
||||||
|
|
||||||
nBytes, err := conn.Write(payload)
|
|
||||||
assert(err, IsNil)
|
|
||||||
assert(nBytes, Equals, len(payload))
|
|
||||||
|
|
||||||
response := readFrom(conn, time.Second*20, 1024)
|
|
||||||
assert(response, Equals, xor(payload))
|
|
||||||
assert(conn.Close(), IsNil)
|
|
||||||
|
|
||||||
CloseAllServers(servers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVMessGCMMux(t *testing.T) {
|
func TestVMessGCMMux(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
tcpServer := tcp.Server{
|
tcpServer := tcp.Server{
|
||||||
MsgProcessor: xor,
|
MsgProcessor: xor,
|
||||||
}
|
}
|
||||||
dest, err := tcpServer.Start()
|
dest, err := tcpServer.Start()
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
defer tcpServer.Close()
|
defer tcpServer.Close()
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
userID := protocol.NewID(uuid.New())
|
||||||
@ -1329,40 +1189,19 @@ func TestVMessGCMMux(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
|
defer CloseAllServers(servers)
|
||||||
|
|
||||||
for range "abcd" {
|
for range "abcd" {
|
||||||
var wg sync.WaitGroup
|
var errg errgroup.Group
|
||||||
const nConnection = 16
|
for i := 0; i < 16; i++ {
|
||||||
wg.Add(nConnection)
|
errg.Go(testTCPConn(clientPort, 10240, time.Second*20))
|
||||||
for i := 0; i < nConnection; i++ {
|
}
|
||||||
go func() {
|
if err := errg.Wait(); err != nil {
|
||||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
t.Fatal(err)
|
||||||
IP: []byte{127, 0, 0, 1},
|
|
||||||
Port: int(clientPort),
|
|
||||||
})
|
|
||||||
assert(err, IsNil)
|
|
||||||
|
|
||||||
payload := make([]byte, 10240)
|
|
||||||
rand.Read(payload)
|
|
||||||
|
|
||||||
xorpayload := xor(payload)
|
|
||||||
|
|
||||||
nBytes, err := conn.Write(payload)
|
|
||||||
assert(err, IsNil)
|
|
||||||
assert(nBytes, Equals, len(payload))
|
|
||||||
|
|
||||||
response := readFrom(conn, time.Second*20, 10240)
|
|
||||||
assert(response, Equals, xorpayload)
|
|
||||||
assert(conn.Close(), IsNil)
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
wg.Wait()
|
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseAllServers(servers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVMessGCMMuxUDP(t *testing.T) {
|
func TestVMessGCMMuxUDP(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user