From 13e76f5ff1fe7b5856c1004276d8257c38b0a8ae Mon Sep 17 00:00:00 2001 From: Manuel Bluhm Date: Tue, 3 Sep 2024 13:20:21 +0400 Subject: [PATCH] Add unix socket as transport method to agent Signed-off-by: Manuel Bluhm --- internal/pkgs/grpc/grpcclient.go | 14 +++++++++++++- internal/pkgs/grpc/grpcserver.go | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/internal/pkgs/grpc/grpcclient.go b/internal/pkgs/grpc/grpcclient.go index 129baa7..a5a95b0 100644 --- a/internal/pkgs/grpc/grpcclient.go +++ b/internal/pkgs/grpc/grpcclient.go @@ -4,6 +4,7 @@ package grpc import ( "context" + "fmt" "time" "givc/internal/pkgs/types" @@ -65,7 +66,18 @@ func NewClient(cfg *types.EndpointConfig, allowLongWaits bool) (*grpc.ClientConn } options = append(options, grpc.WithChainUnaryInterceptor(interceptors...)) - return grpc.NewClient(cfg.Transport.Address+":"+cfg.Transport.Port, options...) + // Set address + var addr string + switch cfg.Transport.Protocol { + case "tcp": + addr = cfg.Transport.Address + ":" + cfg.Transport.Port + case "unix": + addr = cfg.Transport.Address + default: + return nil, fmt.Errorf("unsupported protocol: %s", cfg.Transport.Protocol) + } + + return grpc.NewClient(addr, options...) } func withOutgoingContext(ctx context.Context, method string, req, resp interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { diff --git a/internal/pkgs/grpc/grpcserver.go b/internal/pkgs/grpc/grpcserver.go index 50776c3..9c01f3c 100644 --- a/internal/pkgs/grpc/grpcserver.go +++ b/internal/pkgs/grpc/grpcserver.go @@ -85,7 +85,18 @@ func (s *GrpcServer) ListenAndServe(ctx context.Context, started chan struct{}) var err error var listener net.Listener - addr := s.config.Transport.Address + ":" + s.config.Transport.Port + var addr string + + // Set address + switch s.config.Transport.Protocol { + case "tcp": + addr = s.config.Transport.Address + ":" + s.config.Transport.Port + case "unix": + addr = s.config.Transport.Address + default: + return fmt.Errorf("unsupported protocol: %s", s.config.Transport.Protocol) + } + for i := 0; i < LISTENER_RETRIES; i++ { listener, err = net.Listen(s.config.Transport.Protocol, addr) if err != nil {