Migrate multiplex and UoT server to inbound &

Add tcp-brutal support for multiplex
This commit is contained in:
世界
2023-11-03 01:47:25 +08:00
parent 58c0759cdf
commit 5b9d1e2ae2
63 changed files with 708 additions and 160 deletions

86
test/brutal_test.go Normal file
View File

@@ -0,0 +1,86 @@
package main
import (
"net/netip"
"testing"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
)
func TestMuxBrutal(t *testing.T) {
method := shadowaead_2022.List[0]
password := mkBase64(t, 16)
startInstance(t, option.Options{
Inbounds: []option.Inbound{
{
Type: C.TypeMixed,
Tag: "mixed-in",
MixedOptions: option.HTTPMixedInboundOptions{
ListenOptions: option.ListenOptions{
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
ListenPort: clientPort,
},
},
},
{
Type: C.TypeShadowsocks,
ShadowsocksOptions: option.ShadowsocksInboundOptions{
ListenOptions: option.ListenOptions{
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
ListenPort: serverPort,
},
Method: method,
Password: password,
Multiplex: &option.InboundMultiplexOptions{
Enabled: true,
Brutal: &option.BrutalOptions{
Enabled: true,
UpMbps: 100,
DownMbps: 100,
},
},
},
},
},
Outbounds: []option.Outbound{
{
Type: C.TypeDirect,
},
{
Type: C.TypeShadowsocks,
Tag: "ss-out",
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
ServerOptions: option.ServerOptions{
Server: "127.0.0.1",
ServerPort: serverPort,
},
Method: method,
Password: password,
Multiplex: &option.OutboundMultiplexOptions{
Enabled: true,
Protocol: "smux",
Padding: true,
Brutal: &option.BrutalOptions{
Enabled: true,
UpMbps: 100,
DownMbps: 100,
},
},
},
},
},
Route: &option.RouteOptions{
Rules: []option.Rule{
{
DefaultOptions: option.DefaultRule{
Inbound: []string{"mixed-in"},
Outbound: "ss-out",
},
},
},
},
})
testSuit(t, clientPort, testPort)
}

View File

