watchtower/conf: abstract address normalizer to prevent import cycle

This commit is contained in:
Conner Fromknecht 2019-06-13 17:30:58 -07:00
parent db65d7ead4
commit c823878154
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 11 additions and 4 deletions

@ -2,8 +2,6 @@ package watchtower
import ( import (
"time" "time"
"github.com/lightningnetwork/lnd/lncfg"
) )
// Conf specifies the watchtower options that can be configured from the command // Conf specifies the watchtower options that can be configured from the command
@ -24,7 +22,9 @@ type Conf struct {
// Apply completes the passed Config struct by applying any parsed Conf options. // 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, // If the corresponding values parsed by Conf are already set in the Config,
// those fields will be not be modified. // those fields will be not be modified.
func (c *Conf) Apply(cfg *Config) (*Config, error) { func (c *Conf) Apply(cfg *Config,
normalizer AddressNormalizer) (*Config, error) {
// Set the Config's listening addresses if they are empty. // Set the Config's listening addresses if they are empty.
if cfg.ListenAddrs == nil { if cfg.ListenAddrs == nil {
// Without a network, we will be unable to resolve the listening // Without a network, we will be unable to resolve the listening
@ -43,7 +43,7 @@ func (c *Conf) Apply(cfg *Config) (*Config, error) {
// Normalize the raw listening addresses so that they can be // Normalize the raw listening addresses so that they can be
// used by the brontide listener. // used by the brontide listener.
var err error var err error
cfg.ListenAddrs, err = lncfg.NormalizeAddresses( cfg.ListenAddrs, err = normalizer(
c.RawListeners, DefaultPeerPortStr, c.RawListeners, DefaultPeerPortStr,
cfg.Net.ResolveTCPAddr, cfg.Net.ResolveTCPAddr,
) )

@ -1,6 +1,8 @@
package watchtower package watchtower
import ( import (
"net"
"github.com/lightningnetwork/lnd/watchtower/lookout" "github.com/lightningnetwork/lnd/watchtower/lookout"
"github.com/lightningnetwork/lnd/watchtower/wtserver" "github.com/lightningnetwork/lnd/watchtower/wtserver"
) )
@ -12,3 +14,8 @@ type DB interface {
lookout.DB lookout.DB
wtserver.DB wtserver.DB
} }
// AddressNormalizer is a function signature that allows the tower to resolve
// TCP addresses on clear or onion networks.
type AddressNormalizer func(addrs []string, defaultPort string,
resolver func(string, string) (*net.TCPAddr, error)) ([]net.Addr, error)