new: configurable warp noise parameters, fix stopping issues
This commit is contained in:
@@ -12,7 +12,7 @@ go version go1.21.1 darwin/arm64
|
|||||||
|
|
||||||
> if you're not interested in building/contributing to the Go code, you can skip this section
|
> if you're not interested in building/contributing to the Go code, you can skip this section
|
||||||
|
|
||||||
The Go code for Hiddify Next can be found in the `libcore` folder, as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) and in [core repository](https://github.com/hiddify/hiddify-next-core). The entrypoints for the desktop version are available in the [`libcore/custom`](https://github.com/hiddify/hiddify-next-core/tree/main/custom) folder and for the mobile version they can be found in the [`libcore/mobile`](https://github.com/hiddify/hiddify-next-core/tree/main/mobile) folder.
|
The Go code for Hiddify can be found in the `libcore` folder, as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) and in [core repository](https://github.com/hiddify/hiddify-next-core). The entrypoints for the desktop version are available in the [`libcore/custom`](https://github.com/hiddify/hiddify-next-core/tree/main/custom) folder and for the mobile version they can be found in the [`libcore/mobile`](https://github.com/hiddify/hiddify-next-core/tree/main/mobile) folder.
|
||||||
|
|
||||||
For the desktop version, we have to compile the Go code into a C shared library. We are providing a Makefile to generate the C shared libraries for all operating systems. The following Make commands will build libcore and copy the resulting output in [`libcore/bin`](https://github.com/hiddify/hiddify-next-core/tree/main/bin):
|
For the desktop version, we have to compile the Go code into a C shared library. We are providing a Makefile to generate the C shared libraries for all operating systems. The following Make commands will build libcore and copy the resulting output in [`libcore/bin`](https://github.com/hiddify/hiddify-next-core/tree/main/bin):
|
||||||
|
|
||||||
|
|||||||
@@ -182,7 +182,9 @@ func patchWarp(base *option.Outbound) error {
|
|||||||
port, _ := warp["port"].(float64)
|
port, _ := warp["port"].(float64)
|
||||||
detour, _ := warp["detour"].(string)
|
detour, _ := warp["detour"].(string)
|
||||||
fakePackets, _ := warp["fake_packets"].(string)
|
fakePackets, _ := warp["fake_packets"].(string)
|
||||||
warpConfig, err := generateWarp(key, host, uint16(port), fakePackets)
|
fakePacketsSize, _ := warp["fake_packets_size"].(string)
|
||||||
|
fakePacketsDelay, _ := warp["fake_packets_delay"].(string)
|
||||||
|
warpConfig, err := generateWarp(key, host, uint16(port), fakePackets, fakePacketsSize, fakePacketsDelay)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error generating warp config: %v", err)
|
fmt.Printf("Error generating warp config: %v", err)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ func generateRandomPort() uint16 {
|
|||||||
return warpPorts[rand.Intn(len(warpPorts))]
|
return warpPorts[rand.Intn(len(warpPorts))]
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateWarp(license string, host string, port uint16, fakePackets string) (*T.Outbound, error) {
|
func generateWarp(license string, host string, port uint16, fakePackets string, fakePacketsSize string, fakePacketsDelay string) (*T.Outbound, error) {
|
||||||
if host == "" || isBlockedDomain(host) {
|
if host == "" || isBlockedDomain(host) {
|
||||||
host = "auto"
|
host = "auto"
|
||||||
}
|
}
|
||||||
@@ -163,6 +163,13 @@ func generateWarp(license string, host string, port uint16, fakePackets string)
|
|||||||
if host == "auto" && fakePackets == "" {
|
if host == "auto" && fakePackets == "" {
|
||||||
fakePackets = "8-15"
|
fakePackets = "8-15"
|
||||||
}
|
}
|
||||||
|
if fakePackets != "" && fakePacketsSize == "" {
|
||||||
|
fakePacketsSize = "40-100"
|
||||||
|
}
|
||||||
|
if fakePackets != "" && fakePacketsDelay == "" {
|
||||||
|
fakePacketsDelay = "200-500"
|
||||||
|
}
|
||||||
|
|
||||||
// warp.UpdatePath("./secondary")
|
// warp.UpdatePath("./secondary")
|
||||||
if _, err := os.Stat("./wgcf-identity.json"); err == nil {
|
if _, err := os.Stat("./wgcf-identity.json"); err == nil {
|
||||||
os.Remove("./wgcf-identity.json")
|
os.Remove("./wgcf-identity.json")
|
||||||
@@ -185,6 +192,8 @@ func generateWarp(license string, host string, port uint16, fakePackets string)
|
|||||||
singboxConfig, err := wireGuardToSingbox(wgConfig, host, port)
|
singboxConfig, err := wireGuardToSingbox(wgConfig, host, port)
|
||||||
|
|
||||||
singboxConfig.WireGuardOptions.FakePackets = fakePackets
|
singboxConfig.WireGuardOptions.FakePackets = fakePackets
|
||||||
|
singboxConfig.WireGuardOptions.FakePacketsSize = fakePacketsSize
|
||||||
|
singboxConfig.WireGuardOptions.FakePacketsDelay = fakePacketsDelay
|
||||||
singboxJSON, err := json.MarshalIndent(singboxConfig, "", " ")
|
singboxJSON, err := json.MarshalIndent(singboxConfig, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error marshaling Singbox configuration:", err)
|
fmt.Println("Error marshaling Singbox configuration:", err)
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ func generateConfigFromFile(path string, configOpt config.ConfigOptions) (string
|
|||||||
//export start
|
//export start
|
||||||
func start(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
|
func start(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
|
||||||
defer config.DeferPanicToError("start", func(err error) {
|
defer config.DeferPanicToError("start", func(err error) {
|
||||||
CErr = C.CString(err.Error())
|
|
||||||
stopAndAlert("Unexpected Error!", err)
|
stopAndAlert("Unexpected Error!", err)
|
||||||
|
CErr = C.CString(err.Error())
|
||||||
})
|
})
|
||||||
|
|
||||||
if status != Stopped {
|
if status != Stopped {
|
||||||
@@ -187,40 +187,41 @@ func startService(delayStart bool) error {
|
|||||||
//export stop
|
//export stop
|
||||||
func stop() (CErr *C.char) {
|
func stop() (CErr *C.char) {
|
||||||
defer config.DeferPanicToError("stop", func(err error) {
|
defer config.DeferPanicToError("stop", func(err error) {
|
||||||
|
stopAndAlert("Unexpected Error in Stop!", err)
|
||||||
CErr = C.CString(err.Error())
|
CErr = C.CString(err.Error())
|
||||||
})
|
})
|
||||||
config.DeactivateTunnelService()
|
config.DeactivateTunnelService()
|
||||||
|
|
||||||
if status != Started {
|
if status != Started {
|
||||||
|
stopAndAlert("Already Stopped", nil)
|
||||||
return C.CString("")
|
return C.CString("")
|
||||||
}
|
}
|
||||||
if box == nil {
|
if box == nil {
|
||||||
return C.CString("instance not found")
|
return C.CString("instance not found")
|
||||||
}
|
}
|
||||||
propagateStatus(Stopping)
|
propagateStatus(Stopping)
|
||||||
|
|
||||||
commandServer.SetService(nil)
|
commandServer.SetService(nil)
|
||||||
|
|
||||||
err := box.Close()
|
err := box.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
stopAndAlert("Unexpected Error in Close!", err)
|
||||||
return C.CString(err.Error())
|
return C.CString(err.Error())
|
||||||
}
|
}
|
||||||
box = nil
|
box = nil
|
||||||
|
|
||||||
err = commandServer.Close()
|
err = commandServer.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
stopAndAlert("Unexpected Error in Stop CommandServer/!", err)
|
||||||
return C.CString(err.Error())
|
return C.CString(err.Error())
|
||||||
}
|
}
|
||||||
commandServer = nil
|
commandServer = nil
|
||||||
propagateStatus(Stopped)
|
propagateStatus(Stopped)
|
||||||
|
|
||||||
return C.CString("")
|
return C.CString("")
|
||||||
}
|
}
|
||||||
|
|
||||||
//export restart
|
//export restart
|
||||||
func restart(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
|
func restart(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
|
||||||
defer config.DeferPanicToError("restart", func(err error) {
|
defer config.DeferPanicToError("restart", func(err error) {
|
||||||
CErr = C.CString(err.Error())
|
|
||||||
stopAndAlert("Unexpected Error!", err)
|
stopAndAlert("Unexpected Error!", err)
|
||||||
|
CErr = C.CString(err.Error())
|
||||||
})
|
})
|
||||||
log.Debug("[Service] Restarting")
|
log.Debug("[Service] Restarting")
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,15 @@ func stopAndAlert(alert string, err error) (resultErr error) {
|
|||||||
fmt.Printf("Error: %s: %v\n", alert, err)
|
fmt.Printf("Error: %s: %v\n", alert, err)
|
||||||
propagateStatus(Stopped)
|
propagateStatus(Stopped)
|
||||||
config.DeactivateTunnelService()
|
config.DeactivateTunnelService()
|
||||||
commandServer.SetService(nil)
|
if commandServer != nil {
|
||||||
err = box.Close()
|
commandServer.SetService(nil)
|
||||||
|
}
|
||||||
|
if box != nil {
|
||||||
|
box.Close()
|
||||||
|
box = nil
|
||||||
|
}
|
||||||
|
if commandServer != nil {
|
||||||
|
commandServer.Close()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
6
go.mod
6
go.mod
@@ -4,7 +4,7 @@ go 1.21.5
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bepass-org/wireguard-go v0.0.16-alpha
|
github.com/bepass-org/wireguard-go v0.0.16-alpha
|
||||||
github.com/hiddify/ray2sing v0.0.0-20240130210008-8975ff77e3cd
|
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a
|
||||||
github.com/kardianos/service v1.2.2
|
github.com/kardianos/service v1.2.2
|
||||||
github.com/sagernet/gomobile v0.1.1
|
github.com/sagernet/gomobile v0.1.1
|
||||||
github.com/sagernet/sing v0.3.0
|
github.com/sagernet/sing v0.3.0
|
||||||
@@ -105,8 +105,8 @@ require (
|
|||||||
lukechampine.com/blake3 v1.2.1 // indirect
|
lukechampine.com/blake3 v1.2.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.6-0.20240213024345-1fb57d3690bd
|
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.6-0.20240213125057-2ddd095a1429
|
||||||
|
|
||||||
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240213020321-89576b161250
|
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240213142816-f6785b165244
|
||||||
|
|
||||||
replace github.com/bepass-org/wireguard-go => github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240212065415-62301f758cb7
|
replace github.com/bepass-org/wireguard-go => github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240212065415-62301f758cb7
|
||||||
|
|||||||
12
go.sum
12
go.sum
@@ -53,12 +53,12 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
|
|||||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||||
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240212065415-62301f758cb7 h1:RTlGYawrP2Ir2ADQmLS7+OmRShmk1qPm69ufArXvsqI=
|
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240212065415-62301f758cb7 h1:RTlGYawrP2Ir2ADQmLS7+OmRShmk1qPm69ufArXvsqI=
|
||||||
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240212065415-62301f758cb7/go.mod h1:/ny1FvyrV7/QPClexDyYCEFQfTQn7dD/+1DfedBSwuY=
|
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240212065415-62301f758cb7/go.mod h1:/ny1FvyrV7/QPClexDyYCEFQfTQn7dD/+1DfedBSwuY=
|
||||||
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240213024345-1fb57d3690bd h1:F87K1GtyOOqX6Lsru+5CkUVwEuaOehN+ls4GC4RcL+k=
|
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240213125057-2ddd095a1429 h1:qv+xj+Fd41r3WZdqNzdd95rIsv2Pf2Z7LNSWWqRLEqk=
|
||||||
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240213024345-1fb57d3690bd/go.mod h1:OQ0aCM3q+9mBaVr3yQx2cWvPR1pKZjaBcI24Y82Papw=
|
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240213125057-2ddd095a1429/go.mod h1:AnP54TD0EMNONIlc3uTWYT7K3PapAwalglF9TuKRiWE=
|
||||||
github.com/hiddify/ray2sing v0.0.0-20240130210008-8975ff77e3cd h1:3fKPvAWXTMGY0Qsk6wjCamIeC4xbrOUShMY95G5AZN4=
|
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a h1:ObxmZ8AyhIxtH2Vu+vmDAsxsbsTPGq9pJzcY0V+3BCU=
|
||||||
github.com/hiddify/ray2sing v0.0.0-20240130210008-8975ff77e3cd/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||||
github.com/hiddify/wireguard-go v0.0.0-20240213020321-89576b161250 h1:mgIWgJSmGFfxYwcHPBcHel11zuBc5nQqTD4Zg1GBbH4=
|
github.com/hiddify/wireguard-go v0.0.0-20240213142816-f6785b165244 h1:R/IVg5a0FOGT/85HFj81Fn3oGXPFA5RfMHyHngkLDGk=
|
||||||
github.com/hiddify/wireguard-go v0.0.0-20240213020321-89576b161250/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
|
github.com/hiddify/wireguard-go v0.0.0-20240213142816-f6785b165244/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 h1:1+115FqGoS8p6Iry9AYmrcWDvSveH0F7P2nX1LU00qg=
|
||||||
github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b/go.mod h1:XCscqBi1KKh7GcVDDAdkT/Cf6WDjnDAA1XM3nwmA0Ag=
|
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=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
|||||||
Reference in New Issue
Block a user