Browse Source

loopd/daemon: make server gRPC/REST listeners configurable

pull/115/head
Johan T. Halseth 1 year ago
parent
commit
0f0573c047
No known key found for this signature in database GPG Key ID: 15BAADA29DA20D26
2 changed files with 28 additions and 4 deletions
  1. +12
    -3
      loopd/daemon.go
  2. +16
    -1
      loopd/start.go

+ 12
- 3
loopd/daemon.go View File

@ -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)

+ 16
- 1
loopd/start.go View File

@ -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…
Cancel
Save