From fcd117d1393285af396d2c971801bbf5b057bb09 Mon Sep 17 00:00:00 2001 From: x Date: Sat, 28 Dec 2024 17:11:00 +0100 Subject: [PATCH] update for better handling the background service --- extension/interface.go | 2 +- go.mod | 156 ---------------------------------- platform/mobile/mobile.go | 8 +- v2/config/config.go | 4 + v2/db/hiddify_db.go | 9 +- v2/hcore/buildconfighelper.go | 5 +- v2/hcore/grpc_server.go | 83 +++++++++--------- v2/hcore/restart.go | 2 +- v2/hcore/service.go | 25 +++--- v2/hcore/standalone.go | 6 +- v2/hcore/start.go | 13 +-- 11 files changed, 87 insertions(+), 226 deletions(-) diff --git a/extension/interface.go b/extension/interface.go index 911c533b..8b9c4da9 100644 --- a/extension/interface.go +++ b/extension/interface.go @@ -122,5 +122,5 @@ func (s *extensionService) OnMainServiceClose() error { } func init() { - service_manager.Register(&extensionService{}) + // service_manager.Register(&extensionService{}) } diff --git a/go.mod b/go.mod index 4c5d2514..9e6a233e 100644 --- a/go.mod +++ b/go.mod @@ -1,159 +1,3 @@ -// module github.com/hiddify/hiddify-core - -// go 1.22.0 - -// toolchain go1.22.3 - -// require ( -// github.com/bepass-org/warp-plus v1.2.4 -// github.com/google/uuid v1.6.0 -// github.com/hiddify/hiddify-app-demo-extension v0.0.0-20241001070003-26039f960ad6 -// github.com/hiddify/ray2sing v0.0.0-20240804185422-f340989b59a0 -// github.com/improbable-eng/grpc-web v0.15.0 -// github.com/jellydator/validation v1.1.0 -// github.com/kardianos/service v1.2.2 -// github.com/sagernet/gomobile v0.1.4 -// github.com/sagernet/sing v0.4.3 -// github.com/sagernet/sing-box v1.8.9 -// github.com/sagernet/sing-dns v0.2.3 -// github.com/spf13/cobra v1.8.0 -// github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca -// github.com/tendermint/tm-db v0.6.7 -// github.com/xmdhs/clash2singbox v0.0.2 -// golang.org/x/net v0.28.0 -// golang.org/x/sys v0.25.0 -// google.golang.org/grpc v1.67.0 -// google.golang.org/protobuf v1.35.1 -// gopkg.in/yaml.v3 v3.0.1 -// ) - -// require ( -// berty.tech/go-libtor v1.0.385 // indirect -// github.com/DataDog/zstd v1.4.1 // indirect -// github.com/ajg/form v1.5.1 // indirect -// github.com/andybalholm/brotli v1.1.0 // indirect -// github.com/caddyserver/certmagic v0.20.0 // indirect -// github.com/cenkalti/backoff/v4 v4.1.1 // indirect -// github.com/cespare/xxhash v1.1.0 // indirect -// github.com/cloudflare/circl v1.4.0 // indirect -// github.com/cosmos/gorocksdb v1.2.0 // indirect -// github.com/cretz/bine v0.2.0 // indirect -// github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect -// github.com/dgraph-io/badger/v2 v2.2007.2 // indirect -// github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de // indirect -// github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 // indirect -// github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect -// github.com/dustin/go-humanize v1.0.0 // indirect -// github.com/fatih/color v1.16.0 // indirect -// github.com/francoispqt/gojay v1.2.13 // indirect -// github.com/fsnotify/fsnotify v1.7.0 // indirect -// github.com/gaukas/godicttls v0.0.4 // indirect -// github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 // indirect -// github.com/go-chi/chi/v5 v5.0.12 // indirect -// github.com/go-chi/cors v1.2.1 // indirect -// github.com/go-chi/render v1.0.3 // indirect -// github.com/go-ole/go-ole v1.3.0 // indirect -// github.com/go-task/slim-sprig/v3 v3.0.0 // indirect -// github.com/gobwas/httphead v0.1.0 // indirect -// github.com/gobwas/pool v0.2.1 // indirect -// github.com/gofrs/uuid/v5 v5.2.0 // indirect -// github.com/golang/protobuf v1.5.4 // indirect -// github.com/golang/snappy v0.0.1 // indirect -// github.com/google/btree v1.1.2 // indirect -// github.com/google/pprof v0.0.0-20240528025155-186aa0362fba // indirect -// github.com/gorilla/websocket v1.5.3 // indirect -// github.com/hashicorp/yamux v0.1.1 // indirect -// github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b // indirect -// github.com/inconshreveable/mousetrap v1.1.0 // indirect -// github.com/insomniacslk/dhcp v0.0.0-20231206064809-8c70d406f6d2 // indirect -// github.com/jmhodges/levigo v1.0.0 // indirect -// github.com/josharian/native v1.1.0 // indirect -// github.com/klauspost/compress v1.17.8 // indirect -// github.com/klauspost/cpuid/v2 v2.2.7 // indirect -// github.com/libdns/alidns v1.0.3 // indirect -// github.com/libdns/cloudflare v0.1.1 // indirect -// github.com/libdns/libdns v0.2.2 // indirect -// github.com/logrusorgru/aurora v2.0.3+incompatible // indirect -// github.com/mattn/go-colorable v0.1.13 // indirect -// github.com/mattn/go-isatty v0.0.20 // indirect -// github.com/metacubex/tfo-go v0.0.0-20240821025650-e9be0afd5e7d // indirect -// github.com/mholt/acmez v1.2.0 // indirect -// github.com/miekg/dns v1.1.62 // indirect -// github.com/modern-go/reflect2 v1.0.2 // indirect -// github.com/onsi/ginkgo/v2 v2.19.0 // indirect -// github.com/ooni/go-libtor v1.1.8 // indirect -// github.com/oschwald/maxminddb-golang v1.12.0 // indirect -// github.com/pelletier/go-toml v1.9.5 // indirect -// github.com/pierrec/lz4/v4 v4.1.14 // indirect -// github.com/pion/dtls/v2 v2.2.7 // indirect -// github.com/pion/logging v0.2.2 // indirect -// github.com/pion/randutil v0.1.0 // indirect -// github.com/pion/stun/v2 v2.0.0 // indirect -// github.com/pion/transport/v2 v2.2.3 // indirect -// github.com/pion/transport/v3 v3.0.1 // indirect -// github.com/pion/turn/v3 v3.0.1 // indirect -// github.com/pires/go-proxyproto v0.7.0 // indirect -// github.com/pkg/errors v0.9.1 // indirect -// github.com/quic-go/qpack v0.4.0 // indirect -// github.com/quic-go/qtls-go1-20 v0.4.1 // indirect -// github.com/quic-go/quic-go v0.46.0 // indirect -// github.com/refraction-networking/utls v1.6.7 // indirect -// github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect -// github.com/rs/cors v1.7.0 // indirect -// github.com/sagernet/bbolt v0.0.0-20231014093535-ea5cb2fe9f0a // indirect -// github.com/sagernet/cloudflare-tls v0.0.0-20231208171750-a4483c1b7cd1 // indirect -// github.com/sagernet/gvisor v0.0.0-20240428053021-e691de28565f // indirect -// github.com/sagernet/netlink v0.0.0-20240523065131-45e60152f9ba // indirect -// github.com/sagernet/quic-go v0.47.0-beta.2 // indirect -// github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 // indirect -// github.com/sagernet/sing-mux v0.2.0 // indirect -// github.com/sagernet/sing-quic v0.2.2 // indirect -// github.com/sagernet/sing-shadowsocks v0.2.7 // indirect -// github.com/sagernet/sing-shadowsocks2 v0.2.0 // indirect -// github.com/sagernet/sing-shadowtls v0.1.4 // indirect -// github.com/sagernet/sing-tun v0.3.3 // indirect -// github.com/sagernet/sing-vmess v0.1.12 // indirect -// github.com/sagernet/smux v0.0.0-20231208180855-7041f6ea79e7 // indirect -// github.com/sagernet/utls v1.5.4 // indirect -// github.com/sagernet/wireguard-go v0.0.0-20231215174105-89dec3b2f3e8 // indirect -// github.com/sagernet/ws v0.0.0-20231204124109-acfe8907c854 // indirect -// github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771 // indirect -// github.com/spf13/pflag v1.0.5 // indirect -// github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 // indirect -// github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect -// github.com/vishvananda/netns v0.0.4 // indirect -// github.com/xtls/reality v0.0.0-20240712055506-48f0b2d5ed6d // indirect -// github.com/xtls/xray-core v1.8.21 // indirect -// github.com/zeebo/blake3 v0.2.3 // indirect -// go.etcd.io/bbolt v1.3.6 // indirect -// go.uber.org/mock v0.4.0 // indirect -// go.uber.org/multierr v1.11.0 // indirect -// go.uber.org/zap v1.27.0 // indirect -// go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect -// golang.org/x/crypto v0.26.0 // indirect -// golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect -// golang.org/x/mod v0.18.0 // indirect -// golang.org/x/sync v0.8.0 // indirect -// golang.org/x/text v0.18.0 // indirect -// golang.org/x/time v0.5.0 // indirect -// golang.org/x/tools v0.22.0 // indirect -// google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect -// gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect -// gopkg.in/yaml.v2 v2.4.0 // indirect -// lukechampine.com/blake3 v1.3.0 // indirect -// nhooyr.io/websocket v1.8.6 // indirect -// ) - -// replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20241013222038-47abad60f848 - -// replace github.com/xtls/xray-core => github.com/hiddify/xray-core v0.0.0-20240902024714-0fcb0895bb4b - -// replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240727191222-383c1da14ff1 - -// replace github.com/bepass-org/warp-plus => github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d - -// replace github.com/hiddify/ray2sing => github.com/hiddify/ray2sing v0.0.0-20240928221833-190b549d5222 - module github.com/hiddify/hiddify-core go 1.22.0 diff --git a/platform/mobile/mobile.go b/platform/mobile/mobile.go index 774c0e15..c76b5e46 100644 --- a/platform/mobile/mobile.go +++ b/platform/mobile/mobile.go @@ -8,7 +8,7 @@ import ( "github.com/sagernet/sing-box/experimental/libbox" ) -func Setup(baseDir string, workingDir string, tempDir string, mode int, listen string, secret string, debug bool) error { +func Setup(baseDir string, workingDir string, tempDir string, mode int, listen string, secret string, debug bool, platformInterface libbox.PlatformInterface) error { return hcore.Setup(&hcore.SetupRequest{ BasePath: baseDir, WorkingDir: workingDir, @@ -18,7 +18,7 @@ func Setup(baseDir string, workingDir string, tempDir string, mode int, listen s Debug: debug, Mode: hcore.SetupMode(mode), Secret: secret, - }) + }, platformInterface) // return hcore.Start(17078) } @@ -37,11 +37,11 @@ func BuildConfig(configPath string) (string, error) { // return state, err // } -func Start(configPath string, configContent string, platformInterface libbox.PlatformInterface) error { +func Start(configPath string, configContent string) error { _, err := hcore.StartService(&hcore.StartRequest{ ConfigPath: configPath, ConfigContent: configContent, - }, platformInterface) + }) return err } diff --git a/v2/config/config.go b/v2/config/config.go index 1a2d5c70..0a374b16 100644 --- a/v2/config/config.go +++ b/v2/config/config.go @@ -148,11 +148,15 @@ func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOp case C.TypeCustom: continue default: + if opt.Warp.EnableWarp && opt.Warp.Mode == "warp_over_proxy" && out.Tag == "Hiddify Warp ✅" { + continue + } if !strings.Contains(out.Tag, "§hide§") { tags = append(tags, out.Tag) } out = patchHiddifyWarpFromConfig(out, *opt) outbounds = append(outbounds, out) + } } diff --git a/v2/db/hiddify_db.go b/v2/db/hiddify_db.go index e0f3b3f7..932d885b 100644 --- a/v2/db/hiddify_db.go +++ b/v2/db/hiddify_db.go @@ -20,13 +20,16 @@ func getDB(name string, readOnly bool) (tmdb.DB, error) { if _, err := os.Stat(dbPath); os.IsNotExist(err) { readOnly = false } - const retryAttempts = 100 const retryDelay = 100 * time.Microsecond var db tmdb.DB var err error - + defer func() { + if r := recover(); r != nil { + log.Printf("Recovered from panic: %v", r) + } + }() for i := 0; i < retryAttempts; i++ { // Set readOnly to true for the first 80 attempts opts := &opt.Options{ReadOnly: readOnly && i < 80} @@ -35,11 +38,9 @@ func getDB(name string, readOnly bool) (tmdb.DB, error) { if err == nil { return db, nil } - log.Printf("Failed attempt %d to initialize the database: %v", i, err) time.Sleep(retryDelay) } - return nil, err } diff --git a/v2/hcore/buildconfighelper.go b/v2/hcore/buildconfighelper.go index 99897da6..a2d350b4 100644 --- a/v2/hcore/buildconfighelper.go +++ b/v2/hcore/buildconfighelper.go @@ -25,7 +25,9 @@ func BuildConfigJson(in *StartRequest) (string, error) { } func BuildConfig(in *StartRequest) (*option.Options, error) { + Log(LogLevel_DEBUG, LogType_CORE, "Building Config...") content := in.ConfigContent + if content == "" { fileContent, err := os.ReadFile(in.ConfigPath) if err != nil { @@ -33,8 +35,7 @@ func BuildConfig(in *StartRequest) (*option.Options, error) { } content = string(fileContent) } - - Log(LogLevel_DEBUG, LogType_CORE, "Parsing Config") + Log(LogLevel_DEBUG, LogType_CORE, "Parsing Config... ", in.ConfigPath, " content:", content, "-") parsedContent, err := readOptions(content) Log(LogLevel_DEBUG, LogType_CORE, "Parsed") diff --git a/v2/hcore/grpc_server.go b/v2/hcore/grpc_server.go index 4fcca192..26a0ea95 100644 --- a/v2/hcore/grpc_server.go +++ b/v2/hcore/grpc_server.go @@ -13,7 +13,9 @@ import ( "net" "strconv" "strings" + "time" + "github.com/hiddify/hiddify-core/v2/config" hcommon "github.com/hiddify/hiddify-core/v2/hcommon" "github.com/hiddify/hiddify-core/v2/hello" hutils "github.com/hiddify/hiddify-core/v2/hutils" @@ -82,60 +84,59 @@ func StartGrpcServerByMode(listenAddressG string, mode SetupMode) (*grpc.Server, if hutils.IsPortInUse(uint16(port)) { return nil, fmt.Errorf("port %s is already in use", portStr) } - // Fetch the server private key and public key from the database - if grpcServer[mode] != nil { + if _, exists := grpcServer[mode]; exists { Log(LogLevel_WARNING, LogType_CORE, "grpcServer already started") return grpcServer[mode], nil } - table := db.GetTable[hcommon.AppSettings]() - grpcServerPrivateKey, err := table.Get("grpc_server_private_key") - grpcServerPublicKey, err2 := table.Get("grpc_server_public_key") - if err != nil || err2 != nil { - Log(LogLevel_DEBUG, LogType_CORE, fmt.Sprintf("failed to get grpc_server_private_key and grpc_server_public_key from database: %v %v\n", err, err2)) - certpair, err = hutils.GenerateCertificatePair() - if err != nil { - Log(LogLevel_ERROR, LogType_CORE, fmt.Sprintf("failed to generate certificate pair: %v", err)) - return nil, err - } - table.UpdateInsert( - &hcommon.AppSettings{Id: "grpc_server_public_key", Value: certpair.Certificate}, - &hcommon.AppSettings{Id: "grpc_server_private_key", Value: certpair.PrivateKey}, - ) + if mode == SetupMode_GRPC_BACKGROUND_INSECURE || mode == SetupMode_GRPC_NORMAL_INSECURE { + grpcServer[mode] = grpc.NewServer() } else { - certpair = &hutils.CertificatePair{ - Certificate: grpcServerPublicKey.Value.([]byte), - PrivateKey: grpcServerPrivateKey.Value.([]byte), + table := db.GetTable[hcommon.AppSettings]() + Log(LogLevel_DEBUG, LogType_CORE, table) + grpcServerPrivateKey, err := table.Get("grpc_server_private_key") + grpcServerPublicKey, err2 := table.Get("grpc_server_public_key") + if err != nil || err2 != nil { + Log(LogLevel_DEBUG, LogType_CORE, fmt.Sprintf("failed to get grpc_server_private_key and grpc_server_public_key from database: %v %v\n", err, err2)) + certpair, err = hutils.GenerateCertificatePair() + if err != nil { + Log(LogLevel_ERROR, LogType_CORE, fmt.Sprintf("failed to generate certificate pair: %v", err)) + + return nil, err + } + table.UpdateInsert( + &hcommon.AppSettings{Id: "grpc_server_public_key", Value: certpair.Certificate}, + &hcommon.AppSettings{Id: "grpc_server_private_key", Value: certpair.PrivateKey}, + ) + } else { + certpair = &hutils.CertificatePair{ + Certificate: grpcServerPublicKey.Value.([]byte), + PrivateKey: grpcServerPrivateKey.Value.([]byte), + } } - } - - // Load server certificate and private key - serverCert, err := tls.X509KeyPair(certpair.Certificate, certpair.PrivateKey) - if err != nil { - Log(LogLevel_DEBUG, LogType_CORE, fmt.Sprintf("failed to load server certificate and key: %v\n", err)) + // Load server certificate and private key + serverCert, err := tls.X509KeyPair(certpair.Certificate, certpair.PrivateKey) + if err != nil { + Log(LogLevel_DEBUG, LogType_CORE, fmt.Sprintf("failed to load server certificate and key: %v\n", err)) - return nil, err - } + return nil, err + } - // Create TLS credentials for the gRPC server - tlsConfig := &tls.Config{ - Certificates: []tls.Certificate{serverCert}, - ClientAuth: tls.RequireAndVerifyClientCert, // Enforce mutual TLS (mTLS) - ClientCAs: caCertPool, // Client CAs to verify client certificates - } + // Create TLS credentials for the gRPC server + tlsConfig := &tls.Config{ + Certificates: []tls.Certificate{serverCert}, + ClientAuth: tls.RequireAndVerifyClientCert, // Enforce mutual TLS (mTLS) + ClientCAs: caCertPool, // Client CAs to verify client certificates + } - // Create a new gRPC server with TLS credentials - creds := credentials.NewTLS(tlsConfig) - if mode == SetupMode_GRPC_BACKGROUND_INSECURE || mode == SetupMode_GRPC_NORMAL_INSECURE { - grpcServer[mode] = grpc.NewServer() - } else { + // Create a new gRPC server with TLS credentials + creds := credentials.NewTLS(tlsConfig) grpcServer[mode] = grpc.NewServer(grpc.Creds(creds)) } // Register your gRPC service here RegisterCoreServer(grpcServer[mode], &CoreService{}) hello.RegisterHelloServer(grpcServer[mode], &hello.HelloService{}) - // Listen on the provided address lis, err := net.Listen("tcp", listenAddressG) if err != nil { @@ -147,6 +148,10 @@ func StartGrpcServerByMode(listenAddressG string, mode SetupMode) (*grpc.Server, // Run the server in a goroutine go func() { + defer config.DeferPanicToError("grpcsetup", func(err error) { + Log(LogLevel_FATAL, LogType_CORE, err.Error()) + <-time.After(5 * time.Second) + }) if err := grpcServer[mode].Serve(lis); err != nil { Log(LogLevel_DEBUG, LogType_CORE, fmt.Sprintf("failed to serve: %v\n", err)) } diff --git a/v2/hcore/restart.go b/v2/hcore/restart.go index 8f022eca..956adb82 100644 --- a/v2/hcore/restart.go +++ b/v2/hcore/restart.go @@ -35,6 +35,6 @@ func Restart(in *StartRequest) (coreResponse *CoreInfoResponse, err error) { // <-time.After(250 * time.Millisecond) libbox.SetMemoryLimit(!in.DisableMemoryLimit) - resp, gErr := StartService(in, nil) + resp, gErr := StartService(in) return resp, gErr } diff --git a/v2/hcore/service.go b/v2/hcore/service.go index e72ad4dc..0269c564 100644 --- a/v2/hcore/service.go +++ b/v2/hcore/service.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "runtime" runtimeDebug "runtime/debug" "time" @@ -27,11 +26,12 @@ import ( ) var ( - sWorkingPath string - sTempPath string - sUserID int - sGroupID int - statusPropagationPort int64 + sWorkingPath string + sTempPath string + sUserID int + sGroupID int + statusPropagationPort int64 + globalPlatformInterface libbox.PlatformInterface ) func InitHiddifyService() error { @@ -42,7 +42,7 @@ func (s *CoreService) Setup(ctx context.Context, req *SetupRequest) (*hcommon.Re if grpcServer[req.Mode] != nil { return &hcommon.Response{Code: hcommon.ResponseCode_OK, Message: ""}, nil } - err := Setup(req) + err := Setup(req, nil) code := hcommon.ResponseCode_OK if err != nil { code = hcommon.ResponseCode_FAILED @@ -50,17 +50,19 @@ func (s *CoreService) Setup(ctx context.Context, req *SetupRequest) (*hcommon.Re return &hcommon.Response{Code: code, Message: err.Error()}, err } -func Setup(params *SetupRequest) error { +func Setup(params *SetupRequest, platformInterface libbox.PlatformInterface) error { defer config.DeferPanicToError("setup", func(err error) { Log(LogLevel_FATAL, LogType_CORE, err.Error()) + <-time.After(5 * time.Second) }) + globalPlatformInterface = platformInterface if grpcServer[params.Mode] != nil { Log(LogLevel_WARNING, LogType_CORE, "grpcServer already started") return nil } - tcpConn := runtime.GOOS == "windows" // TODO add TVOS + tcpConn := true // runtime.GOOS == "windows" // TODO add TVOS libbox.Setup(params.BasePath, params.WorkingDir, params.TempDir, tcpConn) - hutils.RedirectStderr(fmt.Sprint(params.WorkingDir, "/data/stderr.log")) + hutils.RedirectStderr(fmt.Sprint(params.WorkingDir, "/data/stderr", params.Mode, ".log")) Log(LogLevel_DEBUG, LogType_CORE, fmt.Sprintf("libbox.Setup success %s %s %s %v", params.BasePath, params.WorkingDir, params.TempDir, tcpConn)) @@ -95,6 +97,7 @@ func Setup(params *SetupRequest) error { switch params.Mode { case SetupMode_OLD: statusPropagationPort = int64(params.FlutterStatusPort) + // case SetupMode_GRPC_BACKGROUND_INSECURE: default: _, err := StartGrpcServerByMode(params.Listen, params.Mode) if err != nil { @@ -104,11 +107,13 @@ func Setup(params *SetupRequest) error { settings := db.GetTable[hcommon.AppSettings]() val, err := settings.Get("HiddifySettingsJson") if val == nil || err != nil { + // if params.Mode == SetupMode_GRPC_BACKGROUND_INSECURE { _, err := ChangeHiddifySettings(&ChangeHiddifySettingsRequest{HiddifySettingsJson: ""}) if err != nil { Log(LogLevel_DEBUG, LogType_CORE, E.Cause(err, "ChangeHiddifySettings").Error()) } } else { + // settings := db.GetTable[hcommon.AppSettings]() _, err := ChangeHiddifySettings(&ChangeHiddifySettingsRequest{HiddifySettingsJson: val.Value.(string)}) if err != nil { Log(LogLevel_DEBUG, LogType_CORE, E.Cause(err, "ChangeHiddifySettings").Error()) diff --git a/v2/hcore/standalone.go b/v2/hcore/standalone.go index 216859e3..984b4979 100644 --- a/v2/hcore/standalone.go +++ b/v2/hcore/standalone.go @@ -31,7 +31,7 @@ func RunStandalone(hiddifySettingPath string, configPath string, defaultConfig c EnableOldCommandServer: false, DelayStart: false, EnableRawConfig: true, - }, nil) + }) go updateConfigInterval(current, hiddifySettingPath, configPath) sigChan := make(chan os.Signal, 1) @@ -188,7 +188,7 @@ func buildConfig(configContent string, options config.HiddifyOptions) (string, e Debug: false, Listen: "127.0.0.1:17078", Mode: SetupMode_GRPC_NORMAL_INSECURE, - }); err != nil { + }, nil); err != nil { return "", fmt.Errorf("failed to set up global configuration: %w", err) } @@ -219,7 +219,7 @@ func updateConfigInterval(current ConfigResult, hiddifySettingPath string, confi EnableOldCommandServer: false, DisableMemoryLimit: false, EnableRawConfig: true, - }, nil) + }) } current = new } diff --git a/v2/hcore/start.go b/v2/hcore/start.go index 84e273a4..521f071b 100644 --- a/v2/hcore/start.go +++ b/v2/hcore/start.go @@ -17,23 +17,24 @@ func (s *CoreService) Start(ctx context.Context, in *StartRequest) (*CoreInfoRes } func Start(in *StartRequest) (*CoreInfoResponse, error) { - return StartService(in, nil) + return StartService(in) } func (s *CoreService) StartService(ctx context.Context, in *StartRequest) (*CoreInfoResponse, error) { - return StartService(in, nil) + return StartService(in) } -func StartService(in *StartRequest, platformInterface libbox.PlatformInterface) (coreResponse *CoreInfoResponse, err error) { +func StartService(in *StartRequest) (coreResponse *CoreInfoResponse, err error) { defer config.DeferPanicToError("startmobile", func(recovered_err error) { coreResponse, err = errorWrapper(MessageType_UNEXPECTED_ERROR, recovered_err) }) SetCoreStatus(CoreStates_STARTING, MessageType_EMPTY, "") - Log(LogLevel_DEBUG, LogType_CORE, "Starting Core Service") + options, err := BuildConfig(in) if err != nil { return errorWrapper(MessageType_ERROR_BUILDING_CONFIG, err) } + Log(LogLevel_DEBUG, LogType_CORE, "Main Service pre start") if err := service_manager.OnMainServicePreStart(options); err != nil { return errorWrapper(MessageType_ERROR_EXTENSION, err) } @@ -51,8 +52,8 @@ func StartService(in *StartRequest, platformInterface libbox.PlatformInterface) Options: *options, PlatformLogWriter: &LogInterface{}, } - if platformInterface != nil { - bopts.PlatformInterface = libbox.WrapPlatformInterface(platformInterface) + if globalPlatformInterface != nil { + bopts.PlatformInterface = libbox.WrapPlatformInterface(globalPlatformInterface) } instance, err := libbox.NewHService(bopts) if err != nil {