watchtower: add externalip CLI configuration

This commit is contained in:
Conner Fromknecht 2019-06-20 16:54:14 -07:00
parent 7e81a5144e
commit fa966a4901
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 26 additions and 1 deletions

@ -11,6 +11,9 @@ type Conf struct {
// RawListeners configures the watchtower's listening ports/interfaces. // RawListeners configures the watchtower's listening ports/interfaces.
RawListeners []string `long:"listen" description:"Add interfaces/ports to listen for peer connections"` 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 // ReadTimeout specifies the duration the tower will wait when trying to
// read a message from a client before hanging up. // 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"` 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 // If the Config has no read timeout, we will use the parsed Conf
// value. // value.
if cfg.ReadTimeout == 0 && c.ReadTimeout != 0 { if cfg.ReadTimeout == 0 && c.ReadTimeout != 0 {

@ -74,9 +74,13 @@ type Config struct {
// have stronger guarantees wrt. returned error types. // have stronger guarantees wrt. returned error types.
PublishTx func(*wire.MsgTx) error 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 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 // ReadTimeout specifies how long a client may go without sending a
// message. // message.
ReadTimeout time.Duration ReadTimeout time.Duration