Skip to content

Commit

Permalink
improvements and add saved config
Browse files Browse the repository at this point in the history
  • Loading branch information
x committed Dec 29, 2024
1 parent 8505e47 commit 55a70ff
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ require (
lukechampine.com/blake3 v1.3.0 // indirect
)

replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20241224082119-1aa6bc1919b9
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20241229165737-711ea7a9f7b2

replace github.com/xtls/xray-core => github.com/hiddify/xray-core v0.0.0-20241219203851-cd7ad9af63bd

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8
github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb h1:PGufWXXDq9yaev6xX1YQauaO1MV90e6Mpoq1I7Lz/VM=
github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb/go.mod h1:QiyDdbZLaJ/mZP4Zwc9g2QsfaEA4o7XvvgZegSci5/E=
github.com/hiddify/hiddify-sing-box v1.8.9-0.20241224082119-1aa6bc1919b9 h1:Nx3nQS/0VeaBD8ZolNnbO91BrYSZ6NQj2H9Ia3YIIS0=
github.com/hiddify/hiddify-sing-box v1.8.9-0.20241224082119-1aa6bc1919b9/go.mod h1:u16dzx+T4FD39c223mKWT0H0mcHhVRpQaBlN34dPXMk=
github.com/hiddify/hiddify-sing-box v1.8.9-0.20241229165737-711ea7a9f7b2 h1:ofbqvCRR39WDY/5Q+Hpr04ZP+YUqAwzchlkkLOs59V8=
github.com/hiddify/hiddify-sing-box v1.8.9-0.20241229165737-711ea7a9f7b2/go.mod h1:u16dzx+T4FD39c223mKWT0H0mcHhVRpQaBlN34dPXMk=
github.com/hiddify/ray2sing v0.0.0-20241219213739-113036bccaba h1:q28rvz9DROJ6P07DlLbSx6cxR00lVp2GYuSCn3WDrpU=
github.com/hiddify/ray2sing v0.0.0-20241219213739-113036bccaba/go.mod h1:soYE48y/Q2HtgRFpcX6LcekVyigy7IELYw4fmIGwLSA=
github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d h1:vRGKh9ou+/vQGfVYa8MczhbIVjHxlP52OWwrDWO77RA=
Expand Down
4 changes: 2 additions & 2 deletions v2/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func getHostnameIfNotIP(inp string) (string, error) {
func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOptions) error {
var outbounds []option.Outbound
var tags []string
OutboundMainProxyTag = OutboundSelectTag
// OutboundMainProxyTag = OutboundSelectTag
// inbound==warp over proxies
// outbound==proxies over warp
if opt.Warp.EnableWarp {
Expand Down Expand Up @@ -125,7 +125,7 @@ func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOp
out.Tag = "Hiddify Warp ✅"
if opt.Warp.Mode == "warp_over_proxy" {
out.WireGuardOptions.Detour = OutboundSelectTag
OutboundMainProxyTag = out.Tag
options.Route.Final = out.Tag
} else {
out.WireGuardOptions.Detour = OutboundDirectTag
}
Expand Down
3 changes: 0 additions & 3 deletions v2/hcore/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ func Restart(in *StartRequest) (coreResponse *CoreInfoResponse, err error) {
coreResponse, err = errorWrapper(MessageType_UNEXPECTED_ERROR, recovered_err)
})
log.Debug("[Service] Restarting")
if in.ConfigContent == "" && in.ConfigPath == "" {
in = previousStartRequest
}
if static.CoreState != CoreStates_STARTED {
return errorWrapper(MessageType_INSTANCE_NOT_STARTED, fmt.Errorf("instance not started"))
}
Expand Down
45 changes: 45 additions & 0 deletions v2/hcore/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"time"

"github.com/hiddify/hiddify-core/v2/config"
"github.com/hiddify/hiddify-core/v2/db"
hcommon "github.com/hiddify/hiddify-core/v2/hcommon"
service_manager "github.com/hiddify/hiddify-core/v2/service_manager"
box "github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/experimental/libbox"
Expand All @@ -24,13 +26,56 @@ func (s *CoreService) StartService(ctx context.Context, in *StartRequest) (*Core
return StartService(in)
}

func saveLastStartRequest(in *StartRequest) error {
if in.ConfigContent == "" && in.ConfigPath == "" {
return nil
}
settings := db.GetTable[hcommon.AppSettings]()
return settings.UpdateInsert(
&hcommon.AppSettings{
Id: "lastStartRequestPath",
Value: in.ConfigPath,
},
&hcommon.AppSettings{
Id: "lastStartRequestContent",
Value: in.ConfigContent,
},
)
}

func loadLastStartRequestIfNeeded(in *StartRequest) (*StartRequest, error) {
if in.ConfigContent != "" || in.ConfigPath != "" {
return in, nil
}
settings := db.GetTable[hcommon.AppSettings]()
lastPath, err := settings.Get("lastStartRequestPath")
if err != nil {
return nil, err
}
lastContent, err := settings.Get("lastStartRequestContent")
if err != nil {
return nil, err
}
return &StartRequest{
ConfigPath: lastPath.Value.(string),
ConfigContent: lastContent.Value.(string),
}, nil
}

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, "")

in, err = loadLastStartRequestIfNeeded(in)
if err != nil {
return errorWrapper(MessageType_ERROR_BUILDING_CONFIG, err)
}

previousStartRequest = in
options, err := BuildConfig(in)
saveLastStartRequest(in)
if err != nil {
return errorWrapper(MessageType_ERROR_BUILDING_CONFIG, err)
}
Expand Down

0 comments on commit 55a70ff

Please sign in to comment.