Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Oct 15, 2024
1 parent 53e3ad8 commit 332d5b2
Show file tree
Hide file tree
Showing 22 changed files with 1,061 additions and 227 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches:
- main
- dev
- android-fix-action-bug
- v3
paths-ignore:
- '**.md'
- 'docs/**'
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ headers:
go build -buildmode=c-archive -o $(BINDIR)/$(LIBNAME).h ./custom

android: lib_install
gomobile bind -v -androidapi=21 -javapkg=io.nekohasekai -libname=box -tags=$(TAGS) -trimpath -target=android -o $(BINDIR)/$(LIBNAME).aar github.com/sagernet/sing-box/experimental/libbox ./mobile
gomobile bind -v -androidapi=21 -javapkg=io.nekohasekai -libname=box -tags=$(TAGS) -trimpath -target=android -o $(BINDIR)/$(LIBNAME).aar github.com/sagernet/sing-box/experimental/libbox
#./mobile

ios-full: lib_install
gomobile bind -v -target ios,iossimulator,tvos,tvossimulator,macos -libname=box -tags=$(TAGS),$(IOS_ADD_TAGS) -trimpath -ldflags="-w -s" -o $(BINDIR)/$(PRODUCT_NAME).xcframework github.com/sagernet/sing-box/experimental/libbox ./mobile
Expand Down
24 changes: 23 additions & 1 deletion cmd/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
hcore "github.com/hiddify/hiddify-core/v2/hcore"

"github.com/spf13/cobra"
)

Expand All @@ -22,6 +23,27 @@ func init() {
}

func runCommand(cmd *cobra.Command, args []string) {
hcore.Setup("./tmp", "./", "./tmp", 0, false)
hcore.Setup(
hcore.SetupParameters{
BasePath: "./tmp",
WorkingDir: "./",
TempDir: "./tmp",
FlutterStatusPort: 0,
Debug: false,
Mode: hcore.GRPC_BOTH,
Listen: "127.0.0.1:17078",
},
)
// conn, err := grpc.Dial("127.0.0.1:17078", grpc.WithInsecure())
// if err != nil {
// fmt.Printf("did not connect: %v", err)
// }
// defer conn.Close()
// c := hello.NewHelloClient(conn)
// ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
// defer cancel()
// res, err := c.SayHello(ctx, &hello.HelloRequest{Name: "test"})
// fmt.Println(res, err)
// <-time.After(10 * time.Second)
hcore.RunStandalone(hiddifySettingPath, configPath, defaultConfigs)
}
47 changes: 36 additions & 11 deletions custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/hiddify/hiddify-core/bridge"
"github.com/hiddify/hiddify-core/config"
pb "github.com/hiddify/hiddify-core/hiddifyrpc"

hcore "github.com/hiddify/hiddify-core/v2/hcore"

"github.com/sagernet/sing-box/log"
Expand All @@ -25,14 +25,24 @@ 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 := hcore.Setup(C.GoString(baseDir), C.GoString(workingDir), C.GoString(tempDir), int64(statusPort), debug)
func setup(baseDir *C.char, workingDir *C.char, tempDir *C.char, mode C.int, listen *C.char, secret *C.char, statusPort C.longlong, debug bool) (CErr *C.char) {
// err := hcore.Setup(C.GoString(baseDir), C.GoString(workingDir), C.GoString(tempDir), int64(statusPort), debug)
err := hcore.Setup(hcore.SetupParameters{
BasePath: C.GoString(baseDir),
WorkingDir: C.GoString(workingDir),
TempDir: C.GoString(tempDir),
FlutterStatusPort: int64(statusPort),
Debug: debug,
Mode: hcore.SetupMode(mode),
Listen: C.GoString(listen),
Secret: C.GoString(secret),
})
return emptyOrErrorC(err)
}

