Skip to content

Commit

Permalink
new: big changes, stablity and more
Browse files Browse the repository at this point in the history
  • Loading branch information
x committed Nov 10, 2024
1 parent a3c205c commit e895661
Show file tree
Hide file tree
Showing 29 changed files with 1,060 additions and 662 deletions.
81 changes: 81 additions & 0 deletions cmd/cmd_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cmd

import (
"context"
"log"
"time"

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

"github.com/spf13/cobra"
"google.golang.org/grpc"
)

var execCommand = &cobra.Command{
Use: "command",
Short: "command",
Args: cobra.OnlyValidArgs,
Run: execCommandgrpc,
}

func init() {
// commandRun.PersistentFlags().BoolP("help", "", false, "help for this command")
// commandRun.Flags().StringVarP(&hiddifySettingPath, "hiddify", "d", "", "Hiddify Setting JSON Path")

mainCommand.AddCommand(execCommand)
}

func execCommandgrpc(cmd *cobra.Command, args []string) {
conn, err := grpc.Dial("127.0.0.1:17078", grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := hcore.NewCoreClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), time.Second*100)
defer cancel()
tream, err := c.CoreInfoListener(ctx, &hcommon.Empty{})
stream2, err := c.OutboundsInfo(ctx, &hcommon.Empty{})
stream, err := c.MainOutboundsInfo(ctx, &hcommon.Empty{})
logstream, err := c.LogListener(ctx, &hcommon.Empty{})
if err != nil {
log.Fatalf("could not stream: %v", err)
}

go coreLogger(tream, "coreinfo")
go coreLogger(stream2, "alloutbounds")
go coreLogger(stream, "mainoutbounds")
go coreLogger(logstream, "log")
for _, x := range []string{
"m4 § 0",
"warp in warp § 1",
"LocalIP § 2",
"WarpInWarp✅ § 3",
} {
c.UrlTest(ctx, &hcore.UrlTestRequest{GroupTag: "auto"})
log.Printf("Sending: %s", x)
resp, err := c.SelectOutbound(ctx, &hcore.SelectOutboundRequest{
GroupTag: "select",
OutboundTag: x,
})
if err != nil {
log.Fatalf("could not greet: %s %v", x, err)
}

log.Printf("Received: %s %v", x, resp)
<-time.After(1 * time.Second)
}
<-time.After(10 * time.Second)
}

