diff --git a/cmd/cmd_warp.go b/cmd/cmd_warp.go index e300300..df10be3 100644 --- a/cmd/cmd_warp.go +++ b/cmd/cmd_warp.go @@ -115,7 +115,7 @@ func generateWarp() (*T.Outbound, error) { _, _, wg, err := config.GenerateWarpInfo("", "", "") // fmt.Printf("%v", wgConfig) - singboxConfig, err := config.GenerateWarpSingbox(*wg, "", 0, "", "", "") + singboxConfig, err := config.GenerateWarpSingbox(*wg, "", 0, "", "", "", "") singboxJSON, err := json.MarshalIndent(singboxConfig, "", " ") if err != nil { fmt.Println("Error marshaling Singbox configuration:", err) diff --git a/config/config.go b/config/config.go index bdab0f3..deea94d 100644 --- a/config/config.go +++ b/config/config.go @@ -535,7 +535,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro } } if opt.Warp.EnableWarp && (opt.Warp.Mode == "warp_over_proxy" || opt.Warp.Mode == "proxy_over_warp") { - out, err := GenerateWarpSingbox(opt.Warp.WireguardConfig, opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay) + out, err := GenerateWarpSingbox(opt.Warp.WireguardConfig, opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay, opt.Warp.FakePacketMode) if err != nil { return nil, fmt.Errorf("failed to generate warp config: %v", err) } @@ -546,12 +546,12 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro } else { out.WireGuardOptions.Detour = OutboundDirectTag } - patchWarp(out, &opt, true) + patchWarp(out, &opt, true,nil) outbounds = append(outbounds, *out) // tags = append(tags, out.Tag) } for _, out := range input.Outbounds { - outbound, serverDomain, err := patchOutbound(out, opt) + outbound, serverDomain, err := patchOutbound(out, opt, options.DNS.StaticIPs) if err != nil { return nil, err } diff --git a/config/option.go b/config/option.go index 6bda618..76fdb41 100644 --- a/config/option.go +++ b/config/option.go @@ -83,8 +83,9 @@ type WarpOptions struct { WireguardConfigStr string `json:"wireguard-config"` WireguardConfig WarpWireguardConfig `json:"wireguardConfig"` // TODO check FakePackets string `json:"noise"` - FakePacketSize string `json:"fake-packet-size"` + FakePacketSize string `json:"noise-size"` FakePacketDelay string `json:"noise-delay"` + FakePacketMode string `json:"noise-mode"` CleanIP string `json:"clean-ip"` CleanPort uint16 `json:"clean-port"` Account WarpAccount diff --git a/config/outbound.go b/config/outbound.go index 80522c0..c6166e9 100644 --- a/config/outbound.go +++ b/config/outbound.go @@ -117,12 +117,12 @@ func isOutboundReality(base option.Outbound) bool { } -func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbound, string, error) { +func patchOutbound(base option.Outbound, configOpt ConfigOptions, staticIpsDns map[string][]string) (*option.Outbound, string, error) { formatErr := func(err error) error { return fmt.Errorf("error patching outbound[%s][%s]: %w", base.Tag, base.Type, err) } - err := patchWarp(&base, &configOpt, true) + err := patchWarp(&base, &configOpt, true, staticIpsDns) if err != nil { return nil, "", formatErr(err) } diff --git a/config/parser.go b/config/parser.go index 47b2621..292c072 100644 --- a/config/parser.go +++ b/config/parser.go @@ -95,7 +95,7 @@ func patchConfig(content []byte, name string, configOpt *ConfigOptions) ([]byte, for _, base := range options.Outbounds { out := base b.Go(base.Tag, func() (*option.Outbound, error) { - err := patchWarp(&out, configOpt, false) + err := patchWarp(&out, configOpt, false, nil) if err != nil { return nil, fmt.Errorf("[Warp] patch warp error: %w", err) } diff --git a/config/warp.go b/config/warp.go index 411d1eb..d83962a 100644 --- a/config/warp.go +++ b/config/warp.go @@ -73,7 +73,7 @@ func getRandomIP() string { return "engage.cloudflareclient.com" } -func generateWarp(license string, host string, port uint16, fakePackets string, fakePacketsSize string, fakePacketsDelay string) (*T.Outbound, error) { +func generateWarp(license string, host string, port uint16, fakePackets string, fakePacketsSize string, fakePacketsDelay string, fakePacketsMode string) (*T.Outbound, error) { _, _, wgConfig, err := GenerateWarpInfo(license, "", "") if err != nil { @@ -83,15 +83,15 @@ func generateWarp(license string, host string, port uint16, fakePackets string, return nil, fmt.Errorf("invalid warp config") } - return GenerateWarpSingbox(*wgConfig, host, port, fakePackets, fakePacketsSize, fakePacketsDelay) + return GenerateWarpSingbox(*wgConfig, host, port, fakePackets, fakePacketsSize, fakePacketsDelay, fakePacketsMode) } -func GenerateWarpSingbox(wgConfig WarpWireguardConfig, host string, port uint16, fakePackets string, fakePacketsSize string, fakePacketsDelay string) (*T.Outbound, error) { +func GenerateWarpSingbox(wgConfig WarpWireguardConfig, host string, port uint16, fakePackets string, fakePacketsSize string, fakePacketsDelay string, fakePacketMode string) (*T.Outbound, error) { if host == "" { - host = "auto" + host = "auto4" } - if host == "auto" && fakePackets == "" { + if (host == "auto" || host == "auto4" || host == "auto6") && fakePackets == "" { fakePackets = "1-3" } if fakePackets != "" && fakePacketsSize == "" { @@ -109,6 +109,7 @@ func GenerateWarpSingbox(wgConfig WarpWireguardConfig, host string, port uint16, singboxConfig.WireGuardOptions.FakePackets = fakePackets singboxConfig.WireGuardOptions.FakePacketsSize = fakePacketsSize singboxConfig.WireGuardOptions.FakePacketsDelay = fakePacketsDelay + singboxConfig.WireGuardOptions.FakePacketsMode = fakePacketMode return singboxConfig, nil } @@ -143,7 +144,7 @@ func GenerateWarpInfo(license string, oldAccountId string, oldAccessToken string } -func patchWarp(base *option.Outbound, configOpt *ConfigOptions, final bool) error { +func patchWarp(base *option.Outbound, configOpt *ConfigOptions, final bool, staticIpsDns map[string][]string) error { if base.Type == C.TypeCustom { if warp, ok := base.CustomOptions["warp"].(map[string]interface{}); ok { key, _ := warp["key"].(string) @@ -153,6 +154,7 @@ func patchWarp(base *option.Outbound, configOpt *ConfigOptions, final bool) erro fakePackets, _ := warp["fake_packets"].(string) fakePacketsSize, _ := warp["fake_packets_size"].(string) fakePacketsDelay, _ := warp["fake_packets_delay"].(string) + fakePacketsMode, _ := warp["fake_packets_mode"].(string) var warpConfig *T.Outbound var err error @@ -160,11 +162,11 @@ func patchWarp(base *option.Outbound, configOpt *ConfigOptions, final bool) erro warpConfig = base return nil } else if key == "p1" { - warpConfig, err = GenerateWarpSingbox(configOpt.Warp.WireguardConfig, host, port, fakePackets, fakePacketsSize, fakePacketsDelay) + warpConfig, err = GenerateWarpSingbox(configOpt.Warp.WireguardConfig, host, port, fakePackets, fakePacketsSize, fakePacketsDelay, fakePacketsMode) } else if key == "p2" { - warpConfig, err = GenerateWarpSingbox(configOpt.Warp2.WireguardConfig, host, port, fakePackets, fakePacketsSize, fakePacketsDelay) + warpConfig, err = GenerateWarpSingbox(configOpt.Warp2.WireguardConfig, host, port, fakePackets, fakePacketsSize, fakePacketsDelay, fakePacketsMode) } else { - warpConfig, err = generateWarp(key, host, uint16(port), fakePackets, fakePacketsSize, fakePacketsDelay) + warpConfig, err = generateWarp(key, host, uint16(port), fakePackets, fakePacketsSize, fakePacketsDelay, fakePacketsMode) } if err != nil { fmt.Printf("Error generating warp config: %v", err) @@ -183,12 +185,21 @@ func patchWarp(base *option.Outbound, configOpt *ConfigOptions, final bool) erro if final && base.Type == C.TypeWireGuard { host := base.WireGuardOptions.Server - if host == "default" || host == "random" || host == "auto" || isBlockedDomain(host) { + if host == "default" || host == "random" || host == "auto" || host == "auto4" || host == "auto6" || isBlockedDomain(host) { if base.WireGuardOptions.Detour != "" { base.WireGuardOptions.Server = "162.159.192.1" } else { - randomIpPort, _ := warp.RandomWarpEndpoint(true, false) - base.WireGuardOptions.Server = randomIpPort.Addr().String() + rndDomain := generateRandomString(20) + staticIpsDns[rndDomain] = []string{} + if host != "auto4" { + randomIpPort, _ := warp.RandomWarpEndpoint(false, true) + staticIpsDns[rndDomain] = append(staticIpsDns[rndDomain], randomIpPort.Addr().String()) + } + if host != "auto6" { + randomIpPort, _ := warp.RandomWarpEndpoint(true, false) + staticIpsDns[rndDomain] = append(staticIpsDns[rndDomain], randomIpPort.Addr().String()) + } + base.WireGuardOptions.Server = rndDomain } } diff --git a/go.mod b/go.mod index c905a8d..845e889 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.22.3 require ( github.com/bepass-org/warp-plus v0.0.0-00010101000000-000000000000 github.com/golang/protobuf v1.5.4 - github.com/hiddify/ray2sing v0.0.0-20240709163254-0b78d4fa3a42 + github.com/hiddify/ray2sing v0.0.0-20240717205915-5b3735b9a990 github.com/kardianos/service v1.2.2 github.com/macronut/godivert v0.0.0-20220121081532-78e5dd672daf github.com/sagernet/gomobile v0.1.3 @@ -25,6 +25,7 @@ require ( require ( berty.tech/go-libtor v1.0.385 // indirect github.com/ajg/form v1.5.1 // indirect + github.com/akavel/rsrc v0.10.2 // indirect github.com/andybalholm/brotli v1.0.6 // indirect github.com/caddyserver/certmagic v0.20.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect @@ -108,8 +109,8 @@ require ( lukechampine.com/blake3 v1.2.1 // indirect ) -replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20240712192523-0af1865bbfe4 +replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20240717205631-60d55deb81f9 -replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240712191632-973cb66a43af +replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240717205116-b0de5e908866 -replace github.com/bepass-org/warp-plus => github.com/hiddify/warp-plus v0.0.0-20240529120935-6c534fdb70b1 +replace github.com/bepass-org/warp-plus => github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d diff --git a/go.sum b/go.sum index f3bf31a..829f668 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ berty.tech/go-libtor v1.0.385 h1:RWK94C3hZj6Z2GdvePpHJLnWYobFr3bY/OdUJ5aoEXw= berty.tech/go-libtor v1.0.385/go.mod h1:9swOOQVb+kmvuAlsgWUK/4c52pm69AdbJsxLzk+fJEw= github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw= +github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI= github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/caddyserver/certmagic v0.20.0 h1:bTw7LcEZAh9ucYCRXyCpIrSAGplplI0vGYJ4BpCQ/Fc= @@ -47,14 +49,14 @@ github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5X github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= 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/hiddify-sing-box v1.8.9-0.20240712192523-0af1865bbfe4 h1:67FjOjXloOYF5t/Qv6+WddUTnCoc+xLyBFT8fQ076nU= -github.com/hiddify/hiddify-sing-box v1.8.9-0.20240712192523-0af1865bbfe4/go.mod h1:t823vUhhPf1wkdIgjoytxGjtDlCDAqq+0M+yhKw8Nrg= -github.com/hiddify/ray2sing v0.0.0-20240709163254-0b78d4fa3a42 h1:JPogyii1LwjhWS6lNEhfa24b+fFqlj9miH/glYeHNrM= -github.com/hiddify/ray2sing v0.0.0-20240709163254-0b78d4fa3a42/go.mod h1:UYYahiWAtp1PfWAnhZQv+GyYSLms5/foB63q3ACYryE= -github.com/hiddify/warp-plus v0.0.0-20240529120935-6c534fdb70b1 h1:QUaQZYHtWfrfoJxdT3MpQkNGbRM11pb4QsGTzJycVQ4= -github.com/hiddify/warp-plus v0.0.0-20240529120935-6c534fdb70b1/go.mod h1:uSRUbr1CcvFrEV69FTvuJFwpzEmwO8N4knb6+Zq3Ys4= -github.com/hiddify/wireguard-go v0.0.0-20240712191632-973cb66a43af h1:ebo07veHL6CqHDkNipNC2rsjrYLx9WEBk2XNGGLRbhc= -github.com/hiddify/wireguard-go v0.0.0-20240712191632-973cb66a43af/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc= +github.com/hiddify/hiddify-sing-box v1.8.9-0.20240717205631-60d55deb81f9 h1:01JjBBilkGSza9eEVRN6XK7JDABbeDWgbYQN+/6j+tc= +github.com/hiddify/hiddify-sing-box v1.8.9-0.20240717205631-60d55deb81f9/go.mod h1:AlbX8EFeSVKjitRnpX2Zv6oD3IGhOFXiPq+4P71Io54= +github.com/hiddify/ray2sing v0.0.0-20240717205915-5b3735b9a990 h1:d6nzEmzMz+82DlpQF2DXJEEwGjiaCPKkq3cY2YlSQ70= +github.com/hiddify/ray2sing v0.0.0-20240717205915-5b3735b9a990/go.mod h1:oeBG6Bm4iR7S89rd/yZ2kFVnp9TYKZMVX/OO+L+EIuA= +github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d h1:vRGKh9ou+/vQGfVYa8MczhbIVjHxlP52OWwrDWO77RA= +github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d/go.mod h1:uSRUbr1CcvFrEV69FTvuJFwpzEmwO8N4knb6+Zq3Ys4= +github.com/hiddify/wireguard-go v0.0.0-20240717205116-b0de5e908866 h1:VhAIBUXPHpO1VWiNUJ97PmfHm6iuuuijf9SSPyZ2xu4= +github.com/hiddify/wireguard-go v0.0.0-20240717205116-b0de5e908866/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc= github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b h1:1+115FqGoS8p6Iry9AYmrcWDvSveH0F7P2nX1LU00qg= github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b/go.mod h1:XCscqBi1KKh7GcVDDAdkT/Cf6WDjnDAA1XM3nwmA0Ag= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=