mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
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.
This commit is contained in:
parent
a8a4da8c98
commit
71fb8e5e8f
1 changed files with 10 additions and 10 deletions
20
rpc_proxy.go
20
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue