netann: add new HostAnnouncer to support dynamic IPs via domains

In this commit, we add a new sub-system, then `HostAnnouncer` which
allows a users without a static IP address to ensure that lnd always
announces the most up to date address based on a domain name. A new
command line flag `--external-hosts` has been added which allows a user
to specify one or most hosts that should be periodically resolved to
update any advertised IPs the node has.

Fixes #1624.
This commit is contained in:
Olaoluwa Osuntokun
2020-05-12 17:05:18 -07:00
parent f9c6a1b73f
commit ba3688c3b9
4 changed files with 520 additions and 0 deletions

View File

@@ -80,6 +80,11 @@ const (
defaultAlias = ""
defaultColor = "#3399FF"
// defaultHostSampleInterval is the default amount of time that the
// HostAnnouncer will wait between DNS resolutions to check if the
// backing IP of a host has changed.
defaultHostSampleInterval = time.Minute * 5
)
var (
@@ -157,6 +162,7 @@ type Config struct {
RawRESTListeners []string `long:"restlisten" description:"Add an interface/port/socket to listen for REST connections"`
RawListeners []string `long:"listen" description:"Add an interface/port to listen for peer connections"`
RawExternalIPs []string `long:"externalip" description:"Add an ip:port to the list of local addresses we claim to listen on to peers. If a port is not specified, the default (9735) will be used regardless of other parameters"`
ExternalHosts []string `long:"externalhosts" description:"A set of hosts that should be periodically resolved to announce IPs for"`
RPCListeners []net.Addr
RESTListeners []net.Addr
RestCORS []string `long:"restcors" description:"Add an ip:port/hostname to allow cross origin access from. To allow all origins, set as \"*\"."`
@@ -659,6 +665,10 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
return nil, errors.New("NAT traversal cannot be used when " +
"listening is disabled")
}
if cfg.NAT && len(cfg.ExternalHosts) != 0 {
return nil, errors.New("NAT support and externalhosts are " +
"mutually exclusive, only one should be selected")
}
// Determine the active chain configuration and its parameters.
switch {