new: add auto warp
This commit is contained in:
@@ -147,10 +147,9 @@ func parsePeerConfig(peerConfig *PeerConfig, line string) {
|
||||
}
|
||||
func generateWarp() *T.Outbound {
|
||||
license := ""
|
||||
endpoint := "engage.cloudflareclient.com:2408"
|
||||
|
||||
if !warp.CheckProfileExists(license) {
|
||||
warp.LoadOrCreateIdentity(license, endpoint)
|
||||
warp.LoadOrCreateIdentity(license)
|
||||
}
|
||||
|
||||
wgConfig, err := readWireGuardConfig("wgcf-profile.ini")
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/hiddify/libcore
|
||||
go 1.21.5
|
||||
|
||||
require (
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126122154-854054f22383
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126124612-8e00e77ec754
|
||||
github.com/sagernet/gomobile v0.1.1
|
||||
github.com/sagernet/sing v0.3.0
|
||||
github.com/sagernet/sing-box v1.8.2
|
||||
|
||||
4
go.sum
4
go.sum
@@ -51,8 +51,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/hiddify-sing-box v1.7.9-0.20240125210314-493067cd2d66 h1:1soOFv4mdCq9OiRN4eo4B0ylDY1EeSnl0M7szOTYNz4=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125210314-493067cd2d66/go.mod h1:DnlHl/vlinL9Mn95+qJ3RzgE3E/9pWlAvTsauo7F5HM=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126122154-854054f22383 h1:yFWzs/DLEXpcdXaVFFEQBHz2Q6XQ+j/IqXC/Qzm7dGw=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126122154-854054f22383/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126124612-8e00e77ec754 h1:OS1xPGAR34zQ2btXGa2ZVpI0nXQnkB6meI1hXkQvgJM=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240126124612-8e00e77ec754/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8=
|
||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
|
||||
Reference in New Issue
Block a user