Skip to content

Commit

Permalink
new: add auto warp
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jan 26, 2024
1 parent 65b4cb7 commit 3b4a128
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions cmd/cmd_warp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions config/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ 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
}

base.Type = C.TypeWireGuard
base.WireGuardOptions = warpConfig.WireGuardOptions
base.WireGuardOptions.FakePackets = fakePackets

}

Expand Down
12 changes: 7 additions & 5 deletions config/warp.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func getRandomIP() string {

ip, err := warp.RandomIPFromRange(randomRange)
if err == nil {
ip.String()
return ip.String()
}
return "engage.cloudflareclient.com"
}
Expand All @@ -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()
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 3b4a128

Please sign in to comment.