Refactor options

This commit is contained in:
problematicconsumer
2024-03-07 20:20:04 +03:30
parent f9e6f022c8
commit 43fd1ceb17
4 changed files with 38 additions and 36 deletions

View File

@@ -394,16 +394,13 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
var outbounds []option.Outbound var outbounds []option.Outbound
var tags []string var tags []string
OutboundMainProxyTag = OutboundSelectTag OutboundMainProxyTag = OutboundSelectTag
//inbound==warp over proxies if opt.Warp.EnableWarp && (opt.Warp.Mode == WarpOverProxy || opt.Warp.Mode == ProxyOverWarp) {
//outbound==proxies over warp
if opt.Warp.EnableWarp && (opt.Warp.Mode == "inbound" || opt.Warp.Mode == "outbound") {
out, err := generateWarpSingbox(opt.Warp.WireguardConfig.ToWireguardConfig(), opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay) 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 { if err != nil {
return nil, fmt.Errorf("failed to generate warp config: %v", err) return nil, fmt.Errorf("failed to generate warp config: %v", err)
} }
out.Tag = "Hiddify Warp ✅" out.Tag = "Hiddify Warp ✅"
if opt.Warp.Mode == "inbound" { if opt.Warp.Mode == WarpOverProxy {
out.WireGuardOptions.Detour = OutboundURLTestTag out.WireGuardOptions.Detour = OutboundURLTestTag
OutboundMainProxyTag = out.Tag OutboundMainProxyTag = out.Tag
} else { } else {
@@ -529,7 +526,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
} }
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound { 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 == "" { if out.DirectOptions.Detour == "" {
out.DirectOptions.Detour = "Hiddify Warp ✅" out.DirectOptions.Detour = "Hiddify Warp ✅"
} }

6
config/constant.go Normal file
View File

@@ -0,0 +1,6 @@
package config
const (
WarpOverProxy = "warp_over_proxy"
ProxyOverWarp = "proxy_over_warp"
)

View File

@@ -13,12 +13,12 @@ type ConfigOptions struct {
GeoSitePath string `json:"geosite-path"` GeoSitePath string `json:"geosite-path"`
Rules []Rule `json:"rules"` Rules []Rule `json:"rules"`
Warp WarpOptions `json:"warp"` Warp WarpOptions `json:"warp"`
Mux MuxOptions `json:"mux"`
TLSTricks TLSTricks `json:"tls-tricks"`
DNSOptions DNSOptions
InboundOptions InboundOptions
URLTestOptions URLTestOptions
RouteOptions RouteOptions
MuxOptions
TLSTricks
} }
type DNSOptions struct { type DNSOptions struct {
@@ -56,19 +56,19 @@ type RouteOptions struct {
} }
type TLSTricks struct { type TLSTricks struct {
EnableFragment bool `json:"enable-tls-fragment"` EnableFragment bool `json:"enable-fragment"`
FragmentSize string `json:"tls-fragment-size"` FragmentSize string `json:"fragment-size"`
FragmentSleep string `json:"tls-fragment-sleep"` FragmentSleep string `json:"fragment-sleep"`
EnableMixedSNICase bool `json:"enable-tls-mixed-sni-case"` MixedSNICase bool `json:"mixed-sni-case"`
EnablePadding bool `json:"enable-tls-padding"` EnablePadding bool `json:"enable-padding"`
PaddingSize string `json:"tls-padding-size"` PaddingSize string `json:"padding-size"`
} }
type MuxOptions struct { type MuxOptions struct {
EnableMux bool `json:"enable-mux"` Enable bool `json:"enable"`
MuxPadding bool `json:"mux-padding"` Padding bool `json:"padding"`
MaxStreams int `json:"mux-max-streams"` MaxStreams int `json:"max-streams"`
MuxProtocol string `json:"mux-protocol"` Protocol string `json:"protocol"`
} }
type WarpOptions struct { type WarpOptions struct {
@@ -121,19 +121,19 @@ func DefaultConfigOptions() *ConfigOptions {
GeoIPPath: "geoip.db", GeoIPPath: "geoip.db",
GeoSitePath: "geosite.db", GeoSitePath: "geosite.db",
Rules: []Rule{}, Rules: []Rule{},
MuxOptions: MuxOptions{ Mux: MuxOptions{
EnableMux: true, Enable: true,
MuxPadding: true, Padding: true,
MaxStreams: 8, MaxStreams: 8,
MuxProtocol: "h2mux", Protocol: "h2mux",
}, },
TLSTricks: TLSTricks{ TLSTricks: TLSTricks{
EnableFragment: false, EnableFragment: false,
FragmentSize: "10-100", FragmentSize: "10-100",
FragmentSleep: "50-200", FragmentSleep: "50-200",
EnableMixedSNICase: false, MixedSNICase: false,
EnablePadding: false, EnablePadding: false,
PaddingSize: "1200-1500", PaddingSize: "1200-1500",
}, },
} }
} }

View File

@@ -12,12 +12,12 @@ import (
type outboundMap map[string]interface{} type outboundMap map[string]interface{}
func patchOutboundMux(base option.Outbound, configOpt ConfigOptions, obj outboundMap) outboundMap { func patchOutboundMux(base option.Outbound, configOpt ConfigOptions, obj outboundMap) outboundMap {
if configOpt.EnableMux { if configOpt.Mux.Enable {
multiplex := option.OutboundMultiplexOptions{ multiplex := option.OutboundMultiplexOptions{
Enabled: true, Enabled: true,
Padding: configOpt.MuxPadding, Padding: configOpt.Mux.Padding,
MaxStreams: configOpt.MaxStreams, MaxStreams: configOpt.Mux.MaxStreams,
Protocol: configOpt.MuxProtocol, Protocol: configOpt.Mux.Protocol,
} }
obj["multiplex"] = multiplex obj["multiplex"] = multiplex
// } else { // } else {
@@ -66,7 +66,7 @@ func patchOutboundTLSTricks(base option.Outbound, configOpt ConfigOptions, obj o
if tlsTricks == nil { if tlsTricks == nil {
tlsTricks = &option.TLSTricksOptions{} tlsTricks = &option.TLSTricksOptions{}
} }
tlsTricks.MixedCaseSNI = tlsTricks.MixedCaseSNI || configOpt.TLSTricks.EnableMixedSNICase tlsTricks.MixedCaseSNI = tlsTricks.MixedCaseSNI || configOpt.TLSTricks.MixedSNICase
if configOpt.TLSTricks.EnablePadding { if configOpt.TLSTricks.EnablePadding {
tlsTricks.PaddingMode = "random" 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 { func patchOutboundFragment(base option.Outbound, configOpt ConfigOptions, obj outboundMap) outboundMap {
if configOpt.EnableFragment { if configOpt.TLSTricks.EnableFragment {
obj["tls_fragment"] = option.TLSFragmentOptions{ obj["tls_fragment"] = option.TLSFragmentOptions{
Enabled: configOpt.TLSTricks.EnableFragment, Enabled: configOpt.TLSTricks.EnableFragment,
Size: configOpt.TLSTricks.FragmentSize, Size: configOpt.TLSTricks.FragmentSize,