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

Function createProxyConfig

internal/cmd/proxy.go:37–125  ·  view source on GitHub ↗

TODO(e.burkov): Use a separate type for the YAML configuration file. createProxyConfig initializes [proxy.Config]. l must not be nil.

(
	ctx context.Context,
	l *slog.Logger,
	conf *configuration,
)

Source from the content-addressed store, hash-verified

35
36// createProxyConfig initializes [proxy.Config]. l must not be nil.
37func createProxyConfig(
38 ctx context.Context,
39 l *slog.Logger,
40 conf *configuration,
41) (proxyConf *proxy.Config, err error) {
42 hostsFiles, err := conf.hostsFiles(ctx, l)
43 if err != nil {
44 // Don't wrap the error since it's informative enough as is.
45 return nil, err
46 }
47
48 hosts, err := middleware.ReadHosts(ctx, l, hostsFiles)
49 if err != nil {
50 return nil, fmt.Errorf("reading hosts files: %w", err)
51 }
52
53 preMw := middleware.New(&middleware.Config{
54 Logger: l.With(slogutil.KeyPrefix, "pre_handler_mw"),
55 // TODO(e.burkov): Use the configured message constructor.
56 MessageConstructor: dnsmsg.DefaultMessageConstructor{},
57 HaltIPv6: conf.IPv6Disabled,
58 HostsFiles: hosts,
59 })
60
61 ratelimitMw, err := conf.newRatelimitMw(l)
62 if err != nil {
63 return nil, fmt.Errorf("ratelimit mw: %w", err)
64 }
65
66 httpConf := &proxy.HTTPConfig{
67 ServerHeader: conf.HTTPSServerName,
68 Routes: conf.DoHRoutes,
69 ReadTimeout: defaultHTTPTimeout,
70 WriteTimeout: defaultHTTPTimeout,
71 HTTP3Enabled: conf.HTTP3,
72 InsecureEnabled: conf.DoHInsecureEnabled,
73 }
74
75 if uiStr := conf.HTTPSUserinfo; uiStr != "" {
76 user, pass, ok := strings.Cut(uiStr, ":")
77 if ok {
78 httpConf.Userinfo = url.UserPassword(user, pass)
79 } else {
80 httpConf.Userinfo = url.User(user)
81 }
82 }
83
84 proxyConf = &proxy.Config{
85 Logger: l.With(slogutil.KeyPrefix, proxy.LogPrefix),
86 CacheEnabled: conf.Cache,
87 CacheSizeBytes: conf.CacheSizeBytes,
88 CacheMinTTL: conf.CacheMinTTL,
89 CacheMaxTTL: conf.CacheMaxTTL,
90 CacheOptimisticAnswerTTL: time.Duration(conf.OptimisticAnswerTTL),
91 CacheOptimisticMaxAge: time.Duration(conf.OptimisticMaxAge),
92 CacheOptimistic: conf.CacheOptimistic,
93 RefuseAny: conf.RefuseAny,
94 // TODO(e.burkov): The following CIDRs are aimed to match any address.

Callers 1

runProxyFunction · 0.85

Calls 12

ReadHostsFunction · 0.92
NewFunction · 0.92
hostsFilesMethod · 0.80
newRatelimitMwMethod · 0.80
initBogusNXDomainMethod · 0.80
initUpstreamsMethod · 0.80
initEDNSMethod · 0.80
initTLSConfigMethod · 0.80
initDNSCryptConfigMethod · 0.80
initListenAddrsMethod · 0.80
initSubnetsMethod · 0.80
WrapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…