From 71fb8e5e8f7963829c8596316b359e3bf3c4e4ff Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 16 Feb 2021 13:39:38 +0100 Subject: [PATCH] rpc_proxy: prepare dialBackend to be more generic As a preparation for using the dialBackend function for other daemons/backends as well, we rename it from dialLnd and add a name parameter for more specific logs. --- rpc_proxy.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rpc_proxy.go b/rpc_proxy.go index 76c52b36..309cb861 100644 --- a/rpc_proxy.go +++ b/rpc_proxy.go @@ -130,7 +130,7 @@ func (p *rpcProxy) Start() error { // Setup the connection to lnd. host, _, tlsPath, _ := p.cfg.lndConnectParams() - p.lndConn, err = dialLnd(host, tlsPath) + p.lndConn, err = dialBackend("lnd", host, tlsPath) if err != nil { return fmt.Errorf("could not dial lnd: %v", err) } @@ -336,21 +336,20 @@ func (p *rpcProxy) basicAuthToMacaroon(ctx context.Context, return metadata.NewIncomingContext(ctx, md), nil } -// dialLnd connects to lnd through the given address and uses the given TLS -// certificate to authenticate the connection. -func dialLnd(dialAddr, tlsCertPath string) (*grpc.ClientConn, error) { - +// dialBackend connects to a gRPC backend through the given address and uses the +// given TLS certificate to authenticate the connection. +func dialBackend(name, dialAddr, tlsCertPath string) (*grpc.ClientConn, error) { var opts []grpc.DialOption tlsConfig, err := credentials.NewClientTLSFromFile(tlsCertPath, "") if err != nil { - return nil, fmt.Errorf("could not read lnd TLS cert %s: %v", - tlsCertPath, err) + return nil, fmt.Errorf("could not read %s TLS cert %s: %v", + name, tlsCertPath, err) } opts = append( opts, - // From the grpxProxy doc: This codec is *crucial* to the + // From the grpcProxy doc: This codec is *crucial* to the // functioning of the proxy. grpc.WithCodec(grpcProxy.Codec()), // nolint grpc.WithTransportCredentials(tlsConfig), @@ -361,10 +360,11 @@ func dialLnd(dialAddr, tlsCertPath string) (*grpc.ClientConn, error) { }), ) - log.Infof("Dialing lnd gRPC server at %s", dialAddr) + log.Infof("Dialing %s gRPC server at %s", name, dialAddr) cc, err := grpc.Dial(dialAddr, opts...) if err != nil { - return nil, fmt.Errorf("failed dialing backend: %v", err) + return nil, fmt.Errorf("failed dialing %s backend: %v", name, + err) } return cc, nil }