Add multiplexer for vmess

This commit is contained in:
世界 2022-08-04 10:38:20 +08:00
parent 1c3c154d6d
commit 64dbac8138
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
12 changed files with 171 additions and 50 deletions

View file

@ -8,19 +8,31 @@ import (
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
"github.com/gofrs/uuid"
)
var muxProtocols = []mux.Protocol{
mux.ProtocolYAMux,
mux.ProtocolSMux,
}
func TestShadowsocksMux(t *testing.T) {
for _, protocol := range []mux.Protocol{
mux.ProtocolYAMux,
mux.ProtocolSMux,
} {
for _, protocol := range muxProtocols {
t.Run(protocol.String(), func(t *testing.T) {
testShadowsocksMux(t, protocol.String())
})
}
}
func TestVMessMux(t *testing.T) {
for _, protocol := range muxProtocols {
t.Run(protocol.String(), func(t *testing.T) {
testVMessMux(t, protocol.String())
})
}
}
func testShadowsocksMux(t *testing.T, protocol string) {
method := shadowaead_2022.List[0]
password := mkBase64(t, 16)
@ -65,7 +77,7 @@ func testShadowsocksMux(t *testing.T, protocol string) {
},
Method: method,
Password: password,
Multiplex: &option.MultiplexOptions{
MultiplexOptions: &option.MultiplexOptions{
Enabled: true,
Protocol: protocol,
},
@ -85,3 +97,70 @@ func testShadowsocksMux(t *testing.T, protocol string) {
})
testSuit(t, clientPort, testPort)
}
func testVMessMux(t *testing.T, protocol string) {
user, _ := uuid.NewV4()
startInstance(t, option.Options{
Log: &option.LogOptions{
Level: "trace",
},
Inbounds: []option.Inbound{
{
Type: C.TypeMixed,
Tag: "mixed-in",
MixedOptions: option.HTTPMixedInboundOptions{
ListenOptions: option.ListenOptions{
Listen: option.ListenAddress(netip.IPv4Unspecified()),
ListenPort: clientPort,
},
},
},
{
Type: C.TypeVMess,
VMessOptions: option.VMessInboundOptions{
ListenOptions: option.ListenOptions{
Listen: option.ListenAddress(netip.IPv4Unspecified()),
ListenPort: serverPort,
},
Users: []option.VMessUser{
{
UUID: user.String(),
},
},
},
},
},
Outbounds: []option.Outbound{
{
Type: C.TypeDirect,
},
{
Type: C.TypeVMess,
Tag: "vmess-out",
VMessOptions: option.VMessOutboundOptions{
ServerOptions: option.ServerOptions{
Server: "127.0.0.1",
ServerPort: serverPort,
},
Security: "auto",
UUID: user.String(),
MultiplexOptions: &option.MultiplexOptions{
Enabled: true,
Protocol: protocol,
},
},
},
},
Route: &option.RouteOptions{
Rules: []option.Rule{
{
DefaultOptions: option.DefaultRule{
Inbound: []string{"mixed-in"},
Outbound: "vmess-out",
},
},
},
},
})
testSuit(t, clientPort, testPort)
}