Refactor options
This commit is contained in:
@@ -394,16 +394,13 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
var outbounds []option.Outbound
|
||||
var tags []string
|
||||
OutboundMainProxyTag = OutboundSelectTag
|
||||
//inbound==warp over proxies
|
||||
//outbound==proxies over warp
|
||||
if opt.Warp.EnableWarp && (opt.Warp.Mode == "inbound" || opt.Warp.Mode == "outbound") {
|
||||
|
||||
if opt.Warp.EnableWarp && (opt.Warp.Mode == WarpOverProxy || opt.Warp.Mode == ProxyOverWarp) {
|
||||
out, err := generateWarpSingbox(opt.Warp.WireguardConfig.ToWireguardConfig(), opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate warp config: %v", err)
|
||||
}
|
||||
out.Tag = "Hiddify Warp ✅"
|
||||
if opt.Warp.Mode == "inbound" {
|
||||
if opt.Warp.Mode == WarpOverProxy {
|
||||
out.WireGuardOptions.Detour = OutboundURLTestTag
|
||||
OutboundMainProxyTag = out.Tag
|
||||
} else {
|
||||
@@ -529,7 +526,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
}
|
||||
|
||||
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
||||
if opt.Warp.EnableWarp && opt.Warp.Mode == "outbound" {
|
||||
if opt.Warp.EnableWarp && opt.Warp.Mode == ProxyOverWarp {
|
||||
if out.DirectOptions.Detour == "" {
|
||||
out.DirectOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
|
||||
6
config/constant.go
Normal file
6
config/constant.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
const (
|
||||
WarpOverProxy = "warp_over_proxy"
|
||||
ProxyOverWarp = "proxy_over_warp"
|
||||
)
|
||||
@@ -13,12 +13,12 @@ type ConfigOptions struct {
|
||||
GeoSitePath string `json:"geosite-path"`
|
||||
Rules []Rule `json:"rules"`
|
||||
Warp WarpOptions `json:"warp"`
|
||||
Mux MuxOptions `json:"mux"`
|
||||
TLSTricks TLSTricks `json:"tls-tricks"`
|
||||
DNSOptions
|
||||
InboundOptions
|
||||
URLTestOptions
|
||||
RouteOptions
|
||||
MuxOptions
|
||||
TLSTricks
|
||||
}
|
||||
|
||||
type DNSOptions struct {
|
||||
@@ -56,19 +56,19 @@ type RouteOptions struct {
|
||||
}
|
||||
|
||||
type TLSTricks struct {
|
||||
EnableFragment bool `json:"enable-tls-fragment"`
|
||||
FragmentSize string `json:"tls-fragment-size"`
|
||||
FragmentSleep string `json:"tls-fragment-sleep"`
|
||||
EnableMixedSNICase bool `json:"enable-tls-mixed-sni-case"`
|
||||
EnablePadding bool `json:"enable-tls-padding"`
|
||||
PaddingSize string `json:"tls-padding-size"`
|
||||
EnableFragment bool `json:"enable-fragment"`
|
||||
FragmentSize string `json:"fragment-size"`
|
||||
FragmentSleep string `json:"fragment-sleep"`
|
||||
MixedSNICase bool `json:"mixed-sni-case"`
|
||||
EnablePadding bool `json:"enable-padding"`
|
||||
PaddingSize string `json:"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"`
|
||||
Enable bool `json:"enable"`
|
||||
Padding bool `json:"padding"`
|
||||
MaxStreams int `json:"max-streams"`
|
||||
Protocol string `json:"protocol"`
|
||||
}
|
||||
|
||||
type WarpOptions struct {
|
||||
@@ -121,19 +121,19 @@ func DefaultConfigOptions() *ConfigOptions {
|
||||
GeoIPPath: "geoip.db",
|
||||
GeoSitePath: "geosite.db",
|
||||
Rules: []Rule{},
|
||||
MuxOptions: MuxOptions{
|
||||
EnableMux: true,
|
||||
MuxPadding: true,
|
||||
MaxStreams: 8,
|
||||
MuxProtocol: "h2mux",
|
||||
Mux: MuxOptions{
|
||||
Enable: true,
|
||||
Padding: true,
|
||||
MaxStreams: 8,
|
||||
Protocol: "h2mux",
|
||||
},
|
||||
TLSTricks: TLSTricks{
|
||||
EnableFragment: false,
|
||||
FragmentSize: "10-100",
|
||||
FragmentSleep: "50-200",
|
||||
EnableMixedSNICase: false,
|
||||
EnablePadding: false,
|
||||
PaddingSize: "1200-1500",
|
||||
EnableFragment: false,
|
||||
FragmentSize: "10-100",
|
||||
FragmentSleep: "50-200",
|
||||
MixedSNICase: false,
|
||||
EnablePadding: false,
|
||||
PaddingSize: "1200-1500",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
type outboundMap map[string]interface{}
|
||||
|
||||
func patchOutboundMux(base option.Outbound, configOpt ConfigOptions, obj outboundMap) outboundMap {
|
||||
if configOpt.EnableMux {
|
||||
if configOpt.Mux.Enable {
|
||||
multiplex := option.OutboundMultiplexOptions{
|
||||
Enabled: true,
|
||||
Padding: configOpt.MuxPadding,
|
||||
MaxStreams: configOpt.MaxStreams,
|
||||
Protocol: configOpt.MuxProtocol,
|
||||
Padding: configOpt.Mux.Padding,
|
||||
MaxStreams: configOpt.Mux.MaxStreams,
|
||||
Protocol: configOpt.Mux.Protocol,
|
||||
}
|
||||
obj["multiplex"] = multiplex
|
||||
// } else {
|
||||
@@ -66,7 +66,7 @@ func patchOutboundTLSTricks(base option.Outbound, configOpt ConfigOptions, obj o
|
||||
if tlsTricks == nil {
|
||||
tlsTricks = &option.TLSTricksOptions{}
|
||||
}
|
||||
tlsTricks.MixedCaseSNI = tlsTricks.MixedCaseSNI || configOpt.TLSTricks.EnableMixedSNICase
|
||||
tlsTricks.MixedCaseSNI = tlsTricks.MixedCaseSNI || configOpt.TLSTricks.MixedSNICase
|
||||
|
||||
if configOpt.TLSTricks.EnablePadding {
|
||||
tlsTricks.PaddingMode = "random"
|
||||
@@ -89,8 +89,7 @@ func patchOutboundTLSTricks(base option.Outbound, configOpt ConfigOptions, obj o
|
||||
}
|
||||
|
||||
func patchOutboundFragment(base option.Outbound, configOpt ConfigOptions, obj outboundMap) outboundMap {
|
||||
if configOpt.EnableFragment {
|
||||
|
||||
if configOpt.TLSTricks.EnableFragment {
|
||||
obj["tls_fragment"] = option.TLSFragmentOptions{
|
||||
Enabled: configOpt.TLSTricks.EnableFragment,
|
||||
Size: configOpt.TLSTricks.FragmentSize,
|
||||
|
||||
Reference in New Issue
Block a user