diff --git a/custom/custom.go b/custom/custom.go index 9b74a97..5d89f8a 100644 --- a/custom/custom.go +++ b/custom/custom.go @@ -189,6 +189,6 @@ func AddGrpcClientPublicKey(clientPublicKey []byte) error { } //export close -func close() { - hcore.Close() +func close(mode SetupMode) { + hcore.Close(mode) } diff --git a/mobile/mobile.go b/mobile/mobile.go index 0159a9d..ff82136 100644 --- a/mobile/mobile.go +++ b/mobile/mobile.go @@ -46,7 +46,6 @@ func Start(configPath string, platformInterface libbox.PlatformInterface) error func Stop() error { _, err := hcore.Stop() - return err } @@ -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) } diff --git a/v2/hcore/command_client.go b/v2/hcore/command_client.go index 0854076..f1a88b0 100644 --- a/v2/hcore/command_client.go +++ b/v2/hcore/command_client.go @@ -5,8 +5,9 @@ import ( "github.com/sagernet/sing-box/log" ) +var _ libbox.CommandClientHandler = (*CommandClientHandler)(nil) + type CommandClientHandler struct { - port int64 logger log.Logger } diff --git a/v2/hcore/commands.go b/v2/hcore/commands.go index 6c3c937..340ee87 100644 --- a/v2/hcore/commands.go +++ b/v2/hcore/commands.go @@ -2,7 +2,6 @@ package hcore import ( "context" - "time" common "github.com/hiddify/hiddify-core/v2/common" "github.com/sagernet/sing-box/experimental/libbox" @@ -10,9 +9,9 @@ import ( ) 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 ( @@ -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): } } } @@ -73,6 +72,7 @@ func (s *CoreService) OutboundsInfo(req *common.Empty, stream grpc.ServerStreami groupClient.Disconnect() groupClient = nil }() + groupClient.Connect() } @@ -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): } } } @@ -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): } } } diff --git a/v2/hcore/custom.go b/v2/hcore/custom.go index cdedca6..b1745b1 100644 --- a/v2/hcore/custom.go +++ b/v2/hcore/custom.go @@ -454,7 +454,7 @@ 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()) @@ -462,11 +462,9 @@ func Close() 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) { diff --git a/v2/hcore/grpc_server.go b/v2/hcore/grpc_server.go index df16d2c..a577783 100644 --- a/v2/hcore/grpc_server.go +++ b/v2/hcore/grpc_server.go @@ -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) } } diff --git a/v2/hcore/logproto.go b/v2/hcore/logproto.go index bd82e5f..14935e9 100644 --- a/v2/hcore/logproto.go +++ b/v2/hcore/logproto.go @@ -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 {