Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Apr 16, 2024
1 parent 1c01e29 commit db2d75c
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions acator/grpcenclave/rpcclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
"google.golang.org/grpc"
)

var (
c authn.AuthnServiceClient
)

func New(cert, addr string, port int) (conn *grpc.ClientConn, err error) {
defer err2.Handle(&err)

Expand All @@ -29,6 +25,16 @@ func New(cert, addr string, port int) (conn *grpc.ClientConn, err error) {
return rpc.ClientConn(*cfg)
}

// ChCloser return error handler that closes all given channels.
func ChCloser[C ~chan T, T any](chs ...C) err2.Handler {
return func(err error) error {
for _, c := range chs {
close(c)
}
return err
}
}

func DoEnter(
conn *grpc.ClientConn,
ctx context.Context, //nolint: revive
Expand All @@ -39,16 +45,14 @@ func DoEnter(
) {
defer err2.Handle(&err)

c = authn.NewAuthnServiceClient(conn)
authnClient := authn.NewAuthnServiceClient(conn)
statusCh := make(chan *authn.CmdStatus)

stream := try.To1(c.Enter(ctx, cmd))
stream := try.To1(authnClient.Enter(ctx, cmd))
glog.V(3).Infoln("successful start of:", cmd.GetType())
go func() {
defer err2.Catch(err2.Err(func(err error) {
glog.V(3).Infoln("err when reading response", err)
close(statusCh)
}))
defer err2.Catch(ChCloser(statusCh), err2.Log)

for {
status, err := stream.Recv()
if try.IsEOF(err) {
Expand Down Expand Up @@ -76,14 +80,13 @@ func DoEnterSecret(
) {
defer err2.Handle(&err)

// we use the same client
//c := authn.NewAuthnServiceClient(conn)
authnClient := authn.NewAuthnServiceClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

glog.V(3).Infoln("going to send SecretMsg:", smsg.Type)
res = try.To1(c.EnterSecret(ctx, smsg))
res = try.To1(authnClient.EnterSecret(ctx, smsg))

glog.V(3).Infoln("successful sent of SecretMsg:", smsg.Type)
return res, nil
Expand Down

0 comments on commit db2d75c

Please sign in to comment.