fix: bugs and issues
This commit is contained in:
8
Makefile
8
Makefile
@@ -13,7 +13,7 @@ endif
|
|||||||
TAGS=with_gvisor,with_quic,with_wireguard,with_ech,with_utls,with_clash_api,with_grpc
|
TAGS=with_gvisor,with_quic,with_wireguard,with_ech,with_utls,with_clash_api,with_grpc
|
||||||
IOS_ADD_TAGS=with_dhcp,with_low_memory,with_conntrack
|
IOS_ADD_TAGS=with_dhcp,with_low_memory,with_conntrack
|
||||||
GOBUILDLIB=CGO_ENABLED=1 go build -trimpath -tags $(TAGS) -ldflags="-w -s" -buildmode=c-shared
|
GOBUILDLIB=CGO_ENABLED=1 go build -trimpath -tags $(TAGS) -ldflags="-w -s" -buildmode=c-shared
|
||||||
GOBUILDSRV=CGO_ENABLED=1 go build -trimpath
|
GOBUILDSRV=CGO_ENABLED=1 go build -trimpath -tags $(TAGS)
|
||||||
|
|
||||||
lib_install:
|
lib_install:
|
||||||
go install -v github.com/sagernet/gomobile/cmd/gomobile@v0.1.1
|
go install -v github.com/sagernet/gomobile/cmd/gomobile@v0.1.1
|
||||||
@@ -42,13 +42,13 @@ webui:
|
|||||||
rm -rf bin/webui
|
rm -rf bin/webui
|
||||||
mv Yacd-meta-gh-pages bin/webui
|
mv Yacd-meta-gh-pages bin/webui
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
windows-amd64:
|
windows-amd64:
|
||||||
curl http://localhost:18020/exit || echo "exited"
|
curl http://localhost:18020/exit || echo "exited"
|
||||||
env GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc $(GOBUILDLIB) -o $(BINDIR)/$(LIBNAME).dll ./custom
|
env GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc $(GOBUILDLIB) -o $(BINDIR)/$(LIBNAME).dll ./custom
|
||||||
go install -mod=readonly github.com/akavel/rsrc@latest
|
go install -mod=readonly github.com/akavel/rsrc@latest ||echo "rsrc error in installation"
|
||||||
cp $(BINDIR)/$(LIBNAME).dll ./$(LIBNAME).dll
|
cp $(BINDIR)/$(LIBNAME).dll ./$(LIBNAME).dll
|
||||||
$$(go env GOPATH)/bin/rsrc -ico ./assets/hiddify-cli.ico -o ./cli/bydll/cli.syso
|
$$(go env GOPATH)/bin/rsrc -ico ./assets/hiddify-cli.ico -o ./cli/bydll/cli.syso ||echo "rsrc error in syso"
|
||||||
env GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CGO_LDFLAGS="$(LIBNAME).dll" $(GOBUILDSRV) -o $(BINDIR)/$(CLINAME).exe ./cli/bydll
|
env GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CGO_LDFLAGS="$(LIBNAME).dll" $(GOBUILDSRV) -o $(BINDIR)/$(CLINAME).exe ./cli/bydll
|
||||||
rm ./$(LIBNAME).dll
|
rm ./$(LIBNAME).dll
|
||||||
make webui
|
make webui
|
||||||
|
|||||||
@@ -17,21 +17,18 @@ type hiddifyNext struct{}
|
|||||||
var port int = 18020
|
var port int = 18020
|
||||||
|
|
||||||
func (m *hiddifyNext) Start(s service.Service) error {
|
func (m *hiddifyNext) Start(s service.Service) error {
|
||||||
go m.run()
|
go StartWebServer(port, false)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (m *hiddifyNext) Stop(s service.Service) error {
|
func (m *hiddifyNext) Stop(s service.Service) error {
|
||||||
err := global.StopServiceC()
|
err := global.StopServiceC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
// Stop should not block. Return with a few seconds.
|
// Stop should not block. Return with a few seconds.
|
||||||
// <-time.After(time.Second * 1)
|
// <-time.After(time.Second * 1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (m *hiddifyNext) run() {
|
|
||||||
StartWebServer(port, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCurrentExecutableDirectory() string {
|
func getCurrentExecutableDirectory() string {
|
||||||
executablePath, err := os.Executable()
|
executablePath, err := os.Executable()
|
||||||
@@ -63,7 +60,7 @@ func StartService(goArg string) (int, string) {
|
|||||||
return 1, fmt.Sprintf("Error: %v", err)
|
return 1, fmt.Sprintf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(goArg) > 0 {
|
if len(goArg) > 0 && goArg != "run" {
|
||||||
return control(s, goArg)
|
return control(s, goArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +99,7 @@ func control(s service.Service, goArg string) (int, string) {
|
|||||||
}
|
}
|
||||||
return 0, "Tunnel Service Already Running."
|
return 0, "Tunnel Service Already Running."
|
||||||
} else if status == service.StatusUnknown {
|
} else if status == service.StatusUnknown {
|
||||||
|
s.Uninstall()
|
||||||
s.Install()
|
s.Install()
|
||||||
status, serr = s.Status()
|
status, serr = s.Status()
|
||||||
if dolog {
|
if dolog {
|
||||||
@@ -112,6 +110,7 @@ func control(s service.Service, goArg string) (int, string) {
|
|||||||
err = s.Start()
|
err = s.Start()
|
||||||
}
|
}
|
||||||
case "install":
|
case "install":
|
||||||
|
s.Uninstall()
|
||||||
err = s.Install()
|
err = s.Install()
|
||||||
status, serr = s.Status()
|
status, serr = s.Status()
|
||||||
if dolog {
|
if dolog {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const (
|
|||||||
func StartWebServer(Port int, TLS bool) {
|
func StartWebServer(Port int, TLS bool) {
|
||||||
http.HandleFunc("/start", startHandler)
|
http.HandleFunc("/start", startHandler)
|
||||||
http.HandleFunc("/stop", StopHandler)
|
http.HandleFunc("/stop", StopHandler)
|
||||||
|
http.HandleFunc("/status", StatusHandler)
|
||||||
http.HandleFunc("/exit", ExitHandler)
|
http.HandleFunc("/exit", ExitHandler)
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: "127.0.0.1:" + fmt.Sprintf("%d", Port),
|
Addr: "127.0.0.1:" + fmt.Sprintf("%d", Port),
|
||||||
@@ -85,6 +86,8 @@ func startHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
http.Error(w, fmt.Sprintf("Ok"), http.StatusOK)
|
http.Error(w, fmt.Sprintf("Ok"), http.StatusOK)
|
||||||
}
|
}
|
||||||
|
func StatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
}
|
||||||
func StopHandler(w http.ResponseWriter, r *http.Request) {
|
func StopHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
err := global.StopServiceC()
|
err := global.StopServiceC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
@@ -19,20 +20,11 @@ func ExecuteCmd(exe string, background bool, args ...string) (string, error) {
|
|||||||
verbPtr, _ := syscall.UTF16PtrFromString(verb)
|
verbPtr, _ := syscall.UTF16PtrFromString(verb)
|
||||||
exePtr, _ := syscall.UTF16PtrFromString(exe)
|
exePtr, _ := syscall.UTF16PtrFromString(exe)
|
||||||
cwdPtr, _ := syscall.UTF16PtrFromString(cwd)
|
cwdPtr, _ := syscall.UTF16PtrFromString(cwd)
|
||||||
|
argPtr, _ := syscall.UTF16PtrFromString(strings.Join(args, " "))
|
||||||
|
|
||||||
// Convert args to UTF16Ptr slice
|
var showCmd int32 = 0 // SW_NORMAL
|
||||||
var argsPtr []*uint16
|
|
||||||
for _, arg := range args {
|
|
||||||
argPtr, err := syscall.UTF16PtrFromString(arg)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
argsPtr = append(argsPtr, argPtr)
|
|
||||||
}
|
|
||||||
|
|
||||||
var showCmd int32 = 1 // SW_NORMAL
|
err = windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, showCmd)
|
||||||
|
|
||||||
err = windows.ShellExecute(0, verbPtr, exePtr, nil, cwdPtr, showCmd)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
dns "github.com/sagernet/sing-dns"
|
dns "github.com/sagernet/sing-dns"
|
||||||
@@ -21,15 +20,18 @@ const (
|
|||||||
stopEndpoint = "/stop"
|
stopEndpoint = "/stop"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var tunnelServiceRunning = false
|
||||||
|
|
||||||
func isSupportedOS() bool {
|
func isSupportedOS() bool {
|
||||||
return runtime.GOOS == "windows" || runtime.GOOS == "linux"
|
return runtime.GOOS == "windows" || runtime.GOOS == "linux"
|
||||||
}
|
}
|
||||||
func ActivateTunnelService(opt ConfigOptions) (bool, error) {
|
func ActivateTunnelService(opt ConfigOptions) (bool, error) {
|
||||||
|
tunnelServiceRunning = true
|
||||||
// if !isSupportedOS() {
|
// if !isSupportedOS() {
|
||||||
// return false, E.New("Unsupported OS: " + runtime.GOOS)
|
// return false, E.New("Unsupported OS: " + runtime.GOOS)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
go startTunnelRequest(opt, true)
|
go startTunnelRequestWithFailover(opt, true)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,11 +39,25 @@ func DeactivateTunnelService() (bool, error) {
|
|||||||
// if !isSupportedOS() {
|
// if !isSupportedOS() {
|
||||||
// return true, nil
|
// return true, nil
|
||||||
// }
|
// }
|
||||||
|
if tunnelServiceRunning {
|
||||||
|
stopTunnelRequest()
|
||||||
|
}
|
||||||
|
tunnelServiceRunning = false
|
||||||
|
|
||||||
go stopTunnelRequest()
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func startTunnelRequestWithFailover(opt ConfigOptions, installService bool) {
|
||||||
|
res, err := startTunnelRequest(opt, installService)
|
||||||
|
fmt.Printf("Start Tunnel Result: %v\n", res)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
fmt.Printf("Start Tunnel Failed! Stopping core... err=%v\n", err)
|
||||||
|
// StopAndAlert(pb.MessageType.MessageType_UNEXPECTED_ERROR, "Start Tunnel Failed! Stopping...")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func startTunnelRequest(opt ConfigOptions, installService bool) (bool, error) {
|
func startTunnelRequest(opt ConfigOptions, installService bool) (bool, error) {
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"Ipv6": opt.IPv6Mode == option.DomainStrategy(dns.DomainStrategyUseIPv4),
|
"Ipv6": opt.IPv6Mode == option.DomainStrategy(dns.DomainStrategyUseIPv4),
|
||||||
@@ -83,9 +99,9 @@ func stopTunnelRequest() (bool, error) {
|
|||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
body, err := io.ReadAll(response.Body)
|
body, err := io.ReadAll(response.Body)
|
||||||
fmt.Printf("Response Code: %d %s. Response Body: %s Error:%v\n", response.StatusCode, response.Status, body, err)
|
// fmt.Printf("Response Code: %d %s. Response Body: %s Error:%v\n", response.StatusCode, response.Status, body, err)
|
||||||
if err != nil || response.StatusCode != http.StatusOK {
|
if err != nil || response.StatusCode != http.StatusOK {
|
||||||
return false, fmt.Errorf("Unexpected Status Code: %d %s. Response Body: %s error:%v", response.StatusCode, response.Status, body, err)
|
return false, fmt.Errorf("unexpected Status Code: %d %s. Response Body: %s error:%v", response.StatusCode, response.Status, body, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|||||||
@@ -394,13 +394,16 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
|||||||
var outbounds []option.Outbound
|
var outbounds []option.Outbound
|
||||||
var tags []string
|
var tags []string
|
||||||
OutboundMainProxyTag = OutboundSelectTag
|
OutboundMainProxyTag = OutboundSelectTag
|
||||||
if opt.Warp.EnableWarp && (opt.Warp.Mode == WarpOverProxy || opt.Warp.Mode == ProxyOverWarp) {
|
//inbound==warp over proxies
|
||||||
|
//outbound==proxies over warp
|
||||||
|
if opt.Warp.EnableWarp && (opt.Warp.Mode == "inbound" || opt.Warp.Mode == "outbound") {
|
||||||
|
|
||||||
out, err := generateWarpSingbox(opt.Warp.WireguardConfig.ToWireguardConfig(), opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay)
|
out, err := generateWarpSingbox(opt.Warp.WireguardConfig.ToWireguardConfig(), opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to generate warp config: %v", err)
|
return nil, fmt.Errorf("failed to generate warp config: %v", err)
|
||||||
}
|
}
|
||||||
out.Tag = "Hiddify Warp ✅"
|
out.Tag = "Hiddify Warp ✅"
|
||||||
if opt.Warp.Mode == WarpOverProxy {
|
if opt.Warp.Mode == "inbound" {
|
||||||
out.WireGuardOptions.Detour = OutboundURLTestTag
|
out.WireGuardOptions.Detour = OutboundURLTestTag
|
||||||
OutboundMainProxyTag = out.Tag
|
OutboundMainProxyTag = out.Tag
|
||||||
} else {
|
} else {
|
||||||
@@ -531,7 +534,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
||||||
if opt.Warp.EnableWarp && opt.Warp.Mode == ProxyOverWarp {
|
if opt.Warp.EnableWarp && opt.Warp.Mode == "outbound" {
|
||||||
if out.DirectOptions.Detour == "" {
|
if out.DirectOptions.Detour == "" {
|
||||||
out.DirectOptions.Detour = "Hiddify Warp ✅"
|
out.DirectOptions.Detour = "Hiddify Warp ✅"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ type InboundOptions struct {
|
|||||||
LocalDnsPort uint16 `json:"local-dns-port"`
|
LocalDnsPort uint16 `json:"local-dns-port"`
|
||||||
MTU uint32 `json:"mtu"`
|
MTU uint32 `json:"mtu"`
|
||||||
StrictRoute bool `json:"strict-route"`
|
StrictRoute bool `json:"strict-route"`
|
||||||
TUNStack string `json:"tun-stack"`
|
TUNStack string `json:"tun-implementation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type URLTestOptions struct {
|
type URLTestOptions struct {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package main
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/hiddify/libcore/cmd"
|
"github.com/hiddify/libcore/cmd"
|
||||||
@@ -15,7 +14,7 @@ import (
|
|||||||
func parseCli(argc C.int, argv **C.char) *C.char {
|
func parseCli(argc C.int, argv **C.char) *C.char {
|
||||||
args := make([]string, argc)
|
args := make([]string, argc)
|
||||||
for i := 0; i < int(argc); i++ {
|
for i := 0; i < int(argc); i++ {
|
||||||
fmt.Println("parseCli", C.GoString(*argv))
|
// fmt.Println("parseCli", C.GoString(*argv))
|
||||||
args[i] = C.GoString(*argv)
|
args[i] = C.GoString(*argv)
|
||||||
argv = (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(argv)) + uintptr(unsafe.Sizeof(*argv))))
|
argv = (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(argv)) + uintptr(unsafe.Sizeof(*argv))))
|
||||||
}
|
}
|
||||||
@@ -23,5 +22,5 @@ func parseCli(argc C.int, argv **C.char) *C.char {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return C.CString(err.Error())
|
return C.CString(err.Error())
|
||||||
}
|
}
|
||||||
return C.CString("Ok")
|
return C.CString("")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func stop() (CErr *C.char) {
|
|||||||
stopAndAlert("Unexpected Error in Stop!", err)
|
stopAndAlert("Unexpected Error in Stop!", err)
|
||||||
CErr = C.CString(err.Error())
|
CErr = C.CString(err.Error())
|
||||||
})
|
})
|
||||||
config.DeactivateTunnelService()
|
|
||||||
if v2.CoreState != pb.CoreState_STARTED {
|
if v2.CoreState != pb.CoreState_STARTED {
|
||||||
stopAndAlert("Already Stopped", nil)
|
stopAndAlert("Already Stopped", nil)
|
||||||
return C.CString("")
|
return C.CString("")
|
||||||
@@ -209,6 +209,7 @@ func stop() (CErr *C.char) {
|
|||||||
return C.CString("instance not found")
|
return C.CString("instance not found")
|
||||||
}
|
}
|
||||||
propagateStatus(pb.CoreState_STOPPING)
|
propagateStatus(pb.CoreState_STOPPING)
|
||||||
|
config.DeactivateTunnelService()
|
||||||
commandServer.SetService(nil)
|
commandServer.SetService(nil)
|
||||||
|
|
||||||
err := v2.Box.Close()
|
err := v2.Box.Close()
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func stopAndAlert(alert string, err error) (resultErr error) {
|
|||||||
msg, _ := json.Marshal(StatusMessage{Status: convert2OldState(v2.CoreState), Alert: &alert, Message: &message})
|
msg, _ := json.Marshal(StatusMessage{Status: convert2OldState(v2.CoreState), Alert: &alert, Message: &message})
|
||||||
bridge.SendStringToPort(statusPropagationPort, string(msg))
|
bridge.SendStringToPort(statusPropagationPort, string(msg))
|
||||||
|
|
||||||
config.DeactivateTunnelService()
|
go config.DeactivateTunnelService()
|
||||||
if commandServer != nil {
|
if commandServer != nil {
|
||||||
commandServer.SetService(nil)
|
commandServer.SetService(nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ func stop() error {
|
|||||||
if box == nil {
|
if box == nil {
|
||||||
return errors.New("instance not found")
|
return errors.New("instance not found")
|
||||||
}
|
}
|
||||||
|
config.DeactivateTunnelService()
|
||||||
propagateStatus(Stopping)
|
propagateStatus(Stopping)
|
||||||
|
|
||||||
commandServer.SetService(nil)
|
commandServer.SetService(nil)
|
||||||
@@ -292,10 +293,10 @@ func StopServiceC() error {
|
|||||||
// if status != Started {
|
// if status != Started {
|
||||||
// return errors.New("instance not started")
|
// return errors.New("instance not started")
|
||||||
// }
|
// }
|
||||||
|
config.DeactivateTunnelService()
|
||||||
if box == nil {
|
if box == nil {
|
||||||
return errors.New("instance not found")
|
return errors.New("instance not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// propagateStatus(Stopping)
|
// propagateStatus(Stopping)
|
||||||
err := box.Close()
|
err := box.Close()
|
||||||
// commandServer.SetService(nil)
|
// commandServer.SetService(nil)
|
||||||
|
|||||||
@@ -18,6 +18,27 @@ import (
|
|||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func RunStandalone(hiddifySettingPath string, configPath string) error {
|
||||||
|
fmt.Println("Running in standalone mode")
|
||||||
|
current, err := readAndBuildConfig(hiddifySettingPath, configPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error in read and build config %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
go StartServiceC(false, current.Config)
|
||||||
|
go updateConfigInterval(current, hiddifySettingPath, configPath)
|
||||||
|
fmt.Printf("Press CTRL+C to stop\n")
|
||||||
|
fmt.Printf("Open http://localhost:6756/?secret=hiddify in your browser\n")
|
||||||
|
sigChan := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
|
<-sigChan
|
||||||
|
err = StopServiceC()
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
type ConfigResult struct {
|
type ConfigResult struct {
|
||||||
Config string
|
Config string
|
||||||
RefreshInterval int
|
RefreshInterval int
|
||||||
@@ -155,22 +176,6 @@ func updateConfigInterval(current ConfigResult, hiddifySettingPath string, confi
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
func RunStandalone(hiddifySettingPath string, configPath string) error {
|
|
||||||
current, err := readAndBuildConfig(hiddifySettingPath, configPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
go StartServiceC(false, current.Config)
|
|
||||||
go updateConfigInterval(current, hiddifySettingPath, configPath)
|
|
||||||
fmt.Printf("Press CTRL+C to stop\n")
|
|
||||||
fmt.Printf("Open http://localhost:6756/?secret=hiddify in your browser\n")
|
|
||||||
sigChan := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
|
||||||
|
|
||||||
<-sigChan
|
|
||||||
err = StopServiceC()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func readConfigBytes(content []byte) (*option.Options, error) {
|
func readConfigBytes(content []byte) (*option.Options, error) {
|
||||||
var options option.Options
|
var options option.Options
|
||||||
|
|||||||
12
v2/custom.go
12
v2/custom.go
@@ -19,7 +19,7 @@ var configOptions *config.ConfigOptions
|
|||||||
var activeConfigPath *string
|
var activeConfigPath *string
|
||||||
var logFactory *log.Factory
|
var logFactory *log.Factory
|
||||||
|
|
||||||
func stopAndAlert(msgType pb.MessageType, message string) {
|
func StopAndAlert(msgType pb.MessageType, message string) {
|
||||||
SetCoreStatus(pb.CoreState_STOPPED, msgType, message)
|
SetCoreStatus(pb.CoreState_STOPPED, msgType, message)
|
||||||
config.DeactivateTunnelService()
|
config.DeactivateTunnelService()
|
||||||
// if commandServer != nil {
|
// if commandServer != nil {
|
||||||
@@ -37,7 +37,7 @@ func stopAndAlert(msgType pb.MessageType, message string) {
|
|||||||
func (s *server) Start(ctx context.Context, in *pb.StartRequest) (*pb.CoreInfoResponse, error) {
|
func (s *server) Start(ctx context.Context, in *pb.StartRequest) (*pb.CoreInfoResponse, error) {
|
||||||
defer config.DeferPanicToError("start", func(err error) {
|
defer config.DeferPanicToError("start", func(err error) {
|
||||||
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
|
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
|
||||||
stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
StopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
||||||
})
|
})
|
||||||
|
|
||||||
if CoreState != pb.CoreState_STOPPED {
|
if CoreState != pb.CoreState_STOPPED {
|
||||||
@@ -112,7 +112,7 @@ func (s *server) StartService(ctx context.Context, in *pb.StartRequest) (*pb.Cor
|
|||||||
func (s *server) Parse(ctx context.Context, in *pb.ParseRequest) (*pb.ParseResponse, error) {
|
func (s *server) Parse(ctx context.Context, in *pb.ParseRequest) (*pb.ParseResponse, error) {
|
||||||
defer config.DeferPanicToError("parse", func(err error) {
|
defer config.DeferPanicToError("parse", func(err error) {
|
||||||
Log(pb.LogLevel_FATAL, pb.LogType_CONFIG, err.Error())
|
Log(pb.LogLevel_FATAL, pb.LogType_CONFIG, err.Error())
|
||||||
stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
StopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
||||||
})
|
})
|
||||||
|
|
||||||
config, err := config.ParseConfigContent(in.Content, true)
|
config, err := config.ParseConfigContent(in.Content, true)
|
||||||
@@ -137,7 +137,7 @@ func (s *server) Parse(ctx context.Context, in *pb.ParseRequest) (*pb.ParseRespo
|
|||||||
// func (s *server) GenerateConfig(ctx context.Context, in *pb.GenerateConfigRequest) (*pb.GenerateConfigResponse, error) {
|
// func (s *server) GenerateConfig(ctx context.Context, in *pb.GenerateConfigRequest) (*pb.GenerateConfigResponse, error) {
|
||||||
// defer config.DeferPanicToError("generateConfig", func(err error) {
|
// defer config.DeferPanicToError("generateConfig", func(err error) {
|
||||||
// Log(pb.LogLevel_FATAL, pb.LogType_CONFIG, err.Error())
|
// Log(pb.LogLevel_FATAL, pb.LogType_CONFIG, err.Error())
|
||||||
// stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
// StopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
||||||
// })
|
// })
|
||||||
|
|
||||||
// config, err := generateConfigFromFile(C.GoString(path), *configOptions)
|
// config, err := generateConfigFromFile(C.GoString(path), *configOptions)
|
||||||
@@ -151,7 +151,7 @@ func (s *server) Parse(ctx context.Context, in *pb.ParseRequest) (*pb.ParseRespo
|
|||||||
func (s *server) Stop(ctx context.Context, empty *pb.Empty) (*pb.CoreInfoResponse, error) {
|
func (s *server) Stop(ctx context.Context, empty *pb.Empty) (*pb.CoreInfoResponse, error) {
|
||||||
defer config.DeferPanicToError("stop", func(err error) {
|
defer config.DeferPanicToError("stop", func(err error) {
|
||||||
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
|
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
|
||||||
stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
StopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
||||||
})
|
})
|
||||||
config.DeactivateTunnelService()
|
config.DeactivateTunnelService()
|
||||||
if CoreState != pb.CoreState_STARTED {
|
if CoreState != pb.CoreState_STARTED {
|
||||||
@@ -199,7 +199,7 @@ func (s *server) Stop(ctx context.Context, empty *pb.Empty) (*pb.CoreInfoRespons
|
|||||||
func (s *server) Restart(ctx context.Context, in *pb.StartRequest) (*pb.CoreInfoResponse, error) {
|
func (s *server) Restart(ctx context.Context, in *pb.StartRequest) (*pb.CoreInfoResponse, error) {
|
||||||
defer config.DeferPanicToError("restart", func(err error) {
|
defer config.DeferPanicToError("restart", func(err error) {
|
||||||
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
|
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
|
||||||
stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
StopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
||||||
})
|
})
|
||||||
log.Debug("[Service] Restarting")
|
log.Debug("[Service] Restarting")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user