From c823878154104616240822eb4e13db27c6b643d7 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 13 Jun 2019 17:30:58 -0700 Subject: [PATCH] watchtower/conf: abstract address normalizer to prevent import cycle --- watchtower/conf.go | 8 ++++---- watchtower/interface.go | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/watchtower/conf.go b/watchtower/conf.go index 4f588e4c..21210995 100644 --- a/watchtower/conf.go +++ b/watchtower/conf.go @@ -2,8 +2,6 @@ package watchtower import ( "time" - - "github.com/lightningnetwork/lnd/lncfg" ) // 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. // 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) { +func (c *Conf) Apply(cfg *Config, + normalizer AddressNormalizer) (*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 @@ -43,7 +43,7 @@ func (c *Conf) Apply(cfg *Config) (*Config, error) { // Normalize the raw listening addresses so that they can be // used by the brontide listener. var err error - cfg.ListenAddrs, err = lncfg.NormalizeAddresses( + cfg.ListenAddrs, err = normalizer( c.RawListeners, DefaultPeerPortStr, cfg.Net.ResolveTCPAddr, ) diff --git a/watchtower/interface.go b/watchtower/interface.go index 59b1b848..cc7c08b4 100644 --- a/watchtower/interface.go +++ b/watchtower/interface.go @@ -1,6 +1,8 @@ package watchtower import ( + "net" + "github.com/lightningnetwork/lnd/watchtower/lookout" "github.com/lightningnetwork/lnd/watchtower/wtserver" ) @@ -12,3 +14,8 @@ type DB interface { lookout.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)