new: add hiddifyrpc

This commit is contained in:
Hiddify
2024-03-03 04:15:19 +01:00
parent 0aa2c99599
commit a4b067006a
22 changed files with 3715 additions and 29 deletions

View File

@@ -69,6 +69,9 @@ macos-universal: macos-amd64 macos-arm64
clean:
rm $(BINDIR)/*
build_protobuf:
protoc --go_out=. --go-grpc_out=. hiddifyrpc/hiddify.proto
release: # Create a new tag for release.
@echo "previous version was $$(git describe --tags $$(git rev-list --tags --max-count=1))"

View File

@@ -46,7 +46,7 @@ func getCurrentExecutableDirectory() string {
}
func StartService(goArg string) (int, string) {
svcConfig := &service.Config{
Name: "Hiddify Tunnel Service",
Name: "HiddifyTunnelService",
DisplayName: "Hiddify Tunnel Service",
Description: "This is a bridge for tunnel",
Option: map[string]interface{}{

View File

@@ -2,6 +2,7 @@ package config
import (
"bytes"
"runtime"
"encoding/json"
"fmt"
@@ -149,6 +150,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
AutoRoute: true,
StrictRoute: opt.StrictRoute,
EndpointIndependentNat: true,
GSO: runtime.GOOS != "windows",
InboundOptions: option.InboundOptions{
SniffEnabled: true,
SniffOverrideDestination: true,

View File

@@ -175,6 +175,9 @@ func patchWarp(base *option.Outbound) error {
if base.WireGuardOptions.ServerPort == 0 {
base.WireGuardOptions.ServerPort = generateRandomPort()
}
// if base.WireGuardOptions.Detour == "" {
// base.WireGuardOptions.GSO = runtime.GOOS != "windows"
// }
}
if base.Type == C.TypeCustom {
if warp, ok := base.CustomOptions["warp"].(map[string]interface{}); ok {

View File

@@ -29,6 +29,10 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
if err != nil {
return nil, err
}
return ParseConfigContent(string(content), debug)
}
func ParseConfigContent(contentstr string, debug bool) ([]byte, error) {
content := []byte(contentstr)
var jsonObj map[string]interface{} = make(map[string]interface{})
fmt.Printf("Convert using json\n")

View File

@@ -1,8 +1,11 @@
package main
import (
pb "github.com/hiddify/libcore/hiddifyrpc"
v2 "github.com/hiddify/libcore/v2"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/log"
)
var commandServer *libbox.CommandServer
@@ -13,14 +16,14 @@ type CommandServerHandler struct {
func (csh *CommandServerHandler) ServiceReload() error {
csh.logger.Trace("Reloading service")
propagateStatus(Starting)
propagateStatus(pb.CoreState_STARTING)
if commandServer != nil {
commandServer.SetService(nil)
commandServer = nil
}
if box != nil {
box.Close()
box = nil
if v2.Box != nil {
v2.Box.Close()
v2.Box = nil
}
return startService(true)
}

View File

@@ -15,12 +15,15 @@ import (
"github.com/hiddify/libcore/bridge"
"github.com/hiddify/libcore/config"
pb "github.com/hiddify/libcore/hiddifyrpc"
v2 "github.com/hiddify/libcore/v2"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
)
var box *libbox.BoxService
// var v2.Box *libbox.BoxService
var configOptions *config.ConfigOptions
var activeConfigPath *string
var logFactory *log.Factory
@@ -132,10 +135,10 @@ func start(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
CErr = C.CString(err.Error())
})
if status != Stopped {
if v2.CoreState != pb.CoreState_STOPPED {
return C.CString("")
}
propagateStatus(Starting)
propagateStatus(pb.CoreState_STARTING)
path := C.GoString(configPath)
activeConfigPath = &path
@@ -184,10 +187,10 @@ func startService(delayStart bool) error {
if err != nil {
return stopAndAlert(StartService, err)
}
box = instance
commandServer.SetService(box)
v2.Box = instance
commandServer.SetService(v2.Box)
propagateStatus(Started)
propagateStatus(pb.CoreState_STARTED)
return nil
}
@@ -198,29 +201,29 @@ func stop() (CErr *C.char) {
CErr = C.CString(err.Error())
})
config.DeactivateTunnelService()
if status != Started {
if v2.CoreState != pb.CoreState_STARTED {
stopAndAlert("Already Stopped", nil)
return C.CString("")
}
if box == nil {
if v2.Box == nil {
return C.CString("instance not found")
}
propagateStatus(Stopping)
propagateStatus(pb.CoreState_STOPPING)
commandServer.SetService(nil)
err := box.Close()
err := v2.Box.Close()
if err != nil {
stopAndAlert("Unexpected Error in Close!", err)
return C.CString(err.Error())
}
box = nil
v2.Box = nil
err = commandServer.Close()
if err != nil {
stopAndAlert("Unexpected Error in Stop CommandServer/!", err)
return C.CString(err.Error())
}
commandServer = nil
propagateStatus(Stopped)
propagateStatus(pb.CoreState_STOPPED)
return C.CString("")
}
@@ -232,10 +235,10 @@ func restart(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
})
log.Debug("[Service] Restarting")
if status != Started {
if v2.CoreState != pb.CoreState_STARTED {
return C.CString("")
}
if box == nil {
if v2.Box == nil {
return C.CString("instance not found")
}
@@ -244,7 +247,7 @@ func restart(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
return err
}
propagateStatus(Starting)
propagateStatus(pb.CoreState_STARTING)
time.Sleep(250 * time.Millisecond)

View File

@@ -7,10 +7,13 @@ import (
"github.com/hiddify/libcore/bridge"
"github.com/hiddify/libcore/config"
pb "github.com/hiddify/libcore/hiddifyrpc"
v2 "github.com/hiddify/libcore/v2"
)
var statusPropagationPort int64
var status = Stopped
// var status = Stopped
type StatusMessage struct {
Status string `json:"status"`
@@ -18,30 +21,46 @@ type StatusMessage struct {
Message *string `json:"message"`
}
func propagateStatus(newStatus string) {
status = newStatus
func propagateStatus(newStatus pb.CoreState) {
v2.CoreState = newStatus
msg, _ := json.Marshal(StatusMessage{Status: status})
msg, _ := json.Marshal(StatusMessage{Status: convert2OldState(v2.CoreState)})
bridge.SendStringToPort(statusPropagationPort, string(msg))
}
func convert2OldState(newStatus pb.CoreState) string {
if newStatus == pb.CoreState_STOPPED {
return Stopped
}
if newStatus == pb.CoreState_STARTED {
return Started
}
if newStatus == pb.CoreState_STARTING {
return Starting
}
if newStatus == pb.CoreState_STOPPING {
return Stopping
}
return "Invalid"
}
func stopAndAlert(alert string, err error) (resultErr error) {
defer config.DeferPanicToError("stopAndAlert", func(err error) {
resultErr = err
})
status = Stopped
v2.CoreState = pb.CoreState_STOPPED
message := err.Error()
fmt.Printf("Error: %s: %s\n", alert, message)
msg, _ := json.Marshal(StatusMessage{Status: status, Alert: &alert, Message: &message})
msg, _ := json.Marshal(StatusMessage{Status: convert2OldState(v2.CoreState), Alert: &alert, Message: &message})
bridge.SendStringToPort(statusPropagationPort, string(msg))
config.DeactivateTunnelService()
if commandServer != nil {
commandServer.SetService(nil)
}
if box != nil {
box.Close()
box = nil
if v2.Box != nil {
v2.Box.Close()
v2.Box = nil
}
if commandServer != nil {
commandServer.Close()

1662
hiddifyrpc/hiddify.pb.go Normal file

File diff suppressed because it is too large Load Diff

214
hiddifyrpc/hiddify.proto Normal file
View File

@@ -0,0 +1,214 @@
syntax = "proto3";
package hiddifyrpc;
option go_package = "./hiddifyrpc";
enum ResponseCode {
OK = 0;
FAILED = 1;
}
enum CoreState {
STOPPED = 0;
STARTING = 1;
STARTED = 2;
STOPPING = 3;
}
enum MessageType {
EMPTY=0;
EMPTY_CONFIGURATION = 1;
START_COMMAND_SERVER = 2;
CREATE_SERVICE = 3;
START_SERVICE = 4;
UNEXPECTED_ERROR = 5;
ALREADY_STARTED = 6;
ALREADY_STOPPED = 7;
INSTANCE_NOT_FOUND = 8;
INSTANCE_NOT_STOPPED = 9;
INSTANCE_NOT_STARTED = 10;
ERROR_BUILDING_CONFIG = 11;
ERROR_PARSING_CONFIG = 12;
ERROR_READING_CONFIG = 13;
}
message CoreInfoResponse {
CoreState core_state = 1;
MessageType message_type = 2;
string message = 3;
}
message StartRequest {
string config_path = 1;
string config_content = 2; // Optional if configPath is not provided.
bool disable_memory_limit = 3;
bool delay_start = 4;
}
message SetupRequest {
string base_path = 1;
string working_path = 2;
string temp_path = 3;
}
message Response {
ResponseCode response_code = 1;
string message = 2;
}
message HelloRequest {
string name = 1;
}
message HelloResponse {
string message = 1;
}
message Empty {
}
message SystemInfo {
int64 memory = 1;
int32 goroutines = 2;
int32 connections_in = 3;
int32 connections_out = 4;
bool traffic_available = 5;
int64 uplink = 6;
int64 downlink = 7;
int64 uplink_total = 8;
int64 downlink_total = 9;
}
message OutboundGroupItem {
string tag = 1;
string type = 2;
int64 url_test_time = 3;
int32 url_test_delay = 4;
}
message OutboundGroup {
string tag = 1;
string type = 2;
string selected=3;
repeated OutboundGroupItem items = 4;
}
message OutboundGroupList{
repeated OutboundGroup items = 1;
}
message WarpAccount {
string account_id = 1;
string access_token = 2;
}
message WarpWireguardConfig {
string private_key = 1;
string local_address_ipv4 = 2;
string local_address_ipv6 = 3;
string peer_public_key = 4;
}
message WarpGenerationResponse {
WarpAccount account = 1;
string log = 2;
WarpWireguardConfig config = 3;
}
message SystemProxyStatus {
bool available = 1;
bool enabled = 2;
}
message ParseRequest {
string content = 1;
bool debug = 2;
}
message ParseResponse {
ResponseCode response_code = 1;
string content = 2;
string message = 3;
}
message ChangeConfigOptionsRequest {
string config_options_json = 1;
}
message GenerateConfigRequest {
string path = 1;
string temp_path = 2;
bool debug = 3;
}
message GenerateConfigResponse {
string config_content = 1;
}
message SelectOutboundRequest {
string group_tag = 1;
string outbound_tag = 2;
}
message UrlTestRequest {
string group_tag = 1;
}
message GenerateWarpConfigRequest {
string license_key = 1;
string account_id = 2;
string access_token = 3;
}
message SetSystemProxyEnabledRequest {
bool is_enabled = 1;
}
enum LogLevel {
DEBUG = 0;
INFO = 1;
WARNING = 2;
ERROR = 3;
FATAL = 4;
}
enum LogType {
CORE = 0;
SERVICE = 1;
CONFIG = 2;
}
message LogMessage {
LogLevel level = 1;
LogType type = 2;
string message = 3;
}
message StopRequest{
}
service Hiddify {
rpc SayHello (HelloRequest) returns (HelloResponse);
rpc SayHelloStream (stream HelloRequest) returns (stream HelloResponse);
rpc Start (StartRequest) returns (CoreInfoResponse);
rpc CoreInfoListener (stream StopRequest) returns (stream CoreInfoResponse);
rpc OutboundsInfo (stream StopRequest) returns (stream OutboundGroupList);
rpc MainOutboundsInfo (stream StopRequest) returns (stream OutboundGroupList);
rpc GetSystemInfo (stream StopRequest) returns (stream SystemInfo);
rpc Setup (SetupRequest) returns (Response);
rpc Parse (ParseRequest) returns (ParseResponse);
//rpc ChangeConfigOptions (ChangeConfigOptionsRequest) returns (CoreInfoResponse);
//rpc GenerateConfig (GenerateConfigRequest) returns (GenerateConfigResponse);
rpc StartService (StartRequest) returns (CoreInfoResponse);
rpc Stop (Empty) returns (CoreInfoResponse);
rpc Restart (StartRequest) returns (CoreInfoResponse);
rpc SelectOutbound (SelectOutboundRequest) returns (Response);
rpc UrlTest (UrlTestRequest) returns (Response);
rpc GenerateWarpConfig (GenerateWarpConfigRequest) returns (WarpGenerationResponse);
rpc GetSystemProxyStatus (Empty) returns (SystemProxyStatus);
rpc SetSystemProxyEnabled (SetSystemProxyEnabledRequest) returns (Response);
rpc LogListener (stream StopRequest) returns (stream LogMessage);
}

View File

@@ -0,0 +1,935 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc v3.6.1
// source: hiddifyrpc/hiddify.proto
package hiddifyrpc
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
Hiddify_SayHello_FullMethodName = "/hiddifyrpc.Hiddify/SayHello"
Hiddify_SayHelloStream_FullMethodName = "/hiddifyrpc.Hiddify/SayHelloStream"
Hiddify_Start_FullMethodName = "/hiddifyrpc.Hiddify/Start"
Hiddify_CoreInfoListener_FullMethodName = "/hiddifyrpc.Hiddify/CoreInfoListener"
Hiddify_OutboundsInfo_FullMethodName = "/hiddifyrpc.Hiddify/OutboundsInfo"
Hiddify_MainOutboundsInfo_FullMethodName = "/hiddifyrpc.Hiddify/MainOutboundsInfo"
Hiddify_GetSystemInfo_FullMethodName = "/hiddifyrpc.Hiddify/GetSystemInfo"
Hiddify_Setup_FullMethodName = "/hiddifyrpc.Hiddify/Setup"
Hiddify_Parse_FullMethodName = "/hiddifyrpc.Hiddify/Parse"
Hiddify_StartService_FullMethodName = "/hiddifyrpc.Hiddify/StartService"
Hiddify_Stop_FullMethodName = "/hiddifyrpc.Hiddify/Stop"
Hiddify_Restart_FullMethodName = "/hiddifyrpc.Hiddify/Restart"
Hiddify_SelectOutbound_FullMethodName = "/hiddifyrpc.Hiddify/SelectOutbound"
Hiddify_UrlTest_FullMethodName = "/hiddifyrpc.Hiddify/UrlTest"
Hiddify_GenerateWarpConfig_FullMethodName = "/hiddifyrpc.Hiddify/GenerateWarpConfig"
Hiddify_GetSystemProxyStatus_FullMethodName = "/hiddifyrpc.Hiddify/GetSystemProxyStatus"
Hiddify_SetSystemProxyEnabled_FullMethodName = "/hiddifyrpc.Hiddify/SetSystemProxyEnabled"
Hiddify_LogListener_FullMethodName = "/hiddifyrpc.Hiddify/LogListener"
)
// HiddifyClient is the client API for Hiddify service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type HiddifyClient interface {
SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error)
SayHelloStream(ctx context.Context, opts ...grpc.CallOption) (Hiddify_SayHelloStreamClient, error)
Start(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (*CoreInfoResponse, error)
CoreInfoListener(ctx context.Context, opts ...grpc.CallOption) (Hiddify_CoreInfoListenerClient, error)
OutboundsInfo(ctx context.Context, opts ...grpc.CallOption) (Hiddify_OutboundsInfoClient, error)
MainOutboundsInfo(ctx context.Context, opts ...grpc.CallOption) (Hiddify_MainOutboundsInfoClient, error)
GetSystemInfo(ctx context.Context, opts ...grpc.CallOption) (Hiddify_GetSystemInfoClient, error)
Setup(ctx context.Context, in *SetupRequest, opts ...grpc.CallOption) (*Response, error)
Parse(ctx context.Context, in *ParseRequest, opts ...grpc.CallOption) (*ParseResponse, error)
//rpc ChangeConfigOptions (ChangeConfigOptionsRequest) returns (CoreInfoResponse);
//rpc GenerateConfig (GenerateConfigRequest) returns (GenerateConfigResponse);
StartService(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (*CoreInfoResponse, error)
Stop(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*CoreInfoResponse, error)
Restart(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (*CoreInfoResponse, error)
SelectOutbound(ctx context.Context, in *SelectOutboundRequest, opts ...grpc.CallOption) (*Response, error)
UrlTest(ctx context.Context, in *UrlTestRequest, opts ...grpc.CallOption) (*Response, error)
GenerateWarpConfig(ctx context.Context, in *GenerateWarpConfigRequest, opts ...grpc.CallOption) (*WarpGenerationResponse, error)
GetSystemProxyStatus(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*SystemProxyStatus, error)
SetSystemProxyEnabled(ctx context.Context, in *SetSystemProxyEnabledRequest, opts ...grpc.CallOption) (*Response, error)
LogListener(ctx context.Context, opts ...grpc.CallOption) (Hiddify_LogListenerClient, error)
}
type hiddifyClient struct {
cc grpc.ClientConnInterface
}
func NewHiddifyClient(cc grpc.ClientConnInterface) HiddifyClient {
return &hiddifyClient{cc}
}
func (c *hiddifyClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) {
out := new(HelloResponse)
err := c.cc.Invoke(ctx, Hiddify_SayHello_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) SayHelloStream(ctx context.Context, opts ...grpc.CallOption) (Hiddify_SayHelloStreamClient, error) {
stream, err := c.cc.NewStream(ctx, &Hiddify_ServiceDesc.Streams[0], Hiddify_SayHelloStream_FullMethodName, opts...)
if err != nil {
return nil, err
}
x := &hiddifySayHelloStreamClient{stream}
return x, nil
}
type Hiddify_SayHelloStreamClient interface {
Send(*HelloRequest) error
Recv() (*HelloResponse, error)
grpc.ClientStream
}
type hiddifySayHelloStreamClient struct {
grpc.ClientStream
}
func (x *hiddifySayHelloStreamClient) Send(m *HelloRequest) error {
return x.ClientStream.SendMsg(m)
}
func (x *hiddifySayHelloStreamClient) Recv() (*HelloResponse, error) {
m := new(HelloResponse)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func (c *hiddifyClient) Start(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (*CoreInfoResponse, error) {
out := new(CoreInfoResponse)
err := c.cc.Invoke(ctx, Hiddify_Start_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) CoreInfoListener(ctx context.Context, opts ...grpc.CallOption) (Hiddify_CoreInfoListenerClient, error) {
stream, err := c.cc.NewStream(ctx, &Hiddify_ServiceDesc.Streams[1], Hiddify_CoreInfoListener_FullMethodName, opts...)
if err != nil {
return nil, err
}
x := &hiddifyCoreInfoListenerClient{stream}
return x, nil
}
type Hiddify_CoreInfoListenerClient interface {
Send(*StopRequest) error
Recv() (*CoreInfoResponse, error)
grpc.ClientStream
}
type hiddifyCoreInfoListenerClient struct {
grpc.ClientStream
}
func (x *hiddifyCoreInfoListenerClient) Send(m *StopRequest) error {
return x.ClientStream.SendMsg(m)
}
func (x *hiddifyCoreInfoListenerClient) Recv() (*CoreInfoResponse, error) {
m := new(CoreInfoResponse)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func (c *hiddifyClient) OutboundsInfo(ctx context.Context, opts ...grpc.CallOption) (Hiddify_OutboundsInfoClient, error) {
stream, err := c.cc.NewStream(ctx, &Hiddify_ServiceDesc.Streams[2], Hiddify_OutboundsInfo_FullMethodName, opts...)
if err != nil {
return nil, err
}
x := &hiddifyOutboundsInfoClient{stream}
return x, nil
}
type Hiddify_OutboundsInfoClient interface {
Send(*StopRequest) error
Recv() (*OutboundGroupList, error)
grpc.ClientStream
}
type hiddifyOutboundsInfoClient struct {
grpc.ClientStream
}
func (x *hiddifyOutboundsInfoClient) Send(m *StopRequest) error {
return x.ClientStream.SendMsg(m)
}
func (x *hiddifyOutboundsInfoClient) Recv() (*OutboundGroupList, error) {
m := new(OutboundGroupList)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func (c *hiddifyClient) MainOutboundsInfo(ctx context.Context, opts ...grpc.CallOption) (Hiddify_MainOutboundsInfoClient, error) {
stream, err := c.cc.NewStream(ctx, &Hiddify_ServiceDesc.Streams[3], Hiddify_MainOutboundsInfo_FullMethodName, opts...)
if err != nil {
return nil, err
}
x := &hiddifyMainOutboundsInfoClient{stream}
return x, nil
}
type Hiddify_MainOutboundsInfoClient interface {
Send(*StopRequest) error
Recv() (*OutboundGroupList, error)
grpc.ClientStream
}
type hiddifyMainOutboundsInfoClient struct {
grpc.ClientStream
}
func (x *hiddifyMainOutboundsInfoClient) Send(m *StopRequest) error {
return x.ClientStream.SendMsg(m)
}
func (x *hiddifyMainOutboundsInfoClient) Recv() (*OutboundGroupList, error) {
m := new(OutboundGroupList)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func (c *hiddifyClient) GetSystemInfo(ctx context.Context, opts ...grpc.CallOption) (Hiddify_GetSystemInfoClient, error) {
stream, err := c.cc.NewStream(ctx, &Hiddify_ServiceDesc.Streams[4], Hiddify_GetSystemInfo_FullMethodName, opts...)
if err != nil {
return nil, err
}
x := &hiddifyGetSystemInfoClient{stream}
return x, nil
}
type Hiddify_GetSystemInfoClient interface {
Send(*StopRequest) error
Recv() (*SystemInfo, error)
grpc.ClientStream
}
type hiddifyGetSystemInfoClient struct {
grpc.ClientStream
}
func (x *hiddifyGetSystemInfoClient) Send(m *StopRequest) error {
return x.ClientStream.SendMsg(m)
}
func (x *hiddifyGetSystemInfoClient) Recv() (*SystemInfo, error) {
m := new(SystemInfo)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func (c *hiddifyClient) Setup(ctx context.Context, in *SetupRequest, opts ...grpc.CallOption) (*Response, error) {
out := new(Response)
err := c.cc.Invoke(ctx, Hiddify_Setup_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) Parse(ctx context.Context, in *ParseRequest, opts ...grpc.CallOption) (*ParseResponse, error) {
out := new(ParseResponse)
err := c.cc.Invoke(ctx, Hiddify_Parse_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) StartService(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (*CoreInfoResponse, error) {
out := new(CoreInfoResponse)
err := c.cc.Invoke(ctx, Hiddify_StartService_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) Stop(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*CoreInfoResponse, error) {
out := new(CoreInfoResponse)
err := c.cc.Invoke(ctx, Hiddify_Stop_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) Restart(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (*CoreInfoResponse, error) {
out := new(CoreInfoResponse)
err := c.cc.Invoke(ctx, Hiddify_Restart_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) SelectOutbound(ctx context.Context, in *SelectOutboundRequest, opts ...grpc.CallOption) (*Response, error) {
out := new(Response)
err := c.cc.Invoke(ctx, Hiddify_SelectOutbound_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) UrlTest(ctx context.Context, in *UrlTestRequest, opts ...grpc.CallOption) (*Response, error) {
out := new(Response)
err := c.cc.Invoke(ctx, Hiddify_UrlTest_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) GenerateWarpConfig(ctx context.Context, in *GenerateWarpConfigRequest, opts ...grpc.CallOption) (*WarpGenerationResponse, error) {
out := new(WarpGenerationResponse)
err := c.cc.Invoke(ctx, Hiddify_GenerateWarpConfig_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) GetSystemProxyStatus(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*SystemProxyStatus, error) {
out := new(SystemProxyStatus)
err := c.cc.Invoke(ctx, Hiddify_GetSystemProxyStatus_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) SetSystemProxyEnabled(ctx context.Context, in *SetSystemProxyEnabledRequest, opts ...grpc.CallOption) (*Response, error) {
out := new(Response)
err := c.cc.Invoke(ctx, Hiddify_SetSystemProxyEnabled_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *hiddifyClient) LogListener(ctx context.Context, opts ...grpc.CallOption) (Hiddify_LogListenerClient, error) {
stream, err := c.cc.NewStream(ctx, &Hiddify_ServiceDesc.Streams[5], Hiddify_LogListener_FullMethodName, opts...)
if err != nil {
return nil, err
}
x := &hiddifyLogListenerClient{stream}
return x, nil
}
type Hiddify_LogListenerClient interface {
Send(*StopRequest) error
Recv() (*LogMessage, error)
grpc.ClientStream
}
type hiddifyLogListenerClient struct {
grpc.ClientStream
}
func (x *hiddifyLogListenerClient) Send(m *StopRequest) error {
return x.ClientStream.SendMsg(m)
}
func (x *hiddifyLogListenerClient) Recv() (*LogMessage, error) {
m := new(LogMessage)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// HiddifyServer is the server API for Hiddify service.
// All implementations must embed UnimplementedHiddifyServer
// for forward compatibility
type HiddifyServer interface {
SayHello(context.Context, *HelloRequest) (*HelloResponse, error)
SayHelloStream(Hiddify_SayHelloStreamServer) error
Start(context.Context, *StartRequest) (*CoreInfoResponse, error)
CoreInfoListener(Hiddify_CoreInfoListenerServer) error
OutboundsInfo(Hiddify_OutboundsInfoServer) error
MainOutboundsInfo(Hiddify_MainOutboundsInfoServer) error
GetSystemInfo(Hiddify_GetSystemInfoServer) error
Setup(context.Context, *SetupRequest) (*Response, error)
Parse(context.Context, *ParseRequest) (*ParseResponse, error)
//rpc ChangeConfigOptions (ChangeConfigOptionsRequest) returns (CoreInfoResponse);
//rpc GenerateConfig (GenerateConfigRequest) returns (GenerateConfigResponse);
StartService(context.Context, *StartRequest) (*CoreInfoResponse, error)
Stop(context.Context, *Empty) (*CoreInfoResponse, error)
Restart(context.Context, *StartRequest) (*CoreInfoResponse, error)
SelectOutbound(context.Context, *SelectOutboundRequest) (*Response, error)
UrlTest(context.Context, *UrlTestRequest) (*Response, error)
GenerateWarpConfig(context.Context, *GenerateWarpConfigRequest) (*WarpGenerationResponse, error)
GetSystemProxyStatus(context.Context, *Empty) (*SystemProxyStatus, error)
SetSystemProxyEnabled(context.Context, *SetSystemProxyEnabledRequest) (*Response, error)
LogListener(Hiddify_LogListenerServer) error
mustEmbedUnimplementedHiddifyServer()
}
// UnimplementedHiddifyServer must be embedded to have forward compatible implementations.
type UnimplementedHiddifyServer struct {
}
func (UnimplementedHiddifyServer) SayHello(context.Context, *HelloRequest) (*HelloResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented")
}
func (UnimplementedHiddifyServer) SayHelloStream(Hiddify_SayHelloStreamServer) error {
return status.Errorf(codes.Unimplemented, "method SayHelloStream not implemented")
}
func (UnimplementedHiddifyServer) Start(context.Context, *StartRequest) (*CoreInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Start not implemented")
}
func (UnimplementedHiddifyServer) CoreInfoListener(Hiddify_CoreInfoListenerServer) error {
return status.Errorf(codes.Unimplemented, "method CoreInfoListener not implemented")
}
func (UnimplementedHiddifyServer) OutboundsInfo(Hiddify_OutboundsInfoServer) error {
return status.Errorf(codes.Unimplemented, "method OutboundsInfo not implemented")
}
func (UnimplementedHiddifyServer) MainOutboundsInfo(Hiddify_MainOutboundsInfoServer) error {
return status.Errorf(codes.Unimplemented, "method MainOutboundsInfo not implemented")
}
func (UnimplementedHiddifyServer) GetSystemInfo(Hiddify_GetSystemInfoServer) error {
return status.Errorf(codes.Unimplemented, "method GetSystemInfo not implemented")
}
func (UnimplementedHiddifyServer) Setup(context.Context, *SetupRequest) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Setup not implemented")
}
func (UnimplementedHiddifyServer) Parse(context.Context, *ParseRequest) (*ParseResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Parse not implemented")
}
func (UnimplementedHiddifyServer) StartService(context.Context, *StartRequest) (*CoreInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method StartService not implemented")
}
func (UnimplementedHiddifyServer) Stop(context.Context, *Empty) (*CoreInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Stop not implemented")
}
func (UnimplementedHiddifyServer) Restart(context.Context, *StartRequest) (*CoreInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Restart not implemented")
}
func (UnimplementedHiddifyServer) SelectOutbound(context.Context, *SelectOutboundRequest) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method SelectOutbound not implemented")
}
func (UnimplementedHiddifyServer) UrlTest(context.Context, *UrlTestRequest) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method UrlTest not implemented")
}
func (UnimplementedHiddifyServer) GenerateWarpConfig(context.Context, *GenerateWarpConfigRequest) (*WarpGenerationResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GenerateWarpConfig not implemented")
}
func (UnimplementedHiddifyServer) GetSystemProxyStatus(context.Context, *Empty) (*SystemProxyStatus, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetSystemProxyStatus not implemented")
}
func (UnimplementedHiddifyServer) SetSystemProxyEnabled(context.Context, *SetSystemProxyEnabledRequest) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetSystemProxyEnabled not implemented")
}
func (UnimplementedHiddifyServer) LogListener(Hiddify_LogListenerServer) error {
return status.Errorf(codes.Unimplemented, "method LogListener not implemented")
}
func (UnimplementedHiddifyServer) mustEmbedUnimplementedHiddifyServer() {}
// UnsafeHiddifyServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to HiddifyServer will
// result in compilation errors.
type UnsafeHiddifyServer interface {
mustEmbedUnimplementedHiddifyServer()
}
func RegisterHiddifyServer(s grpc.ServiceRegistrar, srv HiddifyServer) {
s.RegisterService(&Hiddify_ServiceDesc, srv)
}
func _Hiddify_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HelloRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).SayHello(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_SayHello_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).SayHello(ctx, req.(*HelloRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_SayHelloStream_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(HiddifyServer).SayHelloStream(&hiddifySayHelloStreamServer{stream})
}
type Hiddify_SayHelloStreamServer interface {
Send(*HelloResponse) error
Recv() (*HelloRequest, error)
grpc.ServerStream
}
type hiddifySayHelloStreamServer struct {
grpc.ServerStream
}
func (x *hiddifySayHelloStreamServer) Send(m *HelloResponse) error {
return x.ServerStream.SendMsg(m)
}
func (x *hiddifySayHelloStreamServer) Recv() (*HelloRequest, error) {
m := new(HelloRequest)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func _Hiddify_Start_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(StartRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).Start(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_Start_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).Start(ctx, req.(*StartRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_CoreInfoListener_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(HiddifyServer).CoreInfoListener(&hiddifyCoreInfoListenerServer{stream})
}
type Hiddify_CoreInfoListenerServer interface {
Send(*CoreInfoResponse) error
Recv() (*StopRequest, error)
grpc.ServerStream
}
type hiddifyCoreInfoListenerServer struct {
grpc.ServerStream
}
func (x *hiddifyCoreInfoListenerServer) Send(m *CoreInfoResponse) error {
return x.ServerStream.SendMsg(m)
}
func (x *hiddifyCoreInfoListenerServer) Recv() (*StopRequest, error) {
m := new(StopRequest)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func _Hiddify_OutboundsInfo_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(HiddifyServer).OutboundsInfo(&hiddifyOutboundsInfoServer{stream})
}
type Hiddify_OutboundsInfoServer interface {
Send(*OutboundGroupList) error
Recv() (*StopRequest, error)
grpc.ServerStream
}
type hiddifyOutboundsInfoServer struct {
grpc.ServerStream
}
func (x *hiddifyOutboundsInfoServer) Send(m *OutboundGroupList) error {
return x.ServerStream.SendMsg(m)
}
func (x *hiddifyOutboundsInfoServer) Recv() (*StopRequest, error) {
m := new(StopRequest)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func _Hiddify_MainOutboundsInfo_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(HiddifyServer).MainOutboundsInfo(&hiddifyMainOutboundsInfoServer{stream})
}
type Hiddify_MainOutboundsInfoServer interface {
Send(*OutboundGroupList) error
Recv() (*StopRequest, error)
grpc.ServerStream
}
type hiddifyMainOutboundsInfoServer struct {
grpc.ServerStream
}
func (x *hiddifyMainOutboundsInfoServer) Send(m *OutboundGroupList) error {
return x.ServerStream.SendMsg(m)
}
func (x *hiddifyMainOutboundsInfoServer) Recv() (*StopRequest, error) {
m := new(StopRequest)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func _Hiddify_GetSystemInfo_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(HiddifyServer).GetSystemInfo(&hiddifyGetSystemInfoServer{stream})
}
type Hiddify_GetSystemInfoServer interface {
Send(*SystemInfo) error
Recv() (*StopRequest, error)
grpc.ServerStream
}
type hiddifyGetSystemInfoServer struct {
grpc.ServerStream
}
func (x *hiddifyGetSystemInfoServer) Send(m *SystemInfo) error {
return x.ServerStream.SendMsg(m)
}
func (x *hiddifyGetSystemInfoServer) Recv() (*StopRequest, error) {
m := new(StopRequest)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func _Hiddify_Setup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SetupRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).Setup(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_Setup_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).Setup(ctx, req.(*SetupRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_Parse_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ParseRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).Parse(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_Parse_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).Parse(ctx, req.(*ParseRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_StartService_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(StartRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).StartService(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_StartService_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).StartService(ctx, req.(*StartRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_Stop_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).Stop(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_Stop_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).Stop(ctx, req.(*Empty))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_Restart_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(StartRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).Restart(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_Restart_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).Restart(ctx, req.(*StartRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_SelectOutbound_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SelectOutboundRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).SelectOutbound(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_SelectOutbound_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).SelectOutbound(ctx, req.(*SelectOutboundRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_UrlTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UrlTestRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).UrlTest(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_UrlTest_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).UrlTest(ctx, req.(*UrlTestRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_GenerateWarpConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GenerateWarpConfigRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).GenerateWarpConfig(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_GenerateWarpConfig_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).GenerateWarpConfig(ctx, req.(*GenerateWarpConfigRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_GetSystemProxyStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).GetSystemProxyStatus(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_GetSystemProxyStatus_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).GetSystemProxyStatus(ctx, req.(*Empty))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_SetSystemProxyEnabled_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SetSystemProxyEnabledRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HiddifyServer).SetSystemProxyEnabled(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Hiddify_SetSystemProxyEnabled_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HiddifyServer).SetSystemProxyEnabled(ctx, req.(*SetSystemProxyEnabledRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Hiddify_LogListener_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(HiddifyServer).LogListener(&hiddifyLogListenerServer{stream})
}
type Hiddify_LogListenerServer interface {
Send(*LogMessage) error
Recv() (*StopRequest, error)
grpc.ServerStream
}
type hiddifyLogListenerServer struct {
grpc.ServerStream
}
func (x *hiddifyLogListenerServer) Send(m *LogMessage) error {
return x.ServerStream.SendMsg(m)
}
func (x *hiddifyLogListenerServer) Recv() (*StopRequest, error) {
m := new(StopRequest)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// Hiddify_ServiceDesc is the grpc.ServiceDesc for Hiddify service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Hiddify_ServiceDesc = grpc.ServiceDesc{
ServiceName: "hiddifyrpc.Hiddify",
HandlerType: (*HiddifyServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "SayHello",
Handler: _Hiddify_SayHello_Handler,
},
{
MethodName: "Start",
Handler: _Hiddify_Start_Handler,
},
{
MethodName: "Setup",
Handler: _Hiddify_Setup_Handler,
},
{
MethodName: "Parse",
Handler: _Hiddify_Parse_Handler,
},
{
MethodName: "StartService",
Handler: _Hiddify_StartService_Handler,
},
{
MethodName: "Stop",
Handler: _Hiddify_Stop_Handler,
},
{
MethodName: "Restart",
Handler: _Hiddify_Restart_Handler,
},
{
MethodName: "SelectOutbound",
Handler: _Hiddify_SelectOutbound_Handler,
},
{
MethodName: "UrlTest",
Handler: _Hiddify_UrlTest_Handler,
},
{
MethodName: "GenerateWarpConfig",
Handler: _Hiddify_GenerateWarpConfig_Handler,
},
{
MethodName: "GetSystemProxyStatus",
Handler: _Hiddify_GetSystemProxyStatus_Handler,
},
{
MethodName: "SetSystemProxyEnabled",
Handler: _Hiddify_SetSystemProxyEnabled_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "SayHelloStream",
Handler: _Hiddify_SayHelloStream_Handler,
ServerStreams: true,
ClientStreams: true,
},
{
StreamName: "CoreInfoListener",
Handler: _Hiddify_CoreInfoListener_Handler,
ServerStreams: true,
ClientStreams: true,
},
{
StreamName: "OutboundsInfo",
Handler: _Hiddify_OutboundsInfo_Handler,
ServerStreams: true,
ClientStreams: true,
},
{
StreamName: "MainOutboundsInfo",
Handler: _Hiddify_MainOutboundsInfo_Handler,
ServerStreams: true,
ClientStreams: true,
},
{
StreamName: "GetSystemInfo",
Handler: _Hiddify_GetSystemInfo_Handler,
ServerStreams: true,
ClientStreams: true,
},
{
StreamName: "LogListener",
Handler: _Hiddify_LogListener_Handler,
ServerStreams: true,
ClientStreams: true,
},
},
Metadata: "hiddifyrpc/hiddify.proto",
}

77
v2/command_client.go Normal file
View File

@@ -0,0 +1,77 @@
package v2
import (
pb "github.com/hiddify/libcore/hiddifyrpc"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/log"
)
type CommandClientHandler struct {
port int64
logger log.Logger
}
func (cch *CommandClientHandler) Connected() {
cch.logger.Debug("CONNECTED")
}
func (cch *CommandClientHandler) Disconnected(message string) {
cch.logger.Debug("DISCONNECTED: ", message)
}
func (cch *CommandClientHandler) ClearLog() {
cch.logger.Debug("clear log")
}
func (cch *CommandClientHandler) WriteLog(message string) {
cch.logger.Debug("log: ", message)
}
func (cch *CommandClientHandler) WriteStatus(message *libbox.StatusMessage) {
systemInfoObserver.Emit(pb.SystemInfo{
ConnectionsIn: message.ConnectionsIn,
ConnectionsOut: message.ConnectionsOut,
Uplink: message.Uplink,
Downlink: message.Downlink,
UplinkTotal: message.UplinkTotal,
DownlinkTotal: message.DownlinkTotal,
Memory: message.Memory,
Goroutines: message.Goroutines,
})
cch.logger.Debug("Memory: ", libbox.FormatBytes(message.Memory), ", Goroutines: ", message.Goroutines)
}
func (cch *CommandClientHandler) WriteGroups(message libbox.OutboundGroupIterator) {
if message == nil {
return
}
groups := pb.OutboundGroupList{}
for message.HasNext() {
group := message.Next()
items := group.GetItems()
groupItems := []*pb.OutboundGroupItem{}
for items.HasNext() {
item := items.Next()
groupItems = append(groupItems,
&pb.OutboundGroupItem{
Tag: item.Tag,
Type: item.Type,
UrlTestTime: item.URLTestTime,
UrlTestDelay: item.URLTestDelay,
},
)
}
groups.Items = append(groups.Items, &pb.OutboundGroup{Tag: group.Tag, Type: group.Type, Selected: group.Selected, Items: groupItems})
}
outboundsInfoObserver.Emit(groups)
mainOutboundsInfoObserver.Emit(groups)
}
func (cch *CommandClientHandler) InitializeClashMode(modeList libbox.StringIterator, currentMode string) {
cch.logger.Debug("initial clash mode: ", currentMode)
}
func (cch *CommandClientHandler) UpdateClashMode(newMode string) {
cch.logger.Debug("update clash mode: ", newMode)
}

163
v2/commands.go Normal file
View File

@@ -0,0 +1,163 @@
package v2
import (
"context"
"time"
pb "github.com/hiddify/libcore/hiddifyrpc"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing/common/observable"
)
var systemInfoObserver = observable.Observer[pb.SystemInfo]{}
var outboundsInfoObserver = observable.Observer[pb.OutboundGroupList]{}
var mainOutboundsInfoObserver = observable.Observer[pb.OutboundGroupList]{}
var (
statusClient *libbox.CommandClient
groupClient *libbox.CommandClient
groupInfoOnlyClient *libbox.CommandClient
)
func (s *server) GetSystemInfo(stream pb.Hiddify_GetSystemInfoServer) error {
if statusClient == nil {
statusClient = libbox.NewCommandClient(
&CommandClientHandler{},
&libbox.CommandClientOptions{
Command: libbox.CommandStatus,
StatusInterval: 1000000000, //1000ms debounce
},
)
defer func() {
statusClient.Disconnect()
statusClient = nil
}()
statusClient.Connect()
}
sub, _, _ := systemInfoObserver.Subscribe()
stopch := make(chan int)
go func() {
stream.Recv()
close(stopch)
}()
for {
select {
case <-stream.Context().Done():
break
case <-stopch:
break
case info := <-sub:
stream.Send(&info)
case <-time.After(1000 * time.Millisecond):
}
}
}
func (s *server) OutboundsInfo(stream pb.Hiddify_OutboundsInfoServer) error {
if groupClient == nil {
groupClient = libbox.NewCommandClient(
&CommandClientHandler{},
&libbox.CommandClientOptions{
Command: libbox.CommandGroup,
StatusInterval: 500000000, //500ms debounce
},
)
defer func() {
groupClient.Disconnect()
groupClient = nil
}()
groupClient.Connect()
}
sub, _, _ := outboundsInfoObserver.Subscribe()
stopch := make(chan int)
go func() {
stream.Recv()
close(stopch)
}()
for {
select {
case <-stream.Context().Done():
break
case <-stopch:
break
case info := <-sub:
stream.Send(&info)
case <-time.After(500 * time.Millisecond):
}
}
}
func (s *server) MainOutboundsInfo(stream pb.Hiddify_MainOutboundsInfoServer) error {
if groupInfoOnlyClient == nil {
groupInfoOnlyClient = libbox.NewCommandClient(
&CommandClientHandler{},
&libbox.CommandClientOptions{
Command: libbox.CommandGroupInfoOnly,
StatusInterval: 500000000, //500ms debounce
},
)
defer func() {
groupInfoOnlyClient.Disconnect()
groupInfoOnlyClient = nil
}()
groupInfoOnlyClient.Connect()
}
sub, _, _ := mainOutboundsInfoObserver.Subscribe()
stopch := make(chan int)
go func() {
stream.Recv()
close(stopch)
}()
for {
select {
case <-stream.Context().Done():
break
case <-stopch:
break
case info := <-sub:
stream.Send(&info)
case <-time.After(500 * time.Millisecond):
}
}
}
// Implement the SelectOutbound method
func (s *server) SelectOutbound(ctx context.Context, in *pb.SelectOutboundRequest) (*pb.Response, error) {
err := libbox.NewStandaloneCommandClient().SelectOutbound(in.GroupTag, in.OutboundTag)
if err != nil {
return &pb.Response{
ResponseCode: pb.ResponseCode_FAILED,
Message: err.Error(),
}, err
}
return &pb.Response{
ResponseCode: pb.ResponseCode_OK,
Message: "",
}, nil
}
// Implement the UrlTest method
func (s *server) UrlTest(ctx context.Context, in *pb.UrlTestRequest) (*pb.Response, error) {
err := libbox.NewStandaloneCommandClient().URLTest(in.GroupTag)
if err != nil {
return &pb.Response{
ResponseCode: pb.ResponseCode_FAILED,
Message: err.Error(),
}, err
}
return &pb.Response{
ResponseCode: pb.ResponseCode_OK,
Message: "",
}, nil
}

44
v2/coreinfo.go Normal file
View File

@@ -0,0 +1,44 @@
package v2
import (
"time"
pb "github.com/hiddify/libcore/hiddifyrpc"
"github.com/sagernet/sing/common/observable"
)
var coreInfoObserver = observable.Observer[pb.CoreInfoResponse]{}
var CoreState = pb.CoreState_STOPPED
func SetCoreStatus(state pb.CoreState, msgType pb.MessageType, message string) pb.CoreInfoResponse {
CoreState = state
info := pb.CoreInfoResponse{
CoreState: state,
MessageType: msgType,
Message: message,
}
coreInfoObserver.Emit(info)
return info
}
func (s *server) CoreInfoListener(stream pb.Hiddify_CoreInfoListenerServer) error {
coreSub, _, _ := coreInfoObserver.Subscribe()
defer coreInfoObserver.UnSubscribe(coreSub)
stopch := make(chan int)
go func() {
stream.Recv()
close(stopch)
}()
for {
select {
case <-stream.Context().Done():
break
case <-stopch:
break
case info := <-coreSub:
stream.Send(&info)
case <-time.After(500 * time.Millisecond):
}
}
}

232
v2/custom.go Normal file
View File

@@ -0,0 +1,232 @@
package v2
import (
"context"
"fmt"
"os"
"path/filepath"
"time"
"github.com/hiddify/libcore/config"
pb "github.com/hiddify/libcore/hiddifyrpc"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
)
var Box *libbox.BoxService
var configOptions *config.ConfigOptions
var activeConfigPath *string
var logFactory *log.Factory
func stopAndAlert(msgType pb.MessageType, message string) {
SetCoreStatus(pb.CoreState_STOPPED, msgType, message)
config.DeactivateTunnelService()
// if commandServer != nil {
// commandServer.SetService(nil)
// }
if Box != nil {
Box.Close()
Box = nil
}
// if commandServer != nil {
// commandServer.Close()
// }
}
func (s *server) Start(ctx context.Context, in *pb.StartRequest) (*pb.CoreInfoResponse, error) {
defer config.DeferPanicToError("start", func(err error) {
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
})
if CoreState != pb.CoreState_STOPPED {
return &pb.CoreInfoResponse{
CoreState: CoreState,
MessageType: pb.MessageType_INSTANCE_NOT_STOPPED,
}, fmt.Errorf("instance not stopped")
}
SetCoreStatus(pb.CoreState_STARTING, pb.MessageType_EMPTY, "")
libbox.SetMemoryLimit(!in.DisableMemoryLimit)
resp, err := s.StartService(ctx, in)
return resp, err
}
// Implement the StartService method
func (s *server) StartService(ctx context.Context, in *pb.StartRequest) (*pb.CoreInfoResponse, error) {
content := in.ConfigContent
if content != "" {
fileContent, err := os.ReadFile(*activeConfigPath)
if err != nil {
resp := SetCoreStatus(pb.CoreState_STOPPED, pb.MessageType_ERROR_READING_CONFIG, err.Error())
return &resp, err
}
content = string(fileContent)
}
parsedContent, err := parseConfig(content)
if err != nil {
resp := SetCoreStatus(pb.CoreState_STOPPED, pb.MessageType_ERROR_PARSING_CONFIG, err.Error())
return &resp, err
}
var patchedOptions *option.Options
patchedOptions, err = config.BuildConfig(*configOptions, parsedContent)
if err != nil {
resp := SetCoreStatus(pb.CoreState_STOPPED, pb.MessageType_ERROR_BUILDING_CONFIG, err.Error())
return &resp, err
}
config.SaveCurrentConfig(filepath.Join(sWorkingPath, "current-config.json"), *patchedOptions)
// err = startCommandServer(*logFactory)
// if err != nil {
// resp := SetCoreStatus(pb.CoreState_STOPPED, pb.MessageType_START_COMMAND_SERVER, err.Error())
// return &resp, err
// }
instance, err := NewService(*patchedOptions)
if err != nil {
resp := SetCoreStatus(pb.CoreState_STOPPED, pb.MessageType_CREATE_SERVICE, err.Error())
return &resp, err
}
if in.DelayStart {
<-time.After(250 * time.Millisecond)
}
err = instance.Start()
if err != nil {
resp := SetCoreStatus(pb.CoreState_STOPPED, pb.MessageType_START_SERVICE, err.Error())
return &resp, err
}
Box = instance
// commandServer.SetService(box)
resp := SetCoreStatus(pb.CoreState_STARTED, pb.MessageType_EMPTY, "")
return &resp, nil
}
func (s *server) Parse(ctx context.Context, in *pb.ParseRequest) (*pb.ParseResponse, error) {
defer config.DeferPanicToError("parse", func(err error) {
Log(pb.LogLevel_FATAL, pb.LogType_CONFIG, err.Error())
stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
})
config, err := config.ParseConfigContent(in.Content, true)
if err != nil {
return &pb.ParseResponse{
ResponseCode: pb.ResponseCode_FAILED,
Message: err.Error(),
}, err
}
return &pb.ParseResponse{
ResponseCode: pb.ResponseCode_OK,
Content: string(config),
Message: "",
}, err
}
// func (s *server) ChangeConfigOptions(ctx context.Context, in *pb.ChangeConfigOptionsRequest) (*pb.CoreInfoResponse, error) {
// // Implement your change config options logic
// // Return a CoreInfoResponse
// }
// func (s *server) GenerateConfig(ctx context.Context, in *pb.GenerateConfigRequest) (*pb.GenerateConfigResponse, error) {
// defer config.DeferPanicToError("generateConfig", func(err error) {
// Log(pb.LogLevel_FATAL, pb.LogType_CONFIG, err.Error())
// stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
// })
// config, err := generateConfigFromFile(C.GoString(path), *configOptions)
// if err != nil {
// return C.CString("error" + err.Error())
// }
// return C.CString(config)
// }
// Implement the Stop method
func (s *server) Stop(ctx context.Context, empty *pb.Empty) (*pb.CoreInfoResponse, error) {
defer config.DeferPanicToError("stop", func(err error) {
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
})
config.DeactivateTunnelService()
if CoreState != pb.CoreState_STARTED {
Log(pb.LogLevel_FATAL, pb.LogType_CORE, "Core is not started")
return &pb.CoreInfoResponse{
CoreState: CoreState,
MessageType: pb.MessageType_INSTANCE_NOT_STARTED,
Message: "instance is not started",
}, fmt.Errorf("instance not started")
}
if Box == nil {
return &pb.CoreInfoResponse{
CoreState: CoreState,
MessageType: pb.MessageType_INSTANCE_NOT_FOUND,
Message: "instance is not found",
}, fmt.Errorf("instance not found")
}
SetCoreStatus(pb.CoreState_STOPPING, pb.MessageType_EMPTY, "")
// commandServer.SetService(nil)
err := Box.Close()
if err != nil {
return &pb.CoreInfoResponse{
CoreState: CoreState,
MessageType: pb.MessageType_UNEXPECTED_ERROR,
Message: "Error while stopping the service.",
}, fmt.Errorf("Error while stopping the service.")
}
Box = nil
// err = commandServer.Close()
// if err != nil {
// return &pb.CoreInfoResponse{
// CoreState: CoreState,
// MessageType: pb.MessageType_UNEXPECTED_ERROR,
// Message: "Error while Closing the comand server.",
// }, fmt.Errorf("Error while Closing the comand server.")
// }
// commandServer = nil
resp := SetCoreStatus(pb.CoreState_STOPPED, pb.MessageType_EMPTY, "")
return &resp, nil
}
func (s *server) Restart(ctx context.Context, in *pb.StartRequest) (*pb.CoreInfoResponse, error) {
defer config.DeferPanicToError("restart", func(err error) {
Log(pb.LogLevel_FATAL, pb.LogType_CORE, err.Error())
stopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
})
log.Debug("[Service] Restarting")
if CoreState != pb.CoreState_STARTED {
return &pb.CoreInfoResponse{
CoreState: CoreState,
MessageType: pb.MessageType_INSTANCE_NOT_STARTED,
Message: "instance is not started",
}, fmt.Errorf("instance not started")
}
if Box == nil {
return &pb.CoreInfoResponse{
CoreState: CoreState,
MessageType: pb.MessageType_INSTANCE_NOT_FOUND,
Message: "instance is not found",
}, fmt.Errorf("instance not found")
}
resp, err := s.Stop(ctx, &pb.Empty{})
if err != nil {
return resp, err
}
SetCoreStatus(pb.CoreState_STARTING, pb.MessageType_EMPTY, "")
<-time.After(250 * time.Millisecond)
libbox.SetMemoryLimit(!in.DisableMemoryLimit)
resp, gErr := s.StartService(ctx, in)
return resp, gErr
}

62
v2/example_client/main.go Normal file
View File

@@ -0,0 +1,62 @@
package main
import (
"context"
"log"
"time"
pb "github.com/hiddify/libcore/hiddifyrpc"
"google.golang.org/grpc"
)
const (
address = "localhost:50051"
defaultName = "world"
)
func main() {
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewHiddifyClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
// SayHello
r, err := c.SayHello(ctx, &pb.HelloRequest{Name: defaultName})
if err != nil {
log.Fatalf("could not greet: %v", err)
}
log.Printf("Greeting: %s", r.Message)
// SayHelloStream
stream, err := c.SayHelloStream(ctx)
if err != nil {
log.Fatalf("could not stream: %v", err)
}
names := []string{"Alice", "Bob", "Charlie"}
for _, name := range names {
err := stream.Send(&pb.HelloRequest{Name: name})
if err != nil {
log.Fatalf("could not send: %v", err)
}
r, err := stream.Recv()
if err != nil {
log.Fatalf("could not receive: %v", err)
}
log.Printf("Received1: %s", r.Message)
r2, err2 := stream.Recv()
if err2 != nil {
log.Fatalf("could not receive2: %v", err2)
}
log.Printf("Received: %s", r2.Message)
time.Sleep(1 * time.Second)
}
}

16
v2/example_server/main.go Normal file
View File

@@ -0,0 +1,16 @@
package main
import (
"os"
"os/signal"
"syscall"
v2 "github.com/hiddify/libcore/v2"
)
func main() {
v2.StartGrpcServer()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
<-sigChan
}

34
v2/grpc_server.go Normal file
View File

@@ -0,0 +1,34 @@
package v2
import "C"
import (
"log"
"net"
pb "github.com/hiddify/libcore/hiddifyrpc"
"google.golang.org/grpc"
)
const (
port = ":50051"
)
type server struct {
pb.UnimplementedHiddifyServer
}
//export StartGrpcServer
func StartGrpcServer() {
lis, err := net.Listen("tcp", port)
if err != nil {
log.Printf("failed to listen: %v", err)
}
s := grpc.NewServer()
pb.RegisterHiddifyServer(s, &server{})
log.Printf("Server listening on %s", port)
go func() {
if err := s.Serve(lis); err != nil {
log.Printf("failed to serve: %v", err)
}
}()
}

36
v2/hello.go Normal file
View File

@@ -0,0 +1,36 @@
package v2
import (
"context"
"log"
"time"
pb "github.com/hiddify/libcore/hiddifyrpc"
)
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloResponse, error) {
return &pb.HelloResponse{Message: "Hello, " + in.Name}, nil
}
func (s *server) SayHelloStream(stream pb.Hiddify_SayHelloStreamServer) error {
for {
req, err := stream.Recv()
if err != nil {
log.Printf("stream.Recv() failed: %v", err)
break
}
log.Printf("Received: %v", req.Name)
time.Sleep(1 * time.Second)
err = stream.Send(&pb.HelloResponse{Message: "Hello, " + req.Name})
if err != nil {
log.Printf("stream.Send() failed: %v", err)
break
}
err = stream.Send(&pb.HelloResponse{Message: "Hello again, " + req.Name})
if err != nil {
log.Printf("stream.Send() failed: %v", err)
break
}
}
return nil
}

41
v2/logproto.go Normal file
View File

@@ -0,0 +1,41 @@
package v2
import (
"time"
pb "github.com/hiddify/libcore/hiddifyrpc"
"github.com/sagernet/sing/common/observable"
)
var logObserver = observable.Observer[pb.LogMessage]{}
func Log(level pb.LogLevel, typ pb.LogType, message string) {
logObserver.Emit(pb.LogMessage{
Level: level,
Type: typ,
Message: message,
})
}
func (s *server) LogListener(stream pb.Hiddify_LogListenerServer) error {
logSub, _, _ := logObserver.Subscribe()
defer logObserver.UnSubscribe(logSub)
stopch := make(chan int)
go func() {
stream.Recv()
close(stopch)
}()
for {
select {
case <-stream.Context().Done():
break
case <-stopch:
break
case info := <-logSub:
stream.Send(&info)
case <-time.After(500 * time.Millisecond):
}
}
}

68
v2/service.go Normal file
View File

@@ -0,0 +1,68 @@
package v2
import (
"context"
"os"
"runtime"
runtimeDebug "runtime/debug"
B "github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/common/urltest"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/service"
"github.com/sagernet/sing/service/filemanager"
"github.com/sagernet/sing/service/pause"
)
var (
sWorkingPath string
sTempPath string
sUserID int
sGroupID int
)
func Setup(basePath string, workingPath string, tempPath string) {
tcpConn := runtime.GOOS == "windows" //TODO add TVOS
libbox.Setup(basePath, workingPath, tempPath, tcpConn)
sWorkingPath = workingPath
os.Chdir(sWorkingPath)
sTempPath = tempPath
sUserID = os.Getuid()
sGroupID = os.Getgid()
}
func NewService(options option.Options) (*libbox.BoxService, error) {
runtimeDebug.FreeOSMemory()
ctx, cancel := context.WithCancel(context.Background())
ctx = filemanager.WithDefault(ctx, sWorkingPath, sTempPath, sUserID, sGroupID)
urlTestHistoryStorage := urltest.NewHistoryStorage()
ctx = service.ContextWithPtr(ctx, urlTestHistoryStorage)
instance, err := B.New(B.Options{
Context: ctx,
Options: options,
})
if err != nil {
cancel()
return nil, E.Cause(err, "create service")
}
runtimeDebug.FreeOSMemory()
service := libbox.NewBoxService(
ctx,
cancel,
instance,
service.FromContext[pause.Manager](ctx),
urlTestHistoryStorage,
)
return &service, nil
}
func parseConfig(configContent string) (option.Options, error) {
var options option.Options
err := options.UnmarshalJSON([]byte(configContent))
if err != nil {
return option.Options{}, E.Cause(err, "decode config")
}
return options, nil
}

65
v2/warp.go Normal file
View File

@@ -0,0 +1,65 @@
package v2
import (
"context"
"github.com/hiddify/libcore/config"
pb "github.com/hiddify/libcore/hiddifyrpc"
"github.com/sagernet/sing-box/experimental/libbox"
)
func (s *server) GenerateWarpConfig(ctx context.Context, in *pb.GenerateWarpConfigRequest) (*pb.WarpGenerationResponse, error) {
account, log, wg, err := config.GenerateWarpInfo(in.LicenseKey, in.AccountId, in.AccessToken)
if err != nil {
return nil, err
}
return &pb.WarpGenerationResponse{
Account: &pb.WarpAccount{
AccountId: account.AccountID,
AccessToken: account.AccessToken,
},
Config: &pb.WarpWireguardConfig{
PrivateKey: wg.PrivateKey,
LocalAddressIpv4: wg.LocalAddressIPv4,
LocalAddressIpv6: wg.LocalAddressIPv6,
PeerPublicKey: wg.PeerPublicKey,
},
Log: log,
}, nil
}
// Implement the GetSystemProxyStatus method
func (s *server) GetSystemProxyStatus(ctx context.Context, empty *pb.Empty) (*pb.SystemProxyStatus, error) {
status, err := libbox.NewStandaloneCommandClient().GetSystemProxyStatus()
if err != nil {
return nil, err
}
return &pb.SystemProxyStatus{
Available: status.Available,
Enabled: status.Enabled,
}, nil
}
// Implement the SetSystemProxyEnabled method
func (s *server) SetSystemProxyEnabled(ctx context.Context, in *pb.SetSystemProxyEnabledRequest) (*pb.Response, error) {
err := libbox.NewStandaloneCommandClient().SetSystemProxyEnabled(in.IsEnabled)
if err != nil {
return nil, err
}
if err != nil {
return &pb.Response{
ResponseCode: pb.ResponseCode_FAILED,
Message: err.Error(),
}, err
}
return &pb.Response{
ResponseCode: pb.ResponseCode_OK,
Message: "",
}, nil
}