new: Extensions v0

This commit is contained in:
x
2024-09-26 23:16:20 +02:00
parent a4caf23ee6
commit 0f9f6689b1
40 changed files with 19948 additions and 1675 deletions

View File

@@ -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")
}