mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
rpc_proxy: give the proxy access to basicLNDClient
This commit is contained in:
parent
2fc07fffee
commit
d3dc753b9b
2 changed files with 33 additions and 11 deletions
19
rpc_proxy.go
19
rpc_proxy.go
|
|
@ -18,6 +18,7 @@ import (
|
|||
litstatus "github.com/lightninglabs/lightning-terminal/status"
|
||||
"github.com/lightninglabs/lightning-terminal/subservers"
|
||||
"github.com/lightningnetwork/lnd/lncfg"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
|
||||
"google.golang.org/grpc"
|
||||
|
|
@ -69,7 +70,7 @@ func (e *proxyErr) Unwrap() error {
|
|||
func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
|
||||
superMacValidator session.SuperMacaroonValidator,
|
||||
permsMgr *perms.Manager, subServerMgr *subservers.Manager,
|
||||
statusMgr *litstatus.Manager) *rpcProxy {
|
||||
statusMgr *litstatus.Manager, getLNDClient lndBasicClientFn) *rpcProxy {
|
||||
|
||||
// The gRPC web calls are protected by HTTP basic auth which is defined
|
||||
// by base64(username:password). Because we only have a password, we
|
||||
|
|
@ -91,6 +92,7 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
|
|||
superMacValidator: superMacValidator,
|
||||
subServerMgr: subServerMgr,
|
||||
statusMgr: statusMgr,
|
||||
getBasicLNDClient: getLNDClient,
|
||||
}
|
||||
p.grpcServer = grpc.NewServer(
|
||||
// From the grpxProxy doc: This codec is *crucial* to the
|
||||
|
|
@ -161,11 +163,12 @@ type rpcProxy struct {
|
|||
// must only ever be used atomically.
|
||||
started int32
|
||||
|
||||
cfg *Config
|
||||
basicAuth string
|
||||
permsMgr *perms.Manager
|
||||
subServerMgr *subservers.Manager
|
||||
statusMgr *litstatus.Manager
|
||||
cfg *Config
|
||||
basicAuth string
|
||||
permsMgr *perms.Manager
|
||||
subServerMgr *subservers.Manager
|
||||
statusMgr *litstatus.Manager
|
||||
getBasicLNDClient lndBasicClientFn
|
||||
|
||||
bakeSuperMac bakeSuperMac
|
||||
|
||||
|
|
@ -183,6 +186,10 @@ type rpcProxy struct {
|
|||
// bakeSuperMac can be used to bake a new super macaroon.
|
||||
type bakeSuperMac func(ctx context.Context, rootKeyID uint32) (string, error)
|
||||
|
||||
// lndBasicClientFn can be used to obtain access to an lnrpc.LightningClient if
|
||||
// it is available.
|
||||
type lndBasicClientFn func() (lnrpc.LightningClient, error)
|
||||
|
||||
// Start creates initial connection to lnd.
|
||||
func (p *rpcProxy) Start(lndConn *grpc.ClientConn,
|
||||
bakeSuperMac bakeSuperMac) error {
|
||||
|
|
|
|||
25
terminal.go
25
terminal.go
|
|
@ -16,6 +16,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
restProxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
|
|
@ -174,10 +175,14 @@ type LightningTerminal struct {
|
|||
wg sync.WaitGroup
|
||||
errQueue *queue.ConcurrentQueue[error]
|
||||
|
||||
lndConnID string
|
||||
lndConn *grpc.ClientConn
|
||||
lndClient *lndclient.GrpcLndServices
|
||||
basicClient lnrpc.LightningClient
|
||||
lndConnID string
|
||||
lndConn *grpc.ClientConn
|
||||
lndClient *lndclient.GrpcLndServices
|
||||
|
||||
// basicClient may be accessed by other sub-systems but this access
|
||||
// should be provided via the basicLNDClient method.
|
||||
basicClient lnrpc.LightningClient
|
||||
basicClientSet atomic.Bool
|
||||
|
||||
subServerMgr *subservers.Manager
|
||||
statusMgr *status.Manager
|
||||
|
|
@ -297,7 +302,7 @@ func (g *LightningTerminal) Run() error {
|
|||
// server is started.
|
||||
g.rpcProxy = newRpcProxy(
|
||||
g.cfg, g, g.validateSuperMacaroon, g.permsMgr, g.subServerMgr,
|
||||
g.statusMgr,
|
||||
g.statusMgr, g.basicLNDClient,
|
||||
)
|
||||
|
||||
// Register any gRPC services that should be served using LiT's
|
||||
|
|
@ -728,6 +733,15 @@ func (g *LightningTerminal) start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// basicLNDClient provides access to LiT's basicClient if it has been set.
|
||||
func (g *LightningTerminal) basicLNDClient() (lnrpc.LightningClient, error) {
|
||||
if !g.basicClientSet.Load() {
|
||||
return nil, fmt.Errorf("basic LND client has not yet been set")
|
||||
}
|
||||
|
||||
return g.basicClient, nil
|
||||
}
|
||||
|
||||
// setUpLNDClients sets up the various LND clients required by LiT.
|
||||
func (g *LightningTerminal) setUpLNDClients(lndQuit chan struct{}) error {
|
||||
var (
|
||||
|
|
@ -805,6 +819,7 @@ func (g *LightningTerminal) setUpLNDClients(lndQuit chan struct{}) error {
|
|||
|
||||
log.Infof("Retrying to connect basic lnd client")
|
||||
}
|
||||
g.basicClientSet.Store(true)
|
||||
|
||||
// Now we know that the connection itself is ready. But we also need to
|
||||
// wait for two things: The chain notifier to be ready and the lnd
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue