mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopd: add StartAsSubserver method and started flag
This commit is contained in:
parent
506d0c2257
commit
774a44fac1
1 changed files with 25 additions and 1 deletions
|
|
@ -100,7 +100,8 @@ func New(config *Config, lisCfg *listenerCfg) *Daemon {
|
|||
// execute commands and pass back swap status information.
|
||||
func (d *Daemon) Start() error {
|
||||
// There should be no reason to start the daemon twice. Therefore return
|
||||
// an error if that's tried.
|
||||
// an error if that's tried. This is mostly to guard against Start and
|
||||
// StartAsSubserver both being called.
|
||||
if atomic.AddInt32(&d.started, 1) != 1 {
|
||||
return errOnlyStartOnce
|
||||
}
|
||||
|
|
@ -136,6 +137,29 @@ func (d *Daemon) Start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// StartAsSubserver is an alternative to Start where the RPC server does not
|
||||
// create its own gRPC server but registers to an existing one. The same goes
|
||||
// for REST (if enabled), instead of creating an own mux and HTTP server, we
|
||||
// register to an existing one.
|
||||
func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices) error {
|
||||
// There should be no reason to start the daemon twice. Therefore return
|
||||
// an error if that's tried. This is mostly to guard against Start and
|
||||
// StartAsSubserver both being called.
|
||||
if atomic.AddInt32(&d.started, 1) != 1 {
|
||||
return errOnlyStartOnce
|
||||
}
|
||||
|
||||
// When starting as a subserver, we get passed in an already established
|
||||
// connection to lnd that might be shared among other subservers.
|
||||
d.lnd = lndGrpc
|
||||
|
||||
// With lnd already pre-connected, initialize everything else, such as
|
||||
// the swap server client, the RPC server instance and our main swap
|
||||
// handlers. If this fails, then nothing has been started yet and we can
|
||||
// just return the error.
|
||||
return d.initialize()
|
||||
}
|
||||
|
||||
// startWebServers starts the gRPC and REST servers in goroutines.
|
||||
func (d *Daemon) startWebServers() error {
|
||||
var err error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue