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

Function AddressToUpstream

upstream/upstream.go:188–217  ·  view source on GitHub ↗

AddressToUpstream converts addr to an Upstream using the specified options. addr can be either a URL, or a plain address, either a domain name or an IP. - 1.2.3.4 or 1.2.3.4:4321 for plain DNS using IP address; - udp://5.3.5.3:53 or 5.3.5.3:53 for plain DNS using IP address; - udp://name.server:53

(addr string, opts *Options)

Source from the content-addressed store, hash-verified

186//
187// TODO(e.burkov): Clone opts?
188func AddressToUpstream(addr string, opts *Options) (u Upstream, err error) {
189 if opts == nil {
190 opts = &Options{}
191 }
192
193 if opts.Logger == nil {
194 opts.Logger = slog.Default()
195 }
196
197 var uu *url.URL
198 if strings.Contains(addr, "://") {
199 uu, err = url.Parse(addr)
200 if err != nil {
201 return nil, fmt.Errorf("failed to parse %s: %w", addr, err)
202 }
203 } else {
204 uu = &url.URL{
205 Scheme: "udp",
206 Host: addr,
207 }
208 }
209
210 err = validateUpstreamURL(uu)
211 if err != nil {
212 // Don't wrap the error, because it's informative enough as is.
213 return nil, err
214 }
215
216 return urlToUpstream(uu, opts)
217}
218
219// validateUpstreamURL returns an error if the upstream URL is not valid.
220func validateUpstreamURL(u *url.URL) (err error) {

Callers 15

TestLookupNetIPFunction · 0.92
specifyUpstreamMethod · 0.92
TestUpstreamDNSCryptFunction · 0.85
TestUpstreamDoHFunction · 0.85
TestUpstreamDoH_0RTTFunction · 0.85
TestUpstream_dnsOverTLSFunction · 0.85

Calls 2

validateUpstreamURLFunction · 0.85
urlToUpstreamFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…