From fa966a490143eeea38175a3d8aa7761d417f2941 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Jun 2019 16:54:14 -0700 Subject: [PATCH] watchtower: add externalip CLI configuration --- watchtower/conf.go | 21 +++++++++++++++++++++ watchtower/config.go | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/watchtower/conf.go b/watchtower/conf.go index bf071ae8..653ed1e8 100644 --- a/watchtower/conf.go +++ b/watchtower/conf.go @@ -11,6 +11,9 @@ type Conf struct { // RawListeners configures the watchtower's listening ports/interfaces. RawListeners []string `long:"listen" description:"Add interfaces/ports to listen for peer connections"` + // RawExternalIPs configures the watchtower's external ports/interfaces. + RawExternalIPs []string `long:"externalip" description:"Add interfaces/ports where the watchtower can accept 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"` @@ -53,6 +56,24 @@ func (c *Conf) Apply(cfg *Config, } } + // Set the Config's external ips if they are empty. + if cfg.ExternalIPs == nil { + // Without a network, we will be unable to resolve the external + // IP addresses. + if cfg.Net == nil { + return nil, ErrNoNetwork + } + + var err error + cfg.ExternalIPs, err = normalizer( + c.RawExternalIPs, strconv.Itoa(DefaultPeerPort), + 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 { diff --git a/watchtower/config.go b/watchtower/config.go index f5b5721e..26dfac75 100644 --- a/watchtower/config.go +++ b/watchtower/config.go @@ -74,9 +74,13 @@ type Config struct { // have stronger guarantees wrt. returned error types. PublishTx func(*wire.MsgTx) error - // ListenAddrs specifies which address to which clients may connect. + // ListenAddrs specifies the listening addresses of the tower. ListenAddrs []net.Addr + // ExternalIPs specifies the addresses to which clients may connect to + // the tower. + ExternalIPs []net.Addr + // ReadTimeout specifies how long a client may go without sending a // message. ReadTimeout time.Duration