vless mux

This commit is contained in:
RPRX
2026-11-26 08:33:20 +00:00
committed by RPRXX
parent 328167bb1e
commit bdf29f1e4e
4 changed files with 26 additions and 15 deletions
+1 -4
View File
@@ -541,10 +541,7 @@ func TestXDriveOutboundConfig(t *testing.T) {
for _, c := range []struct{ input, err string }{ for _, c := range []struct{ input, err string }{
{`{"protocol": "vless", "settings": {` + xdriveServer + `, "encryption": "none", "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"encryption"`}, {`{"protocol": "vless", "settings": {` + xdriveServer + `, "encryption": "none", "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"encryption"`},
{`{"protocol": "vless", "settings": {"address": "example.com", "port": 443, ` + xdriveID + `, "encryption": "none", "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"encryption"`}, {`{"protocol": "vless", "settings": {"address": "example.com", "port": 443, ` + xdriveID + `, "encryption": "none", "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"encryption"`},
{`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `}, ` + xdriveStream + `}`, `"settings.multiplex.concurrency"`}, {`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `, "multiplex": {"concurrency": 8, "xudpProxyUDP443": "skip"}}, ` + xdriveStream + `}`, `"xudpProxyUDP443":"skip"`},
{`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `}, ` + xdriveStream + `, "mux": {"enabled": true}}`, `"settings.multiplex.concurrency"`},
{`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `, "multiplex": {"xudpConcurrency": 8}}, ` + xdriveStream + `}`, `"settings.multiplex.concurrency"`},
{`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `, "multiplex": {"concurrency": 8, "xudpProxyUDP443": "skip"}}, ` + xdriveStream + `}`, `"settings.multiplex.concurrency"`},
{`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `, "flow": "xtls-rprx-vision", "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"flow"`}, {`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `, "flow": "xtls-rprx-vision", "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"flow"`},
{`{"protocol": "vless", "settings": {"vnext": [{"address": "127.0.0.1", "port": 443, "users": [{` + xdriveID + `, ` + xdriveEnc + `, "flow": "xtls-rprx-vision"}]}], "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"flow"`}, {`{"protocol": "vless", "settings": {"vnext": [{"address": "127.0.0.1", "port": 443, "users": [{` + xdriveID + `, ` + xdriveEnc + `, "flow": "xtls-rprx-vision"}]}], "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"flow"`},
{`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `, "testpre": 1, "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"testpre"`}, {`{"protocol": "vless", "settings": {` + xdriveServer + `, ` + xdriveEnc + `, "testpre": 1, "multiplex": {"concurrency": 8}}, ` + xdriveStream + `}`, `"testpre"`},
+7 -2
View File
@@ -265,8 +265,13 @@ func validateXDrive(ts proto.Message, ss *internet.StreamConfig, pl *net.PortLis
return errors.New(`the xdrive transport needs VLESS "encryption", run "xray vlessenc" to get one`) return errors.New(`the xdrive transport needs VLESS "encryption", run "xray vlessenc" to get one`)
} }
// Reverse opens its own multiplexed connection. // Reverse opens its own multiplexed connection.
if account.Reverse == nil && (c.Multiplex.GetConcurrency() == 0 || c.Multiplex.GetXudpProxyUDP443() == "skip") { if account.Reverse == nil {
return errors.New(`the xdrive transport needs positive "settings.multiplex.concurrency" and does not support "xudpProxyUDP443":"skip"`) if c.Multiplex == nil {
c.Multiplex = &vless.Multiplex{Concurrency: 128}
}
if c.Multiplex.XudpProxyUDP443 == "skip" {
return errors.New(`the xdrive transport does not support "xudpProxyUDP443":"skip"`)
}
} }
if account.Testpre != 0 { if account.Testpre != 0 {
return errors.New(`the xdrive transport doesn't support VLESS "testpre"`) return errors.New(`the xdrive transport doesn't support VLESS "testpre"`)
+7
View File
@@ -36,6 +36,7 @@ import (
"github.com/xtls/xray-core/proxy/vless/multiplex" "github.com/xtls/xray-core/proxy/vless/multiplex"
"github.com/xtls/xray-core/proxy/vless/reverse" "github.com/xtls/xray-core/proxy/vless/reverse"
"github.com/xtls/xray-core/transport" "github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/reality" "github.com/xtls/xray-core/transport/internet/reality"
"github.com/xtls/xray-core/transport/internet/stat" "github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/tls" "github.com/xtls/xray-core/transport/internet/tls"
@@ -524,6 +525,12 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
} }
errors.LogInfo(ctx, "received request for ", request.Destination()) errors.LogInfo(ctx, "received request for ", request.Destination())
if stream, ok := session.StreamSettingsFromContext(h.ctx).(*internet.MemoryStreamConfig); ok && stream.ProtocolName == "xdrive" {
if request.Command != protocol.RequestCommandMux && request.Command != protocol.RequestCommandRvs {
return errors.New("VLESS over XDRIVE: inbound received a non-Mux/Rvs request")
}
}
inbound := session.InboundFromContext(ctx) inbound := session.InboundFromContext(ctx)
if inbound == nil { if inbound == nil {
panic("no inbound metadata") panic("no inbound metadata")
+11 -9
View File
@@ -42,17 +42,19 @@ type Client struct {
func NewClient(ctx context.Context, config *vless.Multiplex, network string, open func(context.Context) (context.Context, *transport.Link, error)) *Client { func NewClient(ctx context.Context, config *vless.Multiplex, network string, open func(context.Context) (context.Context, *transport.Link, error)) *Client {
c := &Client{config: config} c := &Client{config: config}
pool := func(concurrency int32) *Pool { maxReuseTimes := uint32(1024)
return NewPool(ctx, ClientStrategy{MaxConcurrency: uint32(concurrency), MaxConnection: 1024}, open) if network == "xdrive" {
} maxReuseTimes = 0 // unlimited
if concurrency := config.GetConcurrency(); concurrency > 0 { config.Concurrency = max(config.Concurrency, 128)
if network == "xdrive" { if config.XudpConcurrency > 0 {
concurrency = max(concurrency, 128) config.XudpConcurrency = max(config.XudpConcurrency, 128)
} }
c.tcp = pool(concurrency)
} }
if concurrency := config.GetXudpConcurrency(); concurrency > 0 { if config.Concurrency > 0 {
c.udp = pool(concurrency) c.tcp = NewPool(ctx, ClientStrategy{MaxConcurrency: uint32(config.Concurrency), MaxConnection: maxReuseTimes}, open)
}
if config.XudpConcurrency > 0 {
c.udp = NewPool(ctx, ClientStrategy{MaxConcurrency: uint32(config.XudpConcurrency), MaxConnection: maxReuseTimes}, open)
} }
return c return c
} }