//export parse
func parse(path *C.char, tempPath *C.char, debug bool) (CErr *C.char) {
res, err := hcore.Parse(&pb.ParseRequest{
res, err := hcore.Parse(&hcore.ParseRequest{
ConfigPath: C.GoString(path),
TempPath: C.GoString(tempPath),
})
Expand All @@ -47,15 +57,15 @@ func parse(path *C.char, tempPath *C.char, debug bool) (CErr *C.char) {

//export changeHiddifyOptions
func changeHiddifyOptions(HiddifyOptionsJson *C.char) (CErr *C.char) {
_, err := hcore.ChangeHiddifySettings(&pb.ChangeHiddifySettingsRequest{
_, err := hcore.ChangeHiddifySettings(&hcore.ChangeHiddifySettingsRequest{
HiddifySettingsJson: C.GoString(HiddifyOptionsJson),
})
return emptyOrErrorC(err)
}

//export generateConfig
func generateConfig(path *C.char) (res *C.char) {
conf, err := hcore.GenerateConfig(&pb.GenerateConfigRequest{
conf, err := hcore.GenerateConfig(&hcore.GenerateConfigRequest{
Path: C.GoString(path),
})
if err != nil {
Expand All @@ -68,7 +78,7 @@ func generateConfig(path *C.char) (res *C.char) {

//export start
func start(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
_, err := hcore.Start(&pb.StartRequest{
_, err := hcore.Start(&hcore.StartRequest{
ConfigPath: C.GoString(configPath),
EnableOldCommandServer: true,
DisableMemoryLimit: disableMemoryLimit,
Expand All @@ -84,7 +94,7 @@ func stop() (CErr *C.char) {

//export restart
func restart(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
_, err := hcore.Restart(&pb.StartRequest{
_, err := hcore.Restart(&hcore.StartRequest{
ConfigPath: C.GoString(configPath),
EnableOldCommandServer: true,
DisableMemoryLimit: disableMemoryLimit,
Expand All @@ -106,7 +116,7 @@ func stopCommandClient(command C.int) *C.char {

//export selectOutbound
func selectOutbound(groupTag *C.char, outboundTag *C.char) (CErr *C.char) {
_, err := hcore.SelectOutbound(&pb.SelectOutboundRequest{
_, err := hcore.SelectOutbound(&hcore.SelectOutboundRequest{
GroupTag: C.GoString(groupTag),
OutboundTag: C.GoString(outboundTag),
})
Expand All @@ -116,7 +126,7 @@ func selectOutbound(groupTag *C.char, outboundTag *C.char) (CErr *C.char) {

//export urlTest
func urlTest(groupTag *C.char) (CErr *C.char) {
_, err := hcore.UrlTest(&pb.UrlTestRequest{
_, err := hcore.UrlTest(&hcore.UrlTestRequest{
GroupTag: C.GoString(groupTag),
})

Expand All @@ -133,7 +143,7 @@ func emptyOrErrorC(err error) *C.char {

//export generateWarpConfig
func generateWarpConfig(licenseKey *C.char, accountId *C.char, accessToken *C.char) (CResp *C.char) {
res, err := hcore.GenerateWarpConfig(&pb.GenerateWarpConfigRequest{
res, err := hcore.GenerateWarpConfig(&hcore.GenerateWarpConfigRequest{
LicenseKey: C.GoString(licenseKey),
AccountId: C.GoString(accountId),
AccessToken: C.GoString(accessToken),
Expand Down Expand Up @@ -167,3 +177,18 @@ func generateWarpConfig(licenseKey *C.char, accountId *C.char, accessToken *C.ch
}

func main() {}

//export GetServerPublicKey
func GetServerPublicKey() []byte {
return hcore.GetGrpcServerPublicKey()
}

//export AddGrpcClientPublicKey
func AddGrpcClientPublicKey(clientPublicKey []byte) error {
return hcore.AddGrpcClientPublicKey(clientPublicKey)
}

//export close
func close() {
hcore.Close()
}
14 changes: 13 additions & 1 deletion extension/server/run_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ import (
)

func StartTestExtensionServer() {
hcore.Setup("./tmp", "./", "./tmp", 0, false)
hcore.Setup(
hcore.SetupParameters{
BasePath: "./tmp",
WorkingDir: "./",
TempDir: "./tmp",
FlutterStatusPort: 0,
Listen: "",
Secret: "",
Debug: false,
Mode: hcore.OLD,
},
)
// "./tmp", "./", "./tmp", 0, false)
StartExtensionServer()
}

Expand Down
Loading

0 comments on commit 332d5b2

Please sign in to comment.