MCPcopy
hub / github.com/AdguardTeam/dnsproxy / LookupNetIP

Method LookupNetIP

internal/bootstrap/resolver.go:34–67  ·  view source on GitHub ↗

LookupNetIP implements the [Resolver] interface for ParallelResolver.

(
	ctx context.Context,
	network Network,
	host string,
)

Source from the content-addressed store, hash-verified

32
33// LookupNetIP implements the [Resolver] interface for ParallelResolver.
34func (r ParallelResolver) LookupNetIP(
35 ctx context.Context,
36 network Network,
37 host string,
38) (addrs []netip.Addr, err error) {
39 resolversNum := len(r)
40 switch resolversNum {
41 case 0:
42 return nil, ErrNoResolvers
43 case 1:
44 return r[0].LookupNetIP(ctx, network, host)
45 default:
46 // Go on.
47 }
48
49 // Size of channel must accommodate results of lookups from all resolvers,
50 // sending into channel will block otherwise.
51 ch := make(chan any, resolversNum)
52 for _, rslv := range r {
53 go lookupAsync(ctx, rslv, network, host, ch)
54 }
55
56 var errs []error
57 for range r {
58 switch result := <-ch; result := result.(type) {
59 case error:
60 errs = append(errs, result)
61 case []netip.Addr:
62 return result, nil
63 }
64 }
65
66 return nil, errors.Join(errs...)
67}
68
69// recoverAndLog is a deferred helper that recovers from a panic and logs the
70// panic value with the logger from context or with a default one. It sends the

Callers

nothing calls this directly

Calls 2

lookupAsyncFunction · 0.85
LookupNetIPMethod · 0.65

Tested by

no test coverage detected