From db65d7ead464d35d41773ab1ff698c1dde076348 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 13 Jun 2019 17:30:39 -0700 Subject: [PATCH] watchtower/conf: remove experimental conditional compilation --- watchtower/conf.go | 74 ++++++++++++++++++++++++++++----- watchtower/conf_experimental.go | 65 ----------------------------- watchtower/errors.go | 5 --- 3 files changed, 64 insertions(+), 80 deletions(-) delete mode 100644 watchtower/conf_experimental.go diff --git a/watchtower/conf.go b/watchtower/conf.go index 9383d817..4f588e4c 100644 --- a/watchtower/conf.go +++ b/watchtower/conf.go @@ -1,14 +1,68 @@ -// +build !experimental - package watchtower -// Conf specifies the watchtower options that be configured from the command -// line or configuration file. In non-experimental builds, we disallow such -// configuration. -type Conf struct{} +import ( + "time" -// Apply returns an error signaling that the Conf could not be applied in -// non-experimental builds. -func (c *Conf) Apply(cfg *Config) (*Config, error) { - return nil, ErrNonExperimentalConf + "github.com/lightningnetwork/lnd/lncfg" +) + +// Conf specifies the watchtower options that can be configured from the command +// line or configuration file. +type Conf struct { + // RawListeners configures the watchtower's listening ports/interfaces. + RawListeners []string `long:"listen" description:"Add interfaces/ports to listen for peer connections"` + + // ReadTimeout specifies the duration the tower will wait when trying to + // read a message from a client before hanging up. + ReadTimeout time.Duration `long:"readtimeout" description:"Duration the watchtower server will wait for messages to be received before hanging up on clients"` + + // WriteTimeout specifies the duration the tower will wait when trying + // to write a message from a client before hanging up. + WriteTimeout time.Duration `long:"writetimeout" description:"Duration the watchtower server will wait for messages to be written before hanging up on client connections"` +} + +// Apply completes the passed Config struct by applying any parsed Conf options. +// If the corresponding values parsed by Conf are already set in the Config, +// those fields will be not be modified. +func (c *Conf) Apply(cfg *Config) (*Config, error) { + // Set the Config's listening addresses if they are empty. + if cfg.ListenAddrs == nil { + // Without a network, we will be unable to resolve the listening + // addresses. + if cfg.Net == nil { + return nil, ErrNoNetwork + } + + // If no addresses are specified by the Config, we will resort + // to the default peer port. + if len(c.RawListeners) == 0 { + addr := DefaultPeerPortStr + c.RawListeners = append(c.RawListeners, addr) + } + + // Normalize the raw listening addresses so that they can be + // used by the brontide listener. + var err error + cfg.ListenAddrs, err = lncfg.NormalizeAddresses( + c.RawListeners, DefaultPeerPortStr, + cfg.Net.ResolveTCPAddr, + ) + if err != nil { + return nil, err + } + } + + // If the Config has no read timeout, we will use the parsed Conf + // value. + if cfg.ReadTimeout == 0 && c.ReadTimeout != 0 { + cfg.ReadTimeout = c.ReadTimeout + } + + // If the Config has no write timeout, we will use the parsed Conf + // value. + if cfg.WriteTimeout == 0 && c.WriteTimeout != 0 { + cfg.WriteTimeout = c.WriteTimeout + } + + return cfg, nil } diff --git a/watchtower/conf_experimental.go b/watchtower/conf_experimental.go deleted file mode 100644 index 4b474998..00000000 --- a/watchtower/conf_experimental.go +++ /dev/null @@ -1,65 +0,0 @@ -// +build experimental - -package watchtower - -import ( - "time" - - "github.com/lightningnetwork/lnd/lncfg" -) - -// Conf specifies the watchtower options that can be configured from the command -// line or configuration file. -type Conf struct { - RawListeners []string `long:"listen" description:"Add interfaces/ports to listen for peer connections"` - - ReadTimeout time.Duration `long:"readtimeout" description:"Duration the watchtower server will wait for messages to be received before hanging up on clients"` - - WriteTimeout time.Duration `long:"writetimeout" description:"Duration the watchtower server will wait for messages to be written before hanging up on client connections"` -} - -// Apply completes the passed Config struct by applying any parsed Conf options. -// If the corresponding values parsed by Conf are already set in the Config, -// those fields will be not be modified. -func (c *Conf) Apply(cfg *Config) (*Config, error) { - // Set the Config's listening addresses if they are empty. - if cfg.ListenAddrs == nil { - // Without a network, we will be unable to resolve the listening - // addresses. - if cfg.Net == nil { - return nil, ErrNoNetwork - } - - // If no addresses are specified by the Config, we will resort - // to the default peer port. - if len(c.RawListeners) == 0 { - addr := DefaultPeerPortStr - c.RawListeners = append(c.RawListeners, addr) - } - - // Normalize the raw listening addresses so that they can be - // used by the brontide listener. - var err error - cfg.ListenAddrs, err = lncfg.NormalizeAddresses( - c.RawListeners, DefaultPeerPortStr, - cfg.Net.ResolveTCPAddr, - ) - if err != nil { - return nil, err - } - } - - // If the Config has no read timeout, we will use the parsed Conf - // value. - if cfg.ReadTimeout == 0 && c.ReadTimeout != 0 { - cfg.ReadTimeout = c.ReadTimeout - } - - // If the Config has no write timeout, we will use the parsed Conf - // value. - if cfg.WriteTimeout == 0 && c.WriteTimeout != 0 { - cfg.WriteTimeout = c.WriteTimeout - } - - return cfg, nil -} diff --git a/watchtower/errors.go b/watchtower/errors.go index e8682d4f..1ddeeb3f 100644 --- a/watchtower/errors.go +++ b/watchtower/errors.go @@ -7,11 +7,6 @@ var ( // rendering the tower unable to receive client requests. ErrNoListeners = errors.New("no listening ports were specified") - // ErrNonExperimentalConf signals that an attempt to apply a - // non-experimental Conf to a Config was detected. - ErrNonExperimentalConf = errors.New("cannot use watchtower in non-" + - "experimental builds") - // ErrNoNetwork signals that no tor.Net is provided in the Config, which // prevents resolution of listening addresses. ErrNoNetwork = errors.New("no network specified, must be tor or clearnet")