mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-11 01:11:02 +02:00
Lnd: Add BufListener to ListenerCfg for in-memory RPC calls to LND
This commit is contained in:
parent
c43b9e4fe7
commit
57fc32fe6a
29
lnd.go
29
lnd.go
@ -173,14 +173,19 @@ type ListenerWithSignal struct {
|
|||||||
|
|
||||||
// Ready will be closed by the server listening on Listener.
|
// Ready will be closed by the server listening on Listener.
|
||||||
Ready chan struct{}
|
Ready chan struct{}
|
||||||
|
|
||||||
|
// MacChan is an optional way to pass the admin macaroon to the program
|
||||||
|
// that started lnd. The channel should be buffered to avoid lnd being
|
||||||
|
// blocked on sending to the channel.
|
||||||
|
MacChan chan []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenerCfg is a wrapper around custom listeners that can be passed to lnd
|
// ListenerCfg is a wrapper around custom listeners that can be passed to lnd
|
||||||
// when calling its main method.
|
// when calling its main method.
|
||||||
type ListenerCfg struct {
|
type ListenerCfg struct {
|
||||||
// RPCListener can be set to the listener to use for the RPC server. If
|
// RPCListeners can be set to the listeners to use for the RPC server.
|
||||||
// nil a regular network listener will be created.
|
// If empty a regular network listener will be created.
|
||||||
RPCListener *ListenerWithSignal
|
RPCListeners []*ListenerWithSignal
|
||||||
|
|
||||||
// ExternalRPCSubserverCfg is optional and specifies the registration
|
// ExternalRPCSubserverCfg is optional and specifies the registration
|
||||||
// callback and permissions to register external gRPC subservers.
|
// callback and permissions to register external gRPC subservers.
|
||||||
@ -325,8 +330,8 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
|||||||
// If we have chosen to start with a dedicated listener for the
|
// If we have chosen to start with a dedicated listener for the
|
||||||
// rpc server, we set it directly.
|
// rpc server, we set it directly.
|
||||||
var grpcListeners []*ListenerWithSignal
|
var grpcListeners []*ListenerWithSignal
|
||||||
if lisCfg.RPCListener != nil {
|
if len(lisCfg.RPCListeners) > 0 {
|
||||||
grpcListeners = []*ListenerWithSignal{lisCfg.RPCListener}
|
grpcListeners = append(grpcListeners, lisCfg.RPCListeners...)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise we create listeners from the RPCListeners defined
|
// Otherwise we create listeners from the RPCListeners defined
|
||||||
// in the config.
|
// in the config.
|
||||||
@ -618,6 +623,12 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
|||||||
// The channel is buffered by one element so writing
|
// The channel is buffered by one element so writing
|
||||||
// should not block here.
|
// should not block here.
|
||||||
walletInitParams.MacResponseChan <- adminMacBytes
|
walletInitParams.MacResponseChan <- adminMacBytes
|
||||||
|
|
||||||
|
for _, lis := range grpcListeners {
|
||||||
|
if lis.MacChan != nil {
|
||||||
|
lis.MacChan <- adminMacBytes
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user requested a stateless initialization, no macaroon
|
// If the user requested a stateless initialization, no macaroon
|
||||||
@ -679,6 +690,14 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
|||||||
// --no-macaroons is used.
|
// --no-macaroons is used.
|
||||||
close(walletInitParams.MacResponseChan)
|
close(walletInitParams.MacResponseChan)
|
||||||
|
|
||||||
|
// We'll also close all the macaroon channels since lnd is done sending
|
||||||
|
// macaroon data over it.
|
||||||
|
for _, lis := range grpcListeners {
|
||||||
|
if lis.MacChan != nil {
|
||||||
|
close(lis.MacChan)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// With the information parsed from the configuration, create valid
|
// With the information parsed from the configuration, create valid
|
||||||
// instances of the pertinent interfaces required to operate the
|
// instances of the pertinent interfaces required to operate the
|
||||||
// Lightning Network Daemon.
|
// Lightning Network Daemon.
|
||||||
|
@ -94,10 +94,10 @@ func Start(extraArgs string, rpcReady Callback) {
|
|||||||
// We call the main method with the custom in-memory listener called by
|
// We call the main method with the custom in-memory listener called by
|
||||||
// the mobile APIs, such that the grpc server will use it.
|
// the mobile APIs, such that the grpc server will use it.
|
||||||
cfg := lnd.ListenerCfg{
|
cfg := lnd.ListenerCfg{
|
||||||
RPCListener: &lnd.ListenerWithSignal{
|
RPCListeners: []*lnd.ListenerWithSignal{{
|
||||||
Listener: lightningLis,
|
Listener: lightningLis,
|
||||||
Ready: rpcListening,
|
Ready: rpcListening,
|
||||||
},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the "real" main in a nested manner so the defers will properly
|
// Call the "real" main in a nested manner so the defers will properly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user