From c5ba3e024efcbdb50e321efc3ac293df5eda424c Mon Sep 17 00:00:00 2001
From: hiddify <114227601+hiddify-com@users.noreply.github.com>
Date: Sun, 29 Sep 2024 20:11:52 +0200
Subject: [PATCH] release: version 3.1.2
---
.github/change_version.sh | 20 +++++++++++++++
Info.plist | 4 +--
Makefile | 24 +++---------------
cmd/cmd_extension.go | 1 +
config/warp.go | 2 +-
custom/custom.go | 1 -
extension/extension.go | 2 +-
extension/extension_host.go | 2 +-
extension/interface.go | 35 ++++++++++++++++++++++----
go.mod | 2 +-
go.sum | 4 +--
mobile/mobile.go | 6 +++--
{common => v2/common}/cache.go | 23 +++++++++++++++--
{common => v2/common}/utils.go | 0
v2/grpc_server.go | 1 -
v2/service.go | 14 +++++++++--
v2/service_manager/hiddify.go | 46 ++++++++++++++++++++++++++++++++++
17 files changed, 145 insertions(+), 42 deletions(-)
create mode 100755 .github/change_version.sh
rename {common => v2/common}/cache.go (87%)
rename {common => v2/common}/utils.go (100%)
create mode 100644 v2/service_manager/hiddify.go
diff --git a/.github/change_version.sh b/.github/change_version.sh
new file mode 100755
index 00000000..9d19de08
--- /dev/null
+++ b/.github/change_version.sh
@@ -0,0 +1,20 @@
+#! /bin/bash
+echo "previous version was $(git describe --tags $(git rev-list --tags --max-count=1))"
+echo "WARNING: This operation will creates version tag and push to github"
+read -p "Version? (provide the next x.y.z semver) : " TAG
+echo $TAG &&\
+[[ "$TAG" =~ ^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}(\.dev)?$ ]] || { echo "Incorrect tag. e.g., 1.2.3 or 1.2.3.dev"; exit 1; }
+IFS="." read -r -a VERSION_ARRAY <<< "$TAG"
+VERSION_STR="${VERSION_ARRAY[0]}.${VERSION_ARRAY[1]}.${VERSION_ARRAY[2]}"
+BUILD_NUMBER=$(( ${VERSION_ARRAY[0]} * 10000 + ${VERSION_ARRAY[1]} * 100 + ${VERSION_ARRAY[2]} ))
+echo "version: ${VERSION_STR}+${BUILD_NUMBER}"
+sed -i -e "s|CFBundleVersion\s*[^<]*|CFBundleVersion${VERSION_STR}|" Info.plist &&\
+sed -i -e "s|CFBundleShortVersionString\s*[^<]*|CFBundleShortVersionString${VERSION_STR}|" Info.plist &&\
+sed -i "s|ENV VERSION=.*|ENV VERSION=v${TAG}|g" docker/Dockerfile
+git add Info.plist docker/Dockerfile
+git commit -m "release: version ${TAG}"
+echo "creating git tag : v${TAG}"
+git push
+git tag v${TAG}
+git push -u origin HEAD --tags
+echo "Github Actions will detect the new tag and release the new version."'
\ No newline at end of file
diff --git a/Info.plist b/Info.plist
index 33a08525..2d2369b6 100644
--- a/Info.plist
+++ b/Info.plist
@@ -42,8 +42,8 @@
1.0
CFBundleIdentifier
ios.libcore.hiddify
- CFBundleShortVersionString3.1.1
- CFBundleVersion3.1.1
+ CFBundleShortVersionString3.1.2
+ CFBundleVersion3.1.2
MinimumOSVersion
15.0
diff --git a/Makefile b/Makefile
index 2520081b..45213b0d 100644
--- a/Makefile
+++ b/Makefile
@@ -100,26 +100,8 @@ clean:
-release: # Create a new tag for release.
- @echo "previous version was $$(git describe --tags $$(git rev-list --tags --max-count=1))"
- @echo "WARNING: This operation will creates version tag and push to github"
- @bash -c '\
- read -p "Version? (provide the next x.y.z semver) : " TAG && \
- echo $$TAG &&\
- [[ "$$TAG" =~ ^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}(\.dev)?$$ ]] || { echo "Incorrect tag. e.g., 1.2.3 or 1.2.3.dev"; exit 1; } && \
- IFS="." read -r -a VERSION_ARRAY <<< "$$TAG" && \
- VERSION_STR="$${VERSION_ARRAY[0]}.$${VERSION_ARRAY[1]}.$${VERSION_ARRAY[2]}" && \
- BUILD_NUMBER=$$(( $${VERSION_ARRAY[0]} * 10000 + $${VERSION_ARRAY[1]} * 100 + $${VERSION_ARRAY[2]} )) && \
- echo "version: $${VERSION_STR}+$${BUILD_NUMBER}" && \
- sed -i -e "s|CFBundleVersion\s*[^<]*|CFBundleVersion$${VERSION_STR}|" Info.plist &&\
- sed -i -e "s|CFBundleShortVersionString\s*[^<]*|CFBundleShortVersionString$${VERSION_STR}|" Info.plist &&\
- sed -i "s|ENV VERSION=.*|ENV VERSION=v$${TAG}|g" docker/Dockerfile && \
- git add Info.plist docker/Dockerfile && \
- git commit -m "release: version $${TAG}" && \
- echo "creating git tag : v$${TAG}" && \
- git push && \
- git tag v$${TAG} && \
- git push -u origin HEAD --tags && \
- echo "Github Actions will detect the new tag and release the new version."'
+release: # Create a new tag for release.
+ @bash -c '.github/change_version.sh'
+
diff --git a/cmd/cmd_extension.go b/cmd/cmd_extension.go
index fce7fe85..80fe0f32 100644
--- a/cmd/cmd_extension.go
+++ b/cmd/cmd_extension.go
@@ -31,6 +31,7 @@ var commandExtension = &cobra.Command{
}
func StartExtension() {
+ v2.Setup("./tmp", "./", "./tmp", 0, false)
grpc_server, _ := v2.StartCoreGrpcServer("127.0.0.1:12345")
fmt.Printf("Waiting for CTRL+C to stop\n")
runWebserver(grpc_server)
diff --git a/config/warp.go b/config/warp.go
index 4c5cc012..81d2afe1 100644
--- a/config/warp.go
+++ b/config/warp.go
@@ -9,7 +9,7 @@ import (
"strings"
"github.com/bepass-org/warp-plus/warp"
- "github.com/hiddify/hiddify-core/common"
+ "github.com/hiddify/hiddify-core/v2/common"
C "github.com/sagernet/sing-box/constant"
// "github.com/bepass-org/wireguard-go/warp"
diff --git a/custom/custom.go b/custom/custom.go
index 9250bfee..ff990218 100644
--- a/custom/custom.go
+++ b/custom/custom.go
@@ -27,7 +27,6 @@ func setupOnce(api unsafe.Pointer) {
//export setup
func setup(baseDir *C.char, workingDir *C.char, tempDir *C.char, statusPort C.longlong, debug bool) (CErr *C.char) {
err := v2.Setup(C.GoString(baseDir), C.GoString(workingDir), C.GoString(tempDir), int64(statusPort), debug)
-
return emptyOrErrorC(err)
}
diff --git a/extension/extension.go b/extension/extension.go
index 66d7baef..fe6093a1 100644
--- a/extension/extension.go
+++ b/extension/extension.go
@@ -1,10 +1,10 @@
package extension
import (
- "github.com/hiddify/hiddify-core/common"
"github.com/hiddify/hiddify-core/config"
"github.com/hiddify/hiddify-core/extension/ui"
pb "github.com/hiddify/hiddify-core/hiddifyrpc"
+ "github.com/hiddify/hiddify-core/v2/common"
"github.com/jellydator/validation"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
diff --git a/extension/extension_host.go b/extension/extension_host.go
index 31fbbe40..2585e656 100644
--- a/extension/extension_host.go
+++ b/extension/extension_host.go
@@ -5,8 +5,8 @@ import (
"fmt"
"log"
- "github.com/hiddify/hiddify-core/common"
pb "github.com/hiddify/hiddify-core/hiddifyrpc"
+ "github.com/hiddify/hiddify-core/v2/common"
"google.golang.org/grpc"
)
diff --git a/extension/interface.go b/extension/interface.go
index 4fb74996..1ba80f53 100644
--- a/extension/interface.go
+++ b/extension/interface.go
@@ -4,7 +4,8 @@ import (
"fmt"
"log"
- "github.com/hiddify/hiddify-core/common"
+ "github.com/hiddify/hiddify-core/v2/common"
+ "github.com/hiddify/hiddify-core/v2/service_manager"
)
var (
@@ -26,11 +27,7 @@ func RegisterExtension(factory ExtensionFactory) error {
return err
}
allExtensionsMap[factory.Id] = factory
- common.Storage.GetExtensionData("default", &generalExtensionData)
- if val, ok := generalExtensionData.ExtensionStatusMap[factory.Id]; ok && val {
- loadExtension(factory)
- }
return nil
}
@@ -43,3 +40,31 @@ func loadExtension(factory ExtensionFactory) error {
return nil
}
+
+type extensionService struct {
+ // Storage *CacheFile
+}
+
+func (s *extensionService) Start() error {
+ common.Storage.GetExtensionData("default", &generalExtensionData)
+
+ for id, factory := range allExtensionsMap {
+ if val, ok := generalExtensionData.ExtensionStatusMap[id]; ok && val {
+ loadExtension(factory)
+ }
+ }
+ return nil
+}
+
+func (s *extensionService) Close() error {
+ for _, extension := range enabledExtensionsMap {
+ if err := (*extension).Stop(); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func init() {
+ service_manager.Register(&extensionService{})
+}
diff --git a/go.mod b/go.mod
index d9aea831..cfa395f8 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ toolchain go1.22.3
require (
github.com/bepass-org/warp-plus v1.2.4
github.com/fatih/color v1.16.0 // indirect
- github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240928194626-7f6dde034dfe
+ github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240929171529-e72be5930514
github.com/improbable-eng/grpc-web v0.15.0
github.com/jellydator/validation v1.1.0
github.com/kardianos/service v1.2.2
diff --git a/go.sum b/go.sum
index 6a772dbd..9583ea41 100644
--- a/go.sum
+++ b/go.sum
@@ -239,8 +239,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-app-demo-extension v0.0.0-20240929132536-e158b83e958c h1:DHMeFSoah61yZQKWhQGK6V8ve6KzoiPn1tdK/kpY5Wc=
github.com/hiddify/hiddify-app-demo-extension v0.0.0-20240929132536-e158b83e958c/go.mod h1:a/gJxWYZWt5ii9sDObSERSmxVEUVtsR8ZMnbgN8tLCM=
-github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240928194626-7f6dde034dfe h1:lqlc/H76XSDdOlwboI77pdDZGTwzNh6/J0MaYGOYUAc=
-github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240928194626-7f6dde034dfe/go.mod h1:9Fjoaxn2gbFQioxwdb06Kaz4kfFV7nxS0TJ/+IlDWvg=
+github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240929171529-e72be5930514 h1:22nmdhhrCUW5ygzSIIs6KlCndJGmNUb7+43i71M5nHg=
+github.com/hiddify/hiddify-ip-scanner-extension v0.0.0-20240929171529-e72be5930514/go.mod h1:9Fjoaxn2gbFQioxwdb06Kaz4kfFV7nxS0TJ/+IlDWvg=
github.com/hiddify/hiddify-sing-box v1.8.9-0.20240928213625-7b79bf0c814d h1:+jTGlmOl+Kt3JEU1pt5yIItpi6nKKqUIUf76jkONHgQ=
github.com/hiddify/hiddify-sing-box v1.8.9-0.20240928213625-7b79bf0c814d/go.mod h1:2Cozqb5uVY/y0c/HWZ57CfE6fZwjmik/J3tWynsjjDA=
github.com/hiddify/ray2sing v0.0.0-20240928221833-190b549d5222 h1:+MFxFxoWCA44WhqIixqL/Zkt4DwnqhQvafS0Dm4+dKM=
diff --git a/mobile/mobile.go b/mobile/mobile.go
index 2ecc8e1c..3eefeb1c 100644
--- a/mobile/mobile.go
+++ b/mobile/mobile.go
@@ -7,13 +7,15 @@ import (
"github.com/hiddify/hiddify-core/config"
+ "github.com/hiddify/hiddify-core/v2"
+
_ "github.com/sagernet/gomobile"
"github.com/sagernet/sing-box/option"
)
-func Setup() error {
+func Setup(baseDir string, workingDir string, tempDir string, debug bool) error {
+ return v2.Setup(baseDir, workingDir, tempDir, 0, debug)
// return v2.Start(17078)
- return nil
}
func Parse(path string, tempPath string, debug bool) error {
diff --git a/common/cache.go b/v2/common/cache.go
similarity index 87%
rename from common/cache.go
rename to v2/common/cache.go
index 90cf70b8..fe5eaebc 100644
--- a/common/cache.go
+++ b/v2/common/cache.go
@@ -8,6 +8,7 @@ import (
"os"
"time"
+ "github.com/hiddify/hiddify-core/v2/service_manager"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/bbolt"
@@ -19,7 +20,7 @@ import (
)
var (
- Storage = New(context.Background(), option.CacheFileOptions{})
+ Storage CacheFile
bucketExtension = []byte("extension")
bucketHiddify = []byte("hiddify")
@@ -29,6 +30,24 @@ var (
}
)
+type StorageService struct {
+ // Storage *CacheFile
+}
+
+func (s *StorageService) Start() error {
+ Storage = *NewStorage(context.Background(), option.CacheFileOptions{})
+ return nil
+}
+
+func (s *StorageService) Close() error {
+ Storage.DB.Close()
+ return nil
+}
+
+func init() {
+ service_manager.RegisterPreservice(&StorageService{})
+}
+
type CacheFile struct {
ctx context.Context
path string
@@ -37,7 +56,7 @@ type CacheFile struct {
DB *bbolt.DB
}
-func New(ctx context.Context, options option.CacheFileOptions) *CacheFile {
+func NewStorage(ctx context.Context, options option.CacheFileOptions) *CacheFile {
var path string
if options.Path != "" {
path = options.Path
diff --git a/common/utils.go b/v2/common/utils.go
similarity index 100%
rename from common/utils.go
rename to v2/common/utils.go
diff --git a/v2/grpc_server.go b/v2/grpc_server.go
index e38a19d4..28810c71 100644
--- a/v2/grpc_server.go
+++ b/v2/grpc_server.go
@@ -35,7 +35,6 @@ func StartGrpcServer(listenAddressG string, service string) (*grpc.Server, error
if service == "core" {
// Setup("./tmp/", "./tmp", "./tmp", 11111, false)
- Setup("./tmp", "./", "./tmp", 0, false)
useFlutterBridge = false
pb.RegisterCoreServer(s, &CoreService{})
diff --git a/v2/service.go b/v2/service.go
index eceac3f2..a5273310 100644
--- a/v2/service.go
+++ b/v2/service.go
@@ -8,6 +8,8 @@ import (
runtimeDebug "runtime/debug"
"time"
+ "github.com/hiddify/hiddify-core/v2/service_manager"
+
B "github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/common/urltest"
"github.com/sagernet/sing-box/experimental/libbox"
@@ -27,9 +29,13 @@ var (
statusPropagationPort int64
)
+func InitHiddifyService() error {
+ return service_manager.StartServices()
+}
+
func Setup(basePath string, workingPath string, tempPath string, statusPort int64, debug bool) error {
statusPropagationPort = int64(statusPort)
- tcpConn := runtime.GOOS == "windows" //TODO add TVOS
+ tcpConn := runtime.GOOS == "windows" // TODO add TVOS
libbox.Setup(basePath, workingPath, tempPath, tcpConn)
sWorkingPath = workingPath
os.Chdir(sWorkingPath)
@@ -53,7 +59,11 @@ func Setup(basePath string, workingPath string, tempPath string, statusPort int6
// },
})
coreLogFactory = factory
- return err
+
+ if err != nil {
+ return E.Cause(err, "create logger")
+ }
+ return InitHiddifyService()
}
func NewService(options option.Options) (*libbox.BoxService, error) {
diff --git a/v2/service_manager/hiddify.go b/v2/service_manager/hiddify.go
new file mode 100644
index 00000000..aa985c71
--- /dev/null
+++ b/v2/service_manager/hiddify.go
@@ -0,0 +1,46 @@
+package service_manager
+
+import (
+ "github.com/sagernet/sing-box/adapter"
+)
+
+var (
+ services = []adapter.Service{}
+ preservices = []adapter.Service{}
+)
+
+func RegisterPreservice(service adapter.Service) {
+ preservices = append(services, service)
+}
+
+func Register(service adapter.Service) {
+ services = append(services, service)
+}
+
+func StartServices() error {
+ for _, service := range preservices {
+ if err := service.Start(); err != nil {
+ return err
+ }
+ }
+ for _, service := range services {
+ if err := service.Start(); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func CloseServices() error {
+ for _, service := range services {
+ if err := service.Close(); err != nil {
+ return err
+ }
+ }
+ for _, service := range preservices {
+ if err := service.Close(); err != nil {
+ return err
+ }
+ }
+ return nil
+}