zone.ScanOptions, custom resolver and prevent unnecessary DNS calls #5

Merged
amery merged 5 commits from pr-amery-scan_options into main 2023-08-28 18:10:40 +02:00
Showing only changes of commit 94daf5ad59 - Show all commits
+7 -5
View File
@@ -7,8 +7,9 @@ import (
"time"
)
func (m *Machine) lookupNetIP() ([]netip.Addr, error) {
timeout := 2 * time.Second
// LookupNetIP uses the DNS Resolver to get the public addresses associated
// to a Machine
func (m *Machine) LookupNetIP(timeout time.Duration) ([]netip.Addr, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
@@ -16,8 +17,9 @@ func (m *Machine) lookupNetIP() ([]netip.Addr, error) {
return m.zone.zones.resolver.LookupNetIP(ctx, "ip", m.FullName())
}
func (m *Machine) updatePublicAddresses() error {
addrs, err := m.lookupNetIP()
// UpdatePublicAddresses uses the DNS Resolver to set Machine.PublicAddresses
func (m *Machine) UpdatePublicAddresses() error {
addrs, err := m.LookupNetIP(2 * time.Second)
if err != nil {
return err
}
@@ -60,7 +62,7 @@ func (m *Machine) scan(opts *ScanOptions) error {
}
if !opts.DontResolvePublicAddresses {
return m.updatePublicAddresses()
return m.UpdatePublicAddresses()
}
return nil