Skip to content

Commit

Permalink
Add unix socket as transport method to agent
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Bluhm <[email protected]>
  • Loading branch information
mbssrc committed Sep 3, 2024
1 parent 078fbf1 commit 13e76f5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 13 additions & 1 deletion internal/pkgs/grpc/grpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package grpc

import (
"context"
"fmt"
"time"

"givc/internal/pkgs/types"
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion internal/pkgs/grpc/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 13e76f5

Please sign in to comment.