func coreLogger[T any](stream grpc.ServerStreamingClient[T], name string) {
for {
c, err := stream.Recv()
if err != nil {
log.Printf("could not receive %s : %v", name, err)
}
log.Printf("Received: %s, %v", name, c)
}
}
4 changes: 2 additions & 2 deletions cmd/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func init() {

func runCommand(cmd *cobra.Command, args []string) {
hcore.Setup(
hcore.SetupParameters{
&hcore.SetupRequest{
BasePath: "./tmp",
WorkingDir: "./",
TempDir: "./tmp",
FlutterStatusPort: 0,
Debug: false,
Mode: hcore.GRPC_NORMAL_INSECURE,
Mode: hcore.SetupMode_GRPC_NORMAL_INSECURE,
Listen: "127.0.0.1:17078",
},
)
Expand Down
75 changes: 32 additions & 43 deletions cmd/cmd_temp.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,34 @@
package cmd

import (
"context"
"log"
"os"
"time"

"github.com/hiddify/hiddify-core/v2/hcommon"
hcore "github.com/hiddify/hiddify-core/v2/hcore"
"google.golang.org/grpc"
)

const (
address = "localhost:17078"
defaultName = "world"
)

func init() {
if os.Args[1] == "test" {
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := hcore.NewCoreClient(conn)

// ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
// defer cancel()
ctx := context.Background()

// SayHello
stream, err := c.OutboundsInfo(ctx, &hcommon.Empty{})

for {
r, err := stream.Recv()
if err != nil {
log.Fatalf("could not receive: %v", err)
}
log.Printf("Received1: %s", r.String())

time.Sleep(1 * time.Second)
}
}
}
// const (
// address = "localhost:17078"
// defaultName = "world"
// )

// // func init() {
// // if len(os.Args) > 1 && os.Args[1] == "test" {
// // conn, err := grpc.Dial(address, grpc.WithInsecure())
// // if err != nil {
// // log.Fatalf("did not connect: %v", err)
// // }
// // defer conn.Close()
// // c := hcore.NewCoreClient(conn)

// // ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
// // defer cancel()
// ctx := context.Background()

// // SayHello
// stream, err := c.OutboundsInfo(ctx, &hcommon.Empty{})

// for {
// r, err := stream.Recv()
// if err != nil {
// log.Fatalf("could not receive: %v", err)
// }
// log.Printf("Received1: %s", r.String())

// time.Sleep(1 * time.Second)
// }
// }
// }
30 changes: 26 additions & 4 deletions docs/hiddifyrpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [LogLevel](#hcore-LogLevel)
- [LogType](#hcore-LogType)
- [MessageType](#hcore-MessageType)
- [SetupMode](#hcore-SetupMode)

- [v2/hcore/hcore_service.proto](#v2_hcore_hcore_service-proto)
- [Core](#hcore-Core)
Expand Down Expand Up @@ -281,9 +282,10 @@
| type | [string](#string) | | |
| url_test_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| url_test_delay | [int32](#int32) | | |
| ipinfo | [IpInfo](#hcore-IpInfo) | | |
| ipinfo | [IpInfo](#hcore-IpInfo) | optional | |
| is_selected | [bool](#bool) | | |
| is_group | [bool](#bool) | | |
| group_selected_outbound | [OutboundInfo](#hcore-OutboundInfo) | optional | |
| is_secure | [bool](#bool) | | |
| is_visible | [bool](#bool) | | |
| port | [uint32](#uint32) | | |
Expand Down Expand Up @@ -364,14 +366,19 @@
<a name="hcore-SetupRequest"></a>

### SetupRequest

Define the message equivalent of SetupParameters


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| base_path | [string](#string) | | |
| working_path | [string](#string) | | |
| temp_path | [string](#string) | | |
| working_dir | [string](#string) | | |
| temp_dir | [string](#string) | | |
| flutter_status_port | [int64](#int64) | | |
| listen | [string](#string) | | |
| secret | [string](#string) | | |
| debug | [bool](#bool) | | |
| mode | [SetupMode](#hcore-SetupMode) | | |



Expand Down Expand Up @@ -582,6 +589,21 @@
| ERROR_EXTENSION | 14 | |



<a name="hcore-SetupMode"></a>

### SetupMode


| Name | Number | Description |
| ---- | ------ | ----------- |
| OLD | 0 | |
| GRPC_NORMAL | 1 | |
| GRPC_BACKGROUND | 2 | |
| GRPC_NORMAL_INSECURE | 3 | |
| GRPC_BACKGROUND_INSECURE | 4 | |





Expand Down
4 changes: 2 additions & 2 deletions extension/server/run_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (

func StartTestExtensionServer() {
hcore.Setup(
hcore.SetupParameters{
&hcore.SetupRequest{
BasePath: "./tmp",
WorkingDir: "./",
TempDir: "./tmp",
FlutterStatusPort: 0,
Listen: "",
Secret: "",
Debug: false,
Mode: hcore.OLD,
Mode: hcore.SetupMode_OLD,
},
)
// "./tmp", "./", "./tmp", 0, false)
Expand Down
21 changes: 11 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ require (
github.com/sagernet/sing-dns v0.2.3
github.com/spf13/cobra v1.8.0
github.com/xmdhs/clash2singbox v0.0.2
golang.org/x/sys v0.25.0
google.golang.org/grpc v1.67.0
google.golang.org/protobuf v1.34.2
golang.org/x/sys v0.26.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -186,6 +186,7 @@ require (

require (
github.com/DataDog/zstd v1.4.1 // indirect
github.com/biter777/countries v1.7.5 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
Expand Down Expand Up @@ -254,7 +255,7 @@ require (
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/pires/go-proxyproto v0.8.0 // 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
Expand Down Expand Up @@ -289,25 +290,25 @@ require (
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.27.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.29.0
golang.org/x/net v0.30.0
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/text v0.19.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-20240814211410-ddb44dafa142 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
)

replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20241020111745-22b807080fe7
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20241110203637-1f1d31677f7f

replace github.com/xtls/xray-core => github.com/hiddify/xray-core v0.0.0-20241019134126-3f94892df016
replace github.com/xtls/xray-core => github.com/hiddify/xray-core v0.0.0-20241110202159-0fd7ffea9361

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
replace github.com/hiddify/ray2sing => github.com/hiddify/ray2sing v0.0.0-20241110203152-4c6984597d36
Loading

0 comments on commit e895661

Please sign in to comment.