Skip to content

Commit

Permalink
all: imp docs, restore behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Nov 8, 2023
1 parent aeda179 commit 1823da5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
20 changes: 9 additions & 11 deletions internal/bootstrap/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ Resolver = &net.Resolver{}
const ErrNoResolvers errors.Error = "no resolvers specified"

// ParallelResolver is a slice of resolvers that are queried concurrently. The
// first successful non-empty response is returned.
// first successful response is returned.
type ParallelResolver []Resolver

// type check
Expand Down Expand Up @@ -67,30 +67,28 @@ func (r ParallelResolver) LookupNetIP(
return nil, errors.Join(errs...)
}

// lookupAsync tries to lookup for ip of host with r and sends the result into
// resCh. It's inteneded to be used as a goroutine.
func lookupAsync(
ctx context.Context,
r Resolver,
network,
host string,
resCh chan<- any,
) {
// lookupAsync performs a lookup for ip of host with r and sends the result into
// resCh. It's inteneded to be used within a separate goroutine.
func lookupAsync(ctx context.Context, r Resolver, network string, host string, resCh chan<- any) {
defer log.OnPanic("parallel lookup")

addrs, err := lookup(ctx, r, network, host)
if err != nil || len(addrs) == 0 {
if err != nil {
resCh <- err
} else {
resCh <- addrs
}
}

// lookup tries to lookup ip of host with r.
//
// TODO(e.burkov): Get rid of this function? It only wraps the actual lookup
// with dubious logging.
func lookup(ctx context.Context, r Resolver, network, host string) (addrs []netip.Addr, err error) {
start := time.Now()
addrs, err = r.LookupNetIP(ctx, network, host)
elapsed := time.Since(start)

if err != nil {
log.Debug("parallel lookup: lookup for %s failed in %s: %s", host, elapsed, err)
} else {
Expand Down
3 changes: 2 additions & 1 deletion upstream/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ func (r StaticResolver) LookupNetIP(
}

// ConsequentResolver is a slice of resolvers that are queried in order until
// the first successful non-empty response.
// the first successful non-empty response, as opposed to just successful
// response requirement in [ParallelResolver].
type ConsequentResolver []Resolver

// type check
Expand Down

0 comments on commit 1823da5

Please sign in to comment.