diff --git a/config/option.go b/config/option.go index d12b7f1..15a8302 100644 --- a/config/option.go +++ b/config/option.go @@ -35,6 +35,7 @@ type ConfigOptions struct { GeoIPPath string `json:"geoip-path"` GeoSitePath string `json:"geosite-path"` Rules []Rule `json:"rules"` + MuxOptions TLSTricks } @@ -47,6 +48,13 @@ type TLSTricks struct { PaddingSize string `json:"tls-padding-size"` } +type MuxOptions struct { + EnableMux bool `json:"enable-mux"` + MuxPadding bool `json:"mux-padding"` + MaxStreams int `json:"mux-max-streams"` + MuxProtocol string `json:"mux-protocol"` +} + func DefaultConfigOptions() *ConfigOptions { return &ConfigOptions{ ExecuteAsIs: false, @@ -76,6 +84,12 @@ func DefaultConfigOptions() *ConfigOptions { GeoIPPath: "geoip.db", GeoSitePath: "geosite.db", Rules: []Rule{}, + MuxOptions: MuxOptions{ + EnableMux: true, + MuxPadding: true, + MaxStreams: 8, + MuxProtocol: "h2mux", + }, TLSTricks: TLSTricks{ EnableFragment: false, FragmentSize: "10-100", diff --git a/config/outbound.go b/config/outbound.go index 8c1dc77..b55bca4 100644 --- a/config/outbound.go +++ b/config/outbound.go @@ -9,6 +9,8 @@ import ( "github.com/sagernet/sing-box/option" ) +type outboundMap map[string]interface{} + func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbound, string, error) { var serverDomain string var outbound option.Outbound @@ -22,7 +24,7 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo return nil, "", formatErr(err) } - var obj map[string]interface{} + var obj outboundMap err = json.Unmarshal(jsonData, &obj) if err != nil { return nil, "", formatErr(err) @@ -64,6 +66,21 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo } } + switch base.Type { + case C.TypeVMess, C.TypeVLESS, C.TypeTrojan, C.TypeShadowsocks: + if configOpt.EnableMux { + multiplex := option.OutboundMultiplexOptions{ + Enabled: true, + Padding: configOpt.MuxPadding, + MaxStreams: configOpt.MaxStreams, + Protocol: configOpt.MuxProtocol, + } + obj["multiplex"] = multiplex + } else { + delete(obj, "multiplex") + } + } + modifiedJson, err := json.Marshal(obj) if err != nil { return nil, "", formatErr(err) @@ -76,3 +93,12 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo return &outbound, serverDomain, nil } + +// func (o outboundMap) transportType() string { +// if transport, ok := o["transport"].(map[string]interface{}); ok { +// if transportType, ok := transport["type"].(string); ok { +// return transportType +// } +// } +// return "" +// }