zones: add ResolvePublicAddresses() ScanOption to prevent early LookupIP calls
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -52,12 +52,16 @@ func (m *Machine) setID() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) scan() error {
|
func (m *Machine) scan(opts *ScanOptions) error {
|
||||||
for i := 0; i < RingsCount; i++ {
|
for i := 0; i < RingsCount; i++ {
|
||||||
if err := m.tryApplyWireguardConfig(i); err != nil {
|
if err := m.tryApplyWireguardConfig(i); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.updatePublicAddresses()
|
if !opts.DontResolvePublicAddresses {
|
||||||
|
return m.updatePublicAddresses()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-1
@@ -12,7 +12,22 @@ import (
|
|||||||
type ScanOption func(*Zones, *ScanOptions) error
|
type ScanOption func(*Zones, *ScanOptions) error
|
||||||
|
|
||||||
// ScanOptions contains flags used by the initial scan
|
// ScanOptions contains flags used by the initial scan
|
||||||
type ScanOptions struct{}
|
type ScanOptions struct {
|
||||||
|
// DontResolvePublicAddresses indicates we shouldn't
|
||||||
|
// pre-populate Machine.PublicAddresses during the
|
||||||
|
// initial scan
|
||||||
|
DontResolvePublicAddresses bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResolvePublicAddresses instructs the scanner to use
|
||||||
|
// the DNS resolver to get PublicAddresses of nodes.
|
||||||
|
// Default is true
|
||||||
|
func ResolvePublicAddresses(resolve bool) ScanOption {
|
||||||
|
return func(m *Zones, opt *ScanOptions) error {
|
||||||
|
opt.DontResolvePublicAddresses = !resolve
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithLookuper specifies what resolver.Lookuper to use to
|
// WithLookuper specifies what resolver.Lookuper to use to
|
||||||
// find public addresses
|
// find public addresses
|
||||||
|
|||||||
+2
-2
@@ -46,10 +46,10 @@ func (m *Zones) scanDirectory(_ *ScanOptions) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Zones) scanMachines(_ *ScanOptions) error {
|
func (m *Zones) scanMachines(opts *ScanOptions) error {
|
||||||
var err error
|
var err error
|
||||||
m.ForEachMachine(func(p *Machine) bool {
|
m.ForEachMachine(func(p *Machine) bool {
|
||||||
err = p.scan()
|
err = p.scan(opts)
|
||||||
return err != nil
|
return err != nil
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user