new: add auto warp

This commit is contained in:
Hiddify
2024-01-26 14:01:13 +01:00
parent 65b4cb706a
commit 3b4a128b58
5 changed files with 12 additions and 12 deletions

View File

@@ -148,7 +148,7 @@ func patchWarp(base *option.Outbound) error {
host, _ := warp["host"].(string)
port, _ := warp["port"].(float64)
fakePackets, _ := warp["fake_packets"].(string)
warpConfig, err := generateWarp(key, host, uint16(port))
warpConfig, err := generateWarp(key, host, uint16(port), fakePackets)
if err != nil {
fmt.Printf("Error generating warp config: %v", err)
return err
@@ -156,7 +156,6 @@ func patchWarp(base *option.Outbound) error {
base.Type = C.TypeWireGuard
base.WireGuardOptions = warpConfig.WireGuardOptions
base.WireGuardOptions.FakePackets = fakePackets
}

View File

@@ -146,7 +146,7 @@ func getRandomIP() string {
ip, err := warp.RandomIPFromRange(randomRange)
if err == nil {
ip.String()
return ip.String()
}
return "engage.cloudflareclient.com"
}
@@ -155,10 +155,13 @@ func generateRandomPort() uint16 {
return warpPorts[rand.Intn(len(warpPorts))]
}
func generateWarp(license string, host string, port uint16) (*T.Outbound, error) {
func generateWarp(license string, host string, port uint16, fakePackets string) (*T.Outbound, error) {
if host == "" {
host = "auto"
}
if host == "auto" && fakePackets == "" {
fakePackets = "5-10"
}
if host == "default" || host == "random" || host == "auto" {
host = getRandomIP()
}
@@ -181,9 +184,8 @@ func generateWarp(license string, host string, port uint16) (*T.Outbound, error)
}
// fmt.Printf("%v", wgConfig)
singboxConfig, err := wireGuardToSingbox(wgConfig, host, port)
if host == "auto" && singboxConfig.WireGuardOptions.FakePackets == "" {
singboxConfig.WireGuardOptions.FakePackets = "5-10"
}
singboxConfig.WireGuardOptions.FakePackets = fakePackets
singboxJSON, err := json.MarshalIndent(singboxConfig, "", " ")
if err != nil {
fmt.Println("Error marshaling Singbox configuration:", err)