fix: warp configs, add warp delay, fix network switch
This commit is contained in:
@@ -116,8 +116,17 @@ func readConfigOptionsAt(path string) (*config.ConfigOptions, error) {
|
||||
}
|
||||
var options config.ConfigOptions
|
||||
err = json.Unmarshal(content, &options)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if options.Warp.WireguardConfigStr != "" {
|
||||
err := json.Unmarshal([]byte(options.Warp.WireguardConfigStr), &options.Warp.WireguardConfig)
|
||||
if err != nil {
|
||||
p
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &options, nil
|
||||
}
|
||||
|
||||
@@ -36,7 +36,10 @@ const (
|
||||
InboundDNSTag = "dns-in"
|
||||
)
|
||||
|
||||
var OutboundMainProxyTag = OutboundSelectTag
|
||||
|
||||
func BuildConfigJson(configOpt ConfigOptions, input option.Options) (string, error) {
|
||||
|
||||
options, err := BuildConfig(configOpt, input)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -246,7 +249,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
Type: C.RuleTypeDefault,
|
||||
DefaultOptions: option.DefaultRule{
|
||||
ClashMode: "Global",
|
||||
Outbound: OutboundSelectTag,
|
||||
Outbound: OutboundMainProxyTag,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -388,16 +391,29 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
|
||||
var outbounds []option.Outbound
|
||||
var tags []string
|
||||
if opt.Warp.EnableWarp && (opt.Warp.Mode == "proxy_over_warp" || opt.Warp.Mode == "warp_over_proxy") {
|
||||
OutboundMainProxyTag = OutboundSelectTag
|
||||
//inbound==warp over proxies
|
||||
//outbound==proxies over warp
|
||||
if opt.Warp.EnableWarp && (opt.Warp.Mode == "inbound" || opt.Warp.Mode == "outbound") {
|
||||
fmt.Println("===========================")
|
||||
fmt.Printf("%+v\n\n", opt.Warp)
|
||||
fmt.Printf("%+v\n\n", opt.Warp.WireguardConfig)
|
||||
fmt.Printf("%+v\n\n", opt.Warp.Account)
|
||||
|
||||
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 Config"
|
||||
if opt.Warp.Mode == "warp_over_proxy" {
|
||||
out.WireGuardOptions.Detour = "select"
|
||||
out.Tag = "Hiddify Warp ✅"
|
||||
if opt.Warp.Mode == "inbound" {
|
||||
out.WireGuardOptions.Detour = OutboundURLTestTag
|
||||
OutboundMainProxyTag = out.Tag
|
||||
} else {
|
||||
out.WireGuardOptions.Detour = OutboundDirectTag
|
||||
}
|
||||
patchWarp(out)
|
||||
outbounds = append(outbounds, *out)
|
||||
// tags = append(tags, out.Tag)
|
||||
}
|
||||
for _, out := range input.Outbounds {
|
||||
outbound, serverDomain, err := patchOutbound(out, opt)
|
||||
@@ -439,7 +455,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
|
||||
selector := option.Outbound{
|
||||
Type: C.TypeSelector,
|
||||
Tag: "select",
|
||||
Tag: OutboundSelectTag,
|
||||
SelectorOptions: option.SelectorOutboundOptions{
|
||||
Outbounds: append([]string{urlTest.Tag}, tags...),
|
||||
Default: urlTest.Tag,
|
||||
@@ -510,27 +526,57 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
dnsRule.Server = DNSDirectTag
|
||||
options.DNS.Rules = append([]option.DNSRule{{Type: C.RuleTypeDefault, DefaultOptions: dnsRule}}, options.DNS.Rules...)
|
||||
}
|
||||
|
||||
options.Route.Final = OutboundMainProxyTag
|
||||
return &options, nil
|
||||
}
|
||||
|
||||
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
||||
if opt.Warp.EnableWarp && opt.Warp.Mode == "proxy_over_warp" {
|
||||
out.DirectOptions.Detour = "Hiddify Warp Config"
|
||||
out.HTTPOptions.Detour = "Hiddify Warp Config"
|
||||
out.Hysteria2Options.Detour = "Hiddify Warp Config"
|
||||
out.HysteriaOptions.Detour = "Hiddify Warp Config"
|
||||
out.SSHOptions.Detour = "Hiddify Warp Config"
|
||||
out.ShadowTLSOptions.Detour = "Hiddify Warp Config"
|
||||
out.ShadowsocksOptions.Detour = "Hiddify Warp Config"
|
||||
out.ShadowsocksROptions.Detour = "Hiddify Warp Config"
|
||||
out.SocksOptions.Detour = "Hiddify Warp Config"
|
||||
out.TUICOptions.Detour = "Hiddify Warp Config"
|
||||
out.TorOptions.Detour = "Hiddify Warp Config"
|
||||
out.TrojanOptions.Detour = "Hiddify Warp Config"
|
||||
out.VLESSOptions.Detour = "Hiddify Warp Config"
|
||||
out.VMessOptions.Detour = "Hiddify Warp Config"
|
||||
out.WireGuardOptions.Detour = "Hiddify Warp Config"
|
||||
if opt.Warp.EnableWarp && opt.Warp.Mode == "outbound" {
|
||||
if out.DirectOptions.Detour == "" {
|
||||
out.DirectOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.HTTPOptions.Detour == "" {
|
||||
out.HTTPOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.Hysteria2Options.Detour == "" {
|
||||
out.Hysteria2Options.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.HysteriaOptions.Detour == "" {
|
||||
out.HysteriaOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.SSHOptions.Detour == "" {
|
||||
out.SSHOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.ShadowTLSOptions.Detour == "" {
|
||||
out.ShadowTLSOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.ShadowsocksOptions.Detour == "" {
|
||||
out.ShadowsocksOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.ShadowsocksROptions.Detour == "" {
|
||||
out.ShadowsocksROptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.SocksOptions.Detour == "" {
|
||||
out.SocksOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.TUICOptions.Detour == "" {
|
||||
out.TUICOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.TorOptions.Detour == "" {
|
||||
out.TorOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.TrojanOptions.Detour == "" {
|
||||
out.TrojanOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.VLESSOptions.Detour == "" {
|
||||
out.VLESSOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.VMessOptions.Detour == "" {
|
||||
out.VMessOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
if out.WireGuardOptions.Detour == "" {
|
||||
out.WireGuardOptions.Detour = "Hiddify Warp ✅"
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -72,15 +72,16 @@ type MuxOptions struct {
|
||||
}
|
||||
|
||||
type WarpOptions struct {
|
||||
EnableWarp bool `json:"enable"`
|
||||
Mode string `json:"mode"`
|
||||
WireguardConfig WarpWireguardConfig `json:"wireguard-config"`
|
||||
FakePackets string `json:"fake-packets"`
|
||||
FakePacketSize string `json:"fake-packet-size"`
|
||||
FakePacketDelay string `json:"fake-packet-delay"`
|
||||
CleanIP string `json:"clean-ip"`
|
||||
CleanPort uint16 `json:"clean-port"`
|
||||
Account WarpAccount
|
||||
EnableWarp bool `json:"enable"`
|
||||
Mode string `json:"mode"`
|
||||
WireguardConfigStr string `json:"wireguardConfig"`
|
||||
WireguardConfig WarpWireguardConfig `json:"wireguard-config"`
|
||||
FakePackets string `json:"warpNoise"`
|
||||
FakePacketSize string `json:"fake-packet-size"`
|
||||
FakePacketDelay string `json:"warpNoiseDelay"`
|
||||
CleanIP string `json:"cleanIp"`
|
||||
CleanPort uint16 `json:"cleanPort"`
|
||||
Account WarpAccount
|
||||
}
|
||||
|
||||
func DefaultConfigOptions() *ConfigOptions {
|
||||
|
||||
@@ -85,6 +85,13 @@ func changeConfigOptions(configOptionsJson *C.char) (CErr *C.char) {
|
||||
if err != nil {
|
||||
return C.CString(err.Error())
|
||||
}
|
||||
if configOptions.Warp.WireguardConfigStr != "" {
|
||||
err := json.Unmarshal([]byte(configOptions.Warp.WireguardConfigStr), &configOptions.Warp.WireguardConfig)
|
||||
if err != nil {
|
||||
return C.CString(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return C.CString("")
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,13 @@ func changeConfigOptions(configOptionsJson string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if configOptions.Warp.WireguardConfigStr != "" {
|
||||
err := json.Unmarshal([]byte(configOptions.Warp.WireguardConfigStr), &configOptions.Warp.WireguardConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@@ -105,7 +105,7 @@ require (
|
||||
lukechampine.com/blake3 v1.2.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.6-0.20240221131435-1f6e9d56ebd8
|
||||
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.6-0.20240221142438-1b8e9df9d3f6
|
||||
|
||||
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240220184421-1831c84ddbf9
|
||||
|
||||
|
||||
4
go.sum
4
go.sum
@@ -53,8 +53,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
|
||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240220074702-29dc5459810f h1:h9Vsu3eALcx5il3kYVTTZ/la6znEXLrBMJtkRWuUZ+M=
|
||||
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240220074702-29dc5459810f/go.mod h1:E1qZQpw2IrbRtFpTloTHGfJ2bJc4ZpZRNS497Eq5jCo=
|
||||
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240221131435-1f6e9d56ebd8 h1:6E2QU3kukvQBDg8TXKb1Qkw4xGH1MeejFa4UfOokwho=
|
||||
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240221131435-1f6e9d56ebd8/go.mod h1:/Pfh8KgxbWEg5s5rmXjRc6NWW0W4zcIDLDSpnC43snc=
|
||||
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240221142438-1b8e9df9d3f6 h1:WYDFYkj04TaW/vgs90eu8IXGgfFOPrjXZ3HpQwTBjxI=
|
||||
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240221142438-1b8e9df9d3f6/go.mod h1:/Pfh8KgxbWEg5s5rmXjRc6NWW0W4zcIDLDSpnC43snc=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a h1:ObxmZ8AyhIxtH2Vu+vmDAsxsbsTPGq9pJzcY0V+3BCU=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||
github.com/hiddify/wireguard-go v0.0.0-20240220184421-1831c84ddbf9 h1:pdb/3VPsfJPBEXaY046ISWYS4yevzzZ4rSjyOsCKy8I=
|
||||
|
||||
@@ -34,6 +34,12 @@ func BuildConfig(path string, configOptionsJson string) (string, error) {
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
if configOptions.Warp.WireguardConfigStr != "" {
|
||||
err := json.Unmarshal([]byte(configOptions.Warp.WireguardConfigStr), &configOptions.Warp.WireguardConfig)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return config.BuildConfigJson(*configOptions, options)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user