Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Oct 17, 2024
1 parent 82bfa73 commit b671efd
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ func AddGrpcClientPublicKey(clientPublicKey []byte) error {
}

//export close
func close() {
hcore.Close()
func close(mode SetupMode) {

Check failure on line 192 in custom/custom.go

View workflow job for this annotation

GitHub Actions / run / build (hiddify-core-linux-amd64, ubuntu-20.04, linux-amd64)

unrecognized Go type SetupMode

Check failure on line 192 in custom/custom.go

View workflow job for this annotation

GitHub Actions / run / build (hiddify-core-linux-amd64, ubuntu-20.04, linux-amd64)

unrecognized Go type SetupMode

Check failure on line 192 in custom/custom.go

View workflow job for this annotation

GitHub Actions / run / build (hiddify-core-windows-amd64, ubuntu-latest, windows-amd64, x64)

unrecognized Go type SetupMode

Check failure on line 192 in custom/custom.go

View workflow job for this annotation

GitHub Actions / run / build (hiddify-core-windows-amd64, ubuntu-latest, windows-amd64, x64)

unrecognized Go type SetupMode

Check failure on line 192 in custom/custom.go

View workflow job for this annotation

GitHub Actions / run / build (hiddify-core-macos-universal, macos-12, macos-universal)

unrecognized Go type SetupMode

Check failure on line 192 in custom/custom.go

View workflow job for this annotation

GitHub Actions / run / build (hiddify-core-macos-universal, macos-12, macos-universal)

unrecognized Go type SetupMode

Check failure on line 192 in custom/custom.go

View workflow job for this annotation

GitHub Actions / run / build (hiddify-core-macos-universal, macos-12, macos-universal)

unrecognized Go type SetupMode

Check failure on line 192 in custom/custom.go

View workflow job for this annotation

GitHub Actions / run / build (hiddify-core-macos-universal, macos-12, macos-universal)

unrecognized Go type SetupMode
hcore.Close(mode)
}
5 changes: 2 additions & 3 deletions mobile/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func Start(configPath string, platformInterface libbox.PlatformInterface) error

func Stop() error {
_, err := hcore.Stop()

return err
}

Expand All @@ -58,6 +57,6 @@ func AddGrpcClientPublicKey(clientPublicKey []byte) error {
return hcore.AddGrpcClientPublicKey(clientPublicKey)
}

func Close() {
hcore.Close()
func Close(mode hcore.SetupMode) {
hcore.Close(mode)
}
3 changes: 2 additions & 1 deletion v2/hcore/command_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"github.com/sagernet/sing-box/log"
)

var _ libbox.CommandClientHandler = (*CommandClientHandler)(nil)

type CommandClientHandler struct {
port int64
logger log.Logger
}

Expand Down
14 changes: 7 additions & 7 deletions v2/hcore/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package hcore

import (
"context"
"time"

common "github.com/hiddify/hiddify-core/v2/common"
"github.com/sagernet/sing-box/experimental/libbox"
"google.golang.org/grpc"
)

var (
systemInfoObserver = NewObserver[*SystemInfo](10)
outboundsInfoObserver = NewObserver[*OutboundGroupList](10)
mainOutboundsInfoObserver = NewObserver[*OutboundGroupList](10)
systemInfoObserver = NewObserver[*SystemInfo](1)
outboundsInfoObserver = NewObserver[*OutboundGroupList](1)
mainOutboundsInfoObserver = NewObserver[*OutboundGroupList](1)
)

var (
Expand Down Expand Up @@ -51,7 +50,7 @@ func (s *CoreService) GetSystemInfo(req *common.Empty, stream grpc.ServerStreami
return nil
case info := <-sub:
stream.Send(info)
case <-time.After(1000 * time.Millisecond):
// case <-time.After(1000 * time.Millisecond):
}
}
}
Expand All @@ -73,6 +72,7 @@ func (s *CoreService) OutboundsInfo(req *common.Empty, stream grpc.ServerStreami
groupClient.Disconnect()
groupClient = nil
}()

groupClient.Connect()
}

Expand All @@ -86,7 +86,7 @@ func (s *CoreService) OutboundsInfo(req *common.Empty, stream grpc.ServerStreami
return nil
case info := <-sub:
stream.Send(info)
case <-time.After(500 * time.Millisecond):
// case <-time.After(500 * time.Millisecond):
}
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func (s *CoreService) MainOutboundsInfo(req *common.Empty, stream grpc.ServerStr
return nil
case info := <-sub:
stream.Send(info)
case <-time.After(500 * time.Millisecond):
// case <-time.After(500 * time.Millisecond):
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions v2/hcore/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,17 @@ func Restart(in *StartRequest) (*CoreInfoResponse, error) {
return resp, gErr
}

func Close() error {
func Close(mode SetupMode) error {
defer config.DeferPanicToError("close", func(err error) {
Log(LogLevel_FATAL, LogType_CORE, err.Error())
StopAndAlert(MessageType_UNEXPECTED_ERROR, err.Error())
})
log.Debug("[Service] Closing")

_, err := Stop()
CloseGrpcServer()
if err != nil {
return err
}
return nil
CloseGrpcServer(mode)

return err
}

// func (s *CoreService) Status(ctx context.Context, empty *common.Empty) (*CoreInfoResponse, error) {
Expand Down
8 changes: 4 additions & 4 deletions v2/hcore/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ func AddGrpcClientPublicKey(clientPublicKey []byte) error {
return nil
}

func CloseGrpcServer() {
for mode := range grpcServer {
grpcServer[mode].Stop()
grpcServer[mode] = nil
func CloseGrpcServer(mode SetupMode) {
if server, ok := grpcServer[mode]; ok && server != nil {
server.Stop()
delete(grpcServer, mode)
}
}
2 changes: 1 addition & 1 deletion v2/hcore/logproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewObserver[T any](listenerBufferSize int) *observable.Observer[T] {
return observable.NewObserver(observable.NewSubscriber[T](listenerBufferSize), listenerBufferSize)
}

var logObserver = NewObserver[*LogMessage](10)
var logObserver = NewObserver[*LogMessage](1)

func Log(level LogLevel, typ LogType, message ...any) {
if level != LogLevel_DEBUG {
Expand Down

0 comments on commit b671efd

Please sign in to comment.