new: Extensions v0
This commit is contained in:
@@ -8,7 +8,9 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/hiddify/hiddify-core/extension"
|
||||
pb "github.com/hiddify/hiddify-core/hiddifyrpc"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
@@ -23,16 +25,16 @@ type TunnelService struct {
|
||||
pb.UnimplementedTunnelServiceServer
|
||||
}
|
||||
|
||||
func StartGrpcServer(listenAddressG string, service string) error {
|
||||
|
||||
func StartGrpcServer(listenAddressG string, service string) (*grpc.Server, error) {
|
||||
lis, err := net.Listen("tcp", listenAddressG)
|
||||
if err != nil {
|
||||
log.Printf("failed to listen: %v", err)
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
s := grpc.NewServer()
|
||||
if service == "core" {
|
||||
pb.RegisterCoreServer(s, &CoreService{})
|
||||
pb.RegisterExtensionHostServiceServer(s, &extension.ExtensionHostService{})
|
||||
} else if service == "hello" {
|
||||
pb.RegisterHelloServer(s, &HelloService{})
|
||||
} else if service == "tunnel" {
|
||||
@@ -43,17 +45,20 @@ func StartGrpcServer(listenAddressG string, service string) error {
|
||||
if err := s.Serve(lis); err != nil {
|
||||
log.Printf("failed to serve: %v", err)
|
||||
}
|
||||
log.Printf("Server stopped")
|
||||
// cancel()
|
||||
}()
|
||||
return nil
|
||||
return s, nil
|
||||
}
|
||||
func StartCoreGrpcServer(listenAddressG string) error {
|
||||
|
||||
func StartCoreGrpcServer(listenAddressG string) (*grpc.Server, error) {
|
||||
return StartGrpcServer(listenAddressG, "core")
|
||||
}
|
||||
|
||||
func StartHelloGrpcServer(listenAddressG string) error {
|
||||
func StartHelloGrpcServer(listenAddressG string) (*grpc.Server, error) {
|
||||
return StartGrpcServer(listenAddressG, "hello")
|
||||
}
|
||||
|
||||
func StartTunnelGrpcServer(listenAddressG string) error {
|
||||
func StartTunnelGrpcServer(listenAddressG string) (*grpc.Server, error) {
|
||||
return StartGrpcServer(listenAddressG, "tunnel")
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ type hiddifyNext struct{}
|
||||
var port int = 18020
|
||||
|
||||
func (m *hiddifyNext) Start(s service.Service) error {
|
||||
return StartTunnelGrpcServer(fmt.Sprintf("127.0.0.1:%d", port))
|
||||
_, err := StartTunnelGrpcServer(fmt.Sprintf("127.0.0.1:%d", port))
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *hiddifyNext) Stop(s service.Service) error {
|
||||
_, err := Stop()
|
||||
if err != nil {
|
||||
@@ -39,6 +41,7 @@ func getCurrentExecutableDirectory() string {
|
||||
|
||||
return executableDirectory
|
||||
}
|
||||
|
||||
func StartTunnelService(goArg string) (int, string) {
|
||||
svcConfig := &service.Config{
|
||||
Name: "HiddifyTunnelService",
|
||||
@@ -141,5 +144,4 @@ func control(s service.Service, goArg string) (int, string) {
|
||||
}
|
||||
return 2, out
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user