Merge pull request #4281 from Roasbeef/host-ann
netann: add new HostAnnouncer to support dynamic IPs via domains
This commit is contained in:
4 files changed
+520
No files matched your search
@@ -272,6 +272,8 @@ type server struct {
|
||||
// provide insights into their health and performance.
|
||||
chanEventStore *chanfitness.ChannelEventStore
|
||||
|
||||
hostAnn *netann.HostAnnouncer
|
||||
|
||||
quit chan struct{}
|
||||
|
||||
wg sync.WaitGroup
|
||||
@@ -1224,6 +1226,26 @@ func newServer(cfg *Config, listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
}
|
||||
}
|
||||
|
||||
if len(cfg.ExternalHosts) != 0 {
|
||||
advertisedIPs := make(map[string]struct{})
|
||||
for _, addr := range s.currentNodeAnn.Addresses {
|
||||
advertisedIPs[addr.String()] = struct{}{}
|
||||
}
|
||||
|
||||
s.hostAnn = netann.NewHostAnnouncer(netann.HostAnnouncerConfig{
|
||||
Hosts: cfg.ExternalHosts,
|
||||
RefreshTicker: ticker.New(defaultHostSampleInterval),
|
||||
LookupHost: func(host string) (net.Addr, error) {
|
||||
return lncfg.ParseAddressString(
|
||||
host, strconv.Itoa(defaultPeerPort),
|
||||
cfg.net.ResolveTCPAddr,
|
||||
)
|
||||
},
|
||||
AdvertisedIPs: advertisedIPs,
|
||||
AnnounceNewIPs: netann.IPAnnouncer(s.genNodeAnnouncement),
|
||||
})
|
||||
}
|
||||
|
||||
// Create the connection manager which will be responsible for
|
||||
// maintaining persistent outbound connections and also accepting new
|
||||
// incoming connections
|
||||
@@ -1267,6 +1289,13 @@ func (s *server) Start() error {
|
||||
go s.watchExternalIP()
|
||||
}
|
||||
|
||||
if s.hostAnn != nil {
|
||||
if err := s.hostAnn.Start(); err != nil {
|
||||
startErr = err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Start the notification server. This is used so channel
|
||||
// management goroutines can be notified when a funding
|
||||
// transaction reaches a sufficient number of confirmations, or
|
||||
@@ -1491,6 +1520,13 @@ func (s *server) Stop() error {
|
||||
s.towerClient.Stop()
|
||||
}
|
||||
|
||||
if s.hostAnn != nil {
|
||||
if err := s.hostAnn.Stop(); err != nil {
|
||||
srvrLog.Warnf("unable to shut down host "+
|
||||
"annoucner: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for all lingering goroutines to quit.
|
||||
s.wg.Wait()
|
||||
|
||||
|
||||
Reference in new issue
Block a user