chore(updater): create resolver in provider updater
- Pass min servers to resolve call - Set settings when constructing resolver - Construct resolver in each provider updater - No more common resolver for all providers
This commit is contained in:
@@ -11,20 +11,23 @@ import (
|
||||
)
|
||||
|
||||
type Repeat interface {
|
||||
Resolve(ctx context.Context, host string, settings RepeatSettings) (IPs []net.IP, err error)
|
||||
Resolve(ctx context.Context, host string) (IPs []net.IP, err error)
|
||||
}
|
||||
|
||||
type repeat struct {
|
||||
resolver *net.Resolver
|
||||
settings RepeatSettings
|
||||
}
|
||||
|
||||
func NewRepeat(address string) Repeat {
|
||||
func NewRepeat(settings RepeatSettings) Repeat {
|
||||
return &repeat{
|
||||
resolver: newResolver(address),
|
||||
resolver: newResolver(settings.Address),
|
||||
settings: settings,
|
||||
}
|
||||
}
|
||||
|
||||
type RepeatSettings struct {
|
||||
Address string
|
||||
MaxDuration time.Duration
|
||||
BetweenDuration time.Duration
|
||||
MaxNoNew int
|
||||
@@ -33,8 +36,8 @@ type RepeatSettings struct {
|
||||
SortIPs bool
|
||||
}
|
||||
|
||||
func (r *repeat) Resolve(ctx context.Context, host string, settings RepeatSettings) (ips []net.IP, err error) {
|
||||
timedCtx, cancel := context.WithTimeout(ctx, settings.MaxDuration)
|
||||
func (r *repeat) Resolve(ctx context.Context, host string) (ips []net.IP, err error) {
|
||||
timedCtx, cancel := context.WithTimeout(ctx, r.settings.MaxDuration)
|
||||
defer cancel()
|
||||
|
||||
noNewCounter := 0
|
||||
@@ -45,7 +48,7 @@ func (r *repeat) Resolve(ctx context.Context, host string, settings RepeatSettin
|
||||
// TODO
|
||||
// - one resolving every 100ms for round robin DNS responses
|
||||
// - one every second for time based DNS cycling responses
|
||||
noNewCounter, failCounter, err = r.resolveOnce(ctx, timedCtx, host, settings, uniqueIPs, noNewCounter, failCounter)
|
||||
noNewCounter, failCounter, err = r.resolveOnce(ctx, timedCtx, host, r.settings, uniqueIPs, noNewCounter, failCounter)
|
||||
}
|
||||
|
||||
if len(uniqueIPs) == 0 {
|
||||
@@ -54,7 +57,7 @@ func (r *repeat) Resolve(ctx context.Context, host string, settings RepeatSettin
|
||||
|
||||
ips = uniqueIPsToSlice(uniqueIPs)
|
||||
|
||||
if settings.SortIPs {
|
||||
if r.settings.SortIPs {
|
||||
sort.Slice(ips, func(i, j int) bool {
|
||||
return bytes.Compare(ips[i], ips[j]) < 1
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user