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

Function initBootstrap

internal/cmd/proxy.go:248–281  ·  view source on GitHub ↗

initBootstrap initializes the [upstream.Resolver] for bootstrapping upstream servers. It returns the default resolver if no bootstraps were specified. The returned resolver will also use system hosts files first.

(
	ctx context.Context,
	l *slog.Logger,
	bootstraps []string,
	opts *upstream.Options,
)

Source from the content-addressed store, hash-verified

246// servers. It returns the default resolver if no bootstraps were specified.
247// The returned resolver will also use system hosts files first.
248func initBootstrap(
249 ctx context.Context,
250 l *slog.Logger,
251 bootstraps []string,
252 opts *upstream.Options,
253) (r upstream.Resolver, err error) {
254 var resolvers []upstream.Resolver
255
256 for i, b := range bootstraps {
257 var ur *upstream.UpstreamResolver
258 ur, err = upstream.NewUpstreamResolver(b, opts)
259 if err != nil {
260 return nil, fmt.Errorf("creating bootstrap resolver at index %d: %w", i, err)
261 }
262
263 resolvers = append(resolvers, upstream.NewCachingResolver(ur))
264 }
265
266 switch len(resolvers) {
267 case 0:
268 etcHosts, hostsErr := upstream.NewDefaultHostsResolver(ctx, osutil.RootDirFS(), l)
269 if hostsErr != nil {
270 l.ErrorContext(ctx, "creating default hosts resolver", slogutil.KeyError, hostsErr)
271
272 return net.DefaultResolver, nil
273 }
274
275 return upstream.ConsequentResolver{etcHosts, net.DefaultResolver}, nil
276 case 1:
277 return resolvers[0], nil
278 default:
279 return upstream.ParallelResolver(resolvers), nil
280 }
281}
282
283// initEDNS inits EDNS-related config fields.
284func (conf *configuration) initEDNS(

Callers 1

initUpstreamsMethod · 0.85

Calls 3

NewUpstreamResolverFunction · 0.92
NewCachingResolverFunction · 0.92
NewDefaultHostsResolverFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…