@@ -75,9 +75,9 @@ require (
github.com/sagernet/gvisor v0.0.0-20230930141345-5fef6f2e17ab // indirect
github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 // indirect
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 // indirect
github.com/sagernet/sing-mux v0.1.3 // indirect
github.com/sagernet/sing-mux v0.1.4-0.20231105044304-ae2745a33479 // indirect
github.com/sagernet/sing-shadowtls v0.1.4 // indirect
github.com/sagernet/sing-tun v0.1.17-0.20231030120513-2e85725657c1 // indirect
github.com/sagernet/sing-tun v0.1.17-0.20231104000158-fb98efb75ca7 // indirect
github.com/sagernet/sing-vmess v0.1.8 // indirect
github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 // indirect
github.com/sagernet/tfo-go v0.0.0-20230816093905-5a5c285d44a6 // indirect

View File

@@ -135,8 +135,8 @@ github.com/sagernet/sing v0.2.16-0.20231028125948-afcc9cb766c2 h1:PW18IgRodvppd0
github.com/sagernet/sing v0.2.16-0.20231028125948-afcc9cb766c2/go.mod h1:AhNEHu0GXrpqkuzvTwvC8+j2cQUU/dh+zLEmq4C99pg=
github.com/sagernet/sing-dns v0.1.10 h1:iIU7nRBlUYj+fF2TaktGIvRiTFFrHwSMedLQsvlTZCI=
github.com/sagernet/sing-dns v0.1.10/go.mod h1:vtUimtf7Nq9EdvD5WTpfCr69KL1M7bcgOVKiYBiAY/c=
github.com/sagernet/sing-mux v0.1.3 h1:fAf7PZa2A55mCeh0KKM02f1k2Y4vEmxuZZ/51ahkkLA=
github.com/sagernet/sing-mux v0.1.3/go.mod h1:wGeIeiiFLx4HUM5LAg65wrNZ/X1muOimqK0PEhNbPi0=
github.com/sagernet/sing-mux v0.1.4-0.20231105044304-ae2745a33479 h1:h6ANTA5wbP5BSqbjOT7s1OKLZgdsLqiXO564KQqY2i4=
github.com/sagernet/sing-mux v0.1.4-0.20231105044304-ae2745a33479/go.mod h1:wGeIeiiFLx4HUM5LAg65wrNZ/X1muOimqK0PEhNbPi0=
github.com/sagernet/sing-quic v0.1.3-0.20231026034240-fa3d997246b6 h1:w+TUbIZKZFSdf/AUa/y33kY9xaLeNGz/tBNcNhqpqfg=
github.com/sagernet/sing-quic v0.1.3-0.20231026034240-fa3d997246b6/go.mod h1:1M7xP4802K9Kz6BQ7LlA7UeCapWvWlH1Htmk2bAqkWc=
github.com/sagernet/sing-shadowsocks v0.2.5 h1:qxIttos4xu6ii7MTVJYA8EFQR7Q3KG6xMqmLJIFtBaY=
@@ -145,8 +145,8 @@ github.com/sagernet/sing-shadowsocks2 v0.1.4 h1:vht2M8t3m5DTgXR2j24KbYOygG5aOp+M
github.com/sagernet/sing-shadowsocks2 v0.1.4/go.mod h1:Mgdee99NxxNd5Zld3ixIs18yVs4x2dI2VTDDE1N14Wc=
github.com/sagernet/sing-shadowtls v0.1.4 h1:aTgBSJEgnumzFenPvc+kbD9/W0PywzWevnVpEx6Tw3k=
github.com/sagernet/sing-shadowtls v0.1.4/go.mod h1:F8NBgsY5YN2beQavdgdm1DPlhaKQlaL6lpDdcBglGK4=
github.com/sagernet/sing-tun v0.1.17-0.20231030120513-2e85725657c1 h1:QxC+myHDZ0BnkIEqXE0lWUzfYEVlhhQdSCo7mOMm7x4=
github.com/sagernet/sing-tun v0.1.17-0.20231030120513-2e85725657c1/go.mod h1:4ACZp3C6TDSy1rsMrfwtSyLrKPtm9Wm2eKHwhYIojbU=
github.com/sagernet/sing-tun v0.1.17-0.20231104000158-fb98efb75ca7 h1:nrjFCUNEsDZSZlxmE+tq8OuInjXI08vNfcSJ66gTbCs=
github.com/sagernet/sing-tun v0.1.17-0.20231104000158-fb98efb75ca7/go.mod h1:4ACZp3C6TDSy1rsMrfwtSyLrKPtm9Wm2eKHwhYIojbU=
github.com/sagernet/sing-vmess v0.1.8 h1:XVWad1RpTy9b5tPxdm5MCU8cGfrTGdR8qCq6HV2aCNc=
github.com/sagernet/sing-vmess v0.1.8/go.mod h1:vhx32UNzTDUkNwOyIjcZQohre1CaytquC5mPplId8uA=
github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 h1:HuE6xSwco/Xed8ajZ+coeYLmioq0Qp1/Z2zczFaV8as=

View File

@@ -18,7 +18,7 @@ var muxProtocols = []string{
}
func TestVMessSMux(t *testing.T) {
testVMessMux(t, option.MultiplexOptions{
testVMessMux(t, option.OutboundMultiplexOptions{
Enabled: true,
Protocol: "smux",
})
@@ -27,7 +27,7 @@ func TestVMessSMux(t *testing.T) {
func TestShadowsocksMux(t *testing.T) {
for _, protocol := range muxProtocols {
t.Run(protocol, func(t *testing.T) {
testShadowsocksMux(t, option.MultiplexOptions{
testShadowsocksMux(t, option.OutboundMultiplexOptions{
Enabled: true,
Protocol: protocol,
})
@@ -36,7 +36,7 @@ func TestShadowsocksMux(t *testing.T) {
}
func TestShadowsockH2Mux(t *testing.T) {
testShadowsocksMux(t, option.MultiplexOptions{
testShadowsocksMux(t, option.OutboundMultiplexOptions{
Enabled: true,
Protocol: "h2mux",
Padding: true,
@@ -44,14 +44,14 @@ func TestShadowsockH2Mux(t *testing.T) {
}
func TestShadowsockSMuxPadding(t *testing.T) {
testShadowsocksMux(t, option.MultiplexOptions{
testShadowsocksMux(t, option.OutboundMultiplexOptions{
Enabled: true,
Protocol: "smux",
Padding: true,
})
}
func testShadowsocksMux(t *testing.T, options option.MultiplexOptions) {
func testShadowsocksMux(t *testing.T, options option.OutboundMultiplexOptions) {
method := shadowaead_2022.List[0]
password := mkBase64(t, 16)
startInstance(t, option.Options{
@@ -90,9 +90,9 @@ func testShadowsocksMux(t *testing.T, options option.MultiplexOptions) {
Server: "127.0.0.1",
ServerPort: serverPort,
},
Method: method,
Password: password,
MultiplexOptions: &options,
Method: method,
Password: password,
Multiplex: &options,
},
},
},
@@ -110,7 +110,7 @@ func testShadowsocksMux(t *testing.T, options option.MultiplexOptions) {
testSuit(t, clientPort, testPort)
}
func testVMessMux(t *testing.T, options option.MultiplexOptions) {
func testVMessMux(t *testing.T, options option.OutboundMultiplexOptions) {
user, _ := uuid.NewV4()
startInstance(t, option.Options{
Inbounds: []option.Inbound{
@@ -136,6 +136,9 @@ func testVMessMux(t *testing.T, options option.MultiplexOptions) {
UUID: user.String(),
},
},
Multiplex: &option.InboundMultiplexOptions{
Enabled: true,
},
},
},
},

View File

@@ -232,7 +232,7 @@ func TestShadowsocksUoT(t *testing.T) {
},
Method: method,
Password: password,
UDPOverTCPOptions: &option.UDPOverTCPOptions{
UDPOverTCP: &option.UDPOverTCPOptions{
Enabled: true,
},
},