Browse Source

watchtower: add externalip CLI configuration

master
Conner Fromknecht 5 years ago
parent
commit
fa966a4901
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
  1. 21
      watchtower/conf.go
  2. 6
      watchtower/config.go

21
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 {

6
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

Loading…
Cancel
Save