mirror of
https://github.com/lightninglabs/loop
synced 2024-11-08 01:10:29 +00:00
loopd/daemon: make server gRPC/REST listeners configurable
This commit is contained in:
parent
391ae9dc6b
commit
0f0573c047
@ -18,9 +18,18 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// listenerCfg holds closures used to retrieve listeners for the gRPC services.
|
||||
type listenerCfg struct {
|
||||
// grpcListener returns a listener to use for the gRPC server.
|
||||
grpcListener func() (net.Listener, error)
|
||||
|
||||
// restListener returns a listener to use for the REST proxy.
|
||||
restListener func() (net.Listener, error)
|
||||
}
|
||||
|
||||
// daemon runs loopd in daemon mode. It will listen for grpc connections,
|
||||
// execute commands and pass back swap status information.
|
||||
func daemon(config *config) error {
|
||||
func daemon(config *config, lisCfg *listenerCfg) error {
|
||||
lnd, err := getLnd(config.Network, config.Lnd)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -74,7 +83,7 @@ func daemon(config *config) error {
|
||||
|
||||
// Next, start the gRPC server listening for HTTP/2 connections.
|
||||
log.Infof("Starting gRPC listener")
|
||||
grpcListener, err := net.Listen("tcp", config.RPCListen)
|
||||
grpcListener, err := lisCfg.grpcListener()
|
||||
if err != nil {
|
||||
return fmt.Errorf("RPC server unable to listen on %s",
|
||||
config.RPCListen)
|
||||
@ -96,7 +105,7 @@ func daemon(config *config) error {
|
||||
}
|
||||
|
||||
log.Infof("Starting REST proxy listener")
|
||||
restListener, err := net.Listen("tcp", config.RESTListen)
|
||||
restListener, err := lisCfg.restListener()
|
||||
if err != nil {
|
||||
return fmt.Errorf("REST proxy unable to listen on %s",
|
||||
config.RESTListen)
|
||||
|
@ -2,6 +2,7 @@ package loopd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -26,6 +27,18 @@ var (
|
||||
swapsLock sync.Mutex
|
||||
)
|
||||
|
||||
// newListenerCfg creates and returns a new listenerCfg from the passed config.
|
||||
func newListenerCfg(config *config) *listenerCfg {
|
||||
return &listenerCfg{
|
||||
grpcListener: func() (net.Listener, error) {
|
||||
return net.Listen("tcp", config.RPCListen)
|
||||
},
|
||||
restListener: func() (net.Listener, error) {
|
||||
return net.Listen("tcp", config.RESTListen)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func Start() error {
|
||||
config := defaultConfig
|
||||
|
||||
@ -99,9 +112,11 @@ func Start() error {
|
||||
// Print the version before executing either primary directive.
|
||||
log.Infof("Version: %v", loop.Version())
|
||||
|
||||
lisCfg := newListenerCfg(&config)
|
||||
|
||||
// Execute command.
|
||||
if parser.Active == nil {
|
||||
return daemon(&config)
|
||||
return daemon(&config, lisCfg)
|
||||
}
|
||||
|
||||
if parser.Active.Name == "view" {
|
||||
|
Loading…
Reference in New Issue
Block a user