From 987e25e7acd6544fe04445a755dd9ad7f5a55a22 Mon Sep 17 00:00:00 2001 From: Chang lue Tsen Date: Thu, 3 Jul 2025 14:45:42 -0400 Subject: [PATCH] fix(tuic): add additional configuration options for SNI, RTT reduction, UDP relay, and congestion control --- apis/types.api | 4 ++++ internal/types/types.go | 8 ++++++-- pkg/adapter/clash/parse.go | 22 ++++++++++++++-------- pkg/adapter/general/uri.go | 3 ++- pkg/adapter/proxy/proxy.go | 20 +++++++++++++++++--- pkg/adapter/singbox/tuic.go | 4 +++- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/apis/types.api b/apis/types.api index b24c445..6d32976 100644 --- a/apis/types.api +++ b/apis/types.api @@ -247,6 +247,10 @@ type ( } Tuic { Port int `json:"port" validate:"required"` + DisableSNI bool `json:"disable_sni"` + ReduceRtt bool `json:"reduce_rtt"` + UDPRelayMode string `json:"udp_relay_mode"` + CongestionController string `json:"congestion_controller"` SecurityConfig SecurityConfig `json:"security_config"` } SecurityConfig { diff --git a/internal/types/types.go b/internal/types/types.go index 4f622b5..ad8157c 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1803,8 +1803,12 @@ type TrojanProtocol struct { } type Tuic struct { - Port int `json:"port" validate:"required"` - SecurityConfig SecurityConfig `json:"security_config"` + Port int `json:"port" validate:"required"` + DisableSNI bool `json:"disable_sni"` + ReduceRtt bool `json:"reduce_rtt"` + UDPRelayMode string `json:"udp_relay_mode"` + CongestionController string `json:"congestion_controller"` + SecurityConfig SecurityConfig `json:"security_config"` } type UnbindOAuthRequest struct { diff --git a/pkg/adapter/clash/parse.go b/pkg/adapter/clash/parse.go index acc16aa..b0bf6fa 100644 --- a/pkg/adapter/clash/parse.go +++ b/pkg/adapter/clash/parse.go @@ -116,15 +116,21 @@ func parseTuic(data proxy.Proxy, uuid string) (*Proxy, error) { if !ok { return nil, fmt.Errorf("invalid type for Tuic") } + p := &Proxy{ - Name: data.Name, - Type: "tuic", - Server: data.Server, - Port: data.Port, - UUID: uuid, - Password: uuid, - SNI: tuic.SecurityConfig.SNI, - SkipCertVerify: tuic.SecurityConfig.AllowInsecure, + Name: data.Name, + Type: "tuic", + Server: data.Server, + Port: data.Port, + UUID: uuid, + Password: uuid, + ALPN: []string{"h3"}, + DisableSni: tuic.DisableSNI, + ReduceRtt: tuic.ReduceRtt, + CongestionController: tuic.CongestionController, + UdpRelayMode: tuic.UDPRelayMode, + SNI: tuic.SecurityConfig.SNI, + SkipCertVerify: tuic.SecurityConfig.AllowInsecure, } return p, nil diff --git a/pkg/adapter/general/uri.go b/pkg/adapter/general/uri.go index 4e88b29..c1c925b 100644 --- a/pkg/adapter/general/uri.go +++ b/pkg/adapter/general/uri.go @@ -249,7 +249,8 @@ func TuicUri(data proxy.Proxy, uuid string) string { tuic := data.Option.(proxy.Tuic) var query = make(url.Values) - setQuery(&query, "congestion_control", "bbr") + setQuery(&query, "congestion_control", tuic.CongestionController) + setQuery(&query, "udp_relay_mode", tuic.UDPRelayMode) if tuic.SecurityConfig.SNI != "" { setQuery(&query, "sni", tuic.SecurityConfig.SNI) diff --git a/pkg/adapter/proxy/proxy.go b/pkg/adapter/proxy/proxy.go index d2cf603..ee74d72 100644 --- a/pkg/adapter/proxy/proxy.go +++ b/pkg/adapter/proxy/proxy.go @@ -83,15 +83,29 @@ type Hysteria2 struct { // Tuic represents a Tuic proxy configuration type Tuic struct { + Port int `json:"port"` + DisableSNI bool `json:"disable_sni"` + ReduceRtt bool `json:"reduce_rtt"` + UDPRelayMode string `json:"udp_relay_mode"` + CongestionController string `json:"congestion_controller"` + SecurityConfig SecurityConfig `json:"security_config"` +} + +// AnyTLS represents an AnyTLS proxy configuration +type AnyTLS struct { Port int `json:"port"` SecurityConfig SecurityConfig `json:"security_config"` } // TransportConfig represents the transport configuration for a proxy type TransportConfig struct { - Path string `json:"path,omitempty"` // ws/httpupgrade - Host string `json:"host,omitempty"` - ServiceName string `json:"service_name"` // grpc + Path string `json:"path,omitempty"` // ws/httpupgrade + Host string `json:"host,omitempty"` + ServiceName string `json:"service_name"` // grpc + DisableSNI bool `json:"disable_sni"` // Disable SNI for the transport(tuic) + ReduceRtt bool `json:"reduce_rtt"` // Reduce RTT for the transport(tuic) + UDPRelayMode string `json:"udp_relay_mode"` // UDP relay mode for the transport(tuic) + CongestionController string `json:"congestion_controller"` // Congestion controller for the transport(tuic) } // SecurityConfig represents the security configuration for a proxy diff --git a/pkg/adapter/singbox/tuic.go b/pkg/adapter/singbox/tuic.go index 08f4942..8267d40 100644 --- a/pkg/adapter/singbox/tuic.go +++ b/pkg/adapter/singbox/tuic.go @@ -31,7 +31,9 @@ func ParseTUIC(data proxy.Proxy, uuid string) (*Proxy, error) { }, UUID: uuid, Password: uuid, - CongestionControl: "bbr", + CongestionControl: tuic.CongestionController, + UDPRelayMode: tuic.UDPRelayMode, + ZeroRTTHandshake: tuic.ReduceRtt, }, } // Security options