resolver receiever consistency

This commit is contained in:
grumbulon 2022-09-16 19:20:00 -04:00
parent 790529267a
commit 80e7ded4fb
4 changed files with 42 additions and 42 deletions

View file

@ -19,28 +19,28 @@ type DNSCryptResolver struct {
var _ Resolver = (*DNSCryptResolver)(nil)
// LookUp performs a DNS query.
func (r *DNSCryptResolver) LookUp(msg *dns.Msg) (util.Response, error) {
func (resolver *DNSCryptResolver) LookUp(msg *dns.Msg) (util.Response, error) {
client := dnscrypt.Client{
Timeout: r.opts.Request.Timeout,
Timeout: resolver.opts.Request.Timeout,
UDPSize: 1232,
}
if r.opts.TCP || r.opts.TLS {
if resolver.opts.TCP || resolver.opts.TLS {
client.Net = tcp
} else {
client.Net = udp
}
switch {
case r.opts.IPv4:
case resolver.opts.IPv4:
client.Net += "4"
case r.opts.IPv6:
case resolver.opts.IPv6:
client.Net += "6"
}
r.opts.Logger.Debug("Using", client.Net, "for making the request")
resolver.opts.Logger.Debug("Using", client.Net, "for making the request")
resolverInf, err := client.Dial(r.opts.Request.Server)
resolverInf, err := client.Dial(resolver.opts.Request.Server)
if err != nil {
return util.Response{}, fmt.Errorf("dnscrypt: dial: %w", err)
}
@ -53,7 +53,7 @@ func (r *DNSCryptResolver) LookUp(msg *dns.Msg) (util.Response, error) {
return util.Response{}, fmt.Errorf("dnscrypt: exchange: %w", err)
}
r.opts.Logger.Info("Request successful")
resolver.opts.Logger.Info("Request successful")
return util.Response{
DNS: res,

View file

@ -21,11 +21,11 @@ type HTTPSResolver struct {
var _ Resolver = (*HTTPSResolver)(nil)
// LookUp performs a DNS query.
func (r *HTTPSResolver) LookUp(msg *dns.Msg) (util.Response, error) {
func (resolver *HTTPSResolver) LookUp(msg *dns.Msg) (util.Response, error) {
var resp util.Response
httpR := &http.Client{
Timeout: r.opts.Request.Timeout,
Timeout: resolver.opts.Request.Timeout,
}
buf, err := msg.Pack()
@ -33,9 +33,9 @@ func (r *HTTPSResolver) LookUp(msg *dns.Msg) (util.Response, error) {
return util.Response{}, fmt.Errorf("doh: packing: %w", err)
}
r.opts.Logger.Debug("https: sending HTTPS request")
resolver.opts.Logger.Debug("https: sending HTTPS request")
req, err := http.NewRequest("POST", r.opts.Request.Server, bytes.NewBuffer(buf))
req, err := http.NewRequest("POST", resolver.opts.Request.Server, bytes.NewBuffer(buf))
if err != nil {
return util.Response{}, fmt.Errorf("doh: request creation: %w", err)
}
@ -55,7 +55,7 @@ func (r *HTTPSResolver) LookUp(msg *dns.Msg) (util.Response, error) {
return util.Response{}, &errHTTPStatus{res.StatusCode}
}
r.opts.Logger.Debug("https: reading response")
resolver.opts.Logger.Debug("https: reading response")
fullRes, err := io.ReadAll(res.Body)
if err != nil {
@ -67,7 +67,7 @@ func (r *HTTPSResolver) LookUp(msg *dns.Msg) (util.Response, error) {
return util.Response{}, fmt.Errorf("doh: body close: %w", err)
}
r.opts.Logger.Debug("https: unpacking response")
resolver.opts.Logger.Debug("https: unpacking response")
resp.DNS = &dns.Msg{}

View file

@ -21,28 +21,28 @@ type QUICResolver struct {
var _ Resolver = (*QUICResolver)(nil)
// LookUp performs a DNS query.
func (r *QUICResolver) LookUp(msg *dns.Msg) (util.Response, error) {
func (resolver *QUICResolver) LookUp(msg *dns.Msg) (util.Response, error) {
var resp util.Response
tls := &tls.Config{
//nolint:gosec // This is intentional if the user requests it
InsecureSkipVerify: r.opts.TLSNoVerify,
ServerName: r.opts.TLSHost,
InsecureSkipVerify: resolver.opts.TLSNoVerify,
ServerName: resolver.opts.TLSHost,
MinVersion: tls.VersionTLS12,
NextProtos: []string{"doq"},
}
conf := new(quic.Config)
conf.HandshakeIdleTimeout = r.opts.Request.Timeout
conf.HandshakeIdleTimeout = resolver.opts.Request.Timeout
r.opts.Logger.Debug("quic: making query")
resolver.opts.Logger.Debug("quic: making query")
connection, err := quic.DialAddr(r.opts.Request.Server, tls, conf)
connection, err := quic.DialAddr(resolver.opts.Request.Server, tls, conf)
if err != nil {
return util.Response{}, fmt.Errorf("doq: dial: %w", err)
}
r.opts.Logger.Debug("quic: packing query")
resolver.opts.Logger.Debug("quic: packing query")
// Compress request to over-the-wire
buf, err := msg.Pack()
@ -52,21 +52,21 @@ func (r *QUICResolver) LookUp(msg *dns.Msg) (util.Response, error) {
t := time.Now()
r.opts.Logger.Debug("quic: creating stream")
resolver.opts.Logger.Debug("quic: creating stream")
stream, err := connection.OpenStream()
if err != nil {
return util.Response{}, fmt.Errorf("doq: quic stream creation: %w", err)
}
r.opts.Logger.Debug("quic: writing to stream")
resolver.opts.Logger.Debug("quic: writing to stream")
_, err = stream.Write(buf)
if err != nil {
return util.Response{}, fmt.Errorf("doq: quic stream write: %w", err)
}
r.opts.Logger.Debug("quic: reading stream")
resolver.opts.Logger.Debug("quic: reading stream")
fullRes, err := io.ReadAll(stream)
if err != nil {
@ -75,14 +75,14 @@ func (r *QUICResolver) LookUp(msg *dns.Msg) (util.Response, error) {
resp.RTT = time.Since(t)
r.opts.Logger.Debug("quic: closing connection")
resolver.opts.Logger.Debug("quic: closing connection")
// Close with error: no error
err = connection.CloseWithError(0, "")
if err != nil {
return util.Response{}, fmt.Errorf("doq: quic connection close: %w", err)
}
r.opts.Logger.Debug("quic: closing stream")
resolver.opts.Logger.Debug("quic: closing stream")
err = stream.Close()
if err != nil {
@ -91,7 +91,7 @@ func (r *QUICResolver) LookUp(msg *dns.Msg) (util.Response, error) {
resp.DNS = &dns.Msg{}
r.opts.Logger.Debug("quic: unpacking response")
resolver.opts.Logger.Debug("quic: unpacking response")
err = resp.DNS.Unpack(fullRes)
if err != nil {

View file

@ -19,7 +19,7 @@ type StandardResolver struct {
var _ Resolver = (*StandardResolver)(nil)
// LookUp performs a DNS query.
func (r *StandardResolver) LookUp(msg *dns.Msg) (util.Response, error) {
func (resolver *StandardResolver) LookUp(msg *dns.Msg) (util.Response, error) {
var (
resp util.Response
err error
@ -27,53 +27,53 @@ func (r *StandardResolver) LookUp(msg *dns.Msg) (util.Response, error) {
dnsClient := new(dns.Client)
dnsClient.Dialer = &net.Dialer{
Timeout: r.opts.Request.Timeout,
Timeout: resolver.opts.Request.Timeout,
}
if r.opts.TCP || r.opts.TLS {
if resolver.opts.TCP || resolver.opts.TLS {
dnsClient.Net = tcp
} else {
dnsClient.Net = udp
}
switch {
case r.opts.IPv4:
case resolver.opts.IPv4:
dnsClient.Net += "4"
case r.opts.IPv6:
case resolver.opts.IPv6:
dnsClient.Net += "6"
}
if r.opts.TLS {
if resolver.opts.TLS {
dnsClient.Net += "-tls"
dnsClient.TLSConfig = &tls.Config{
//nolint:gosec // This is intentional if the user requests it
InsecureSkipVerify: r.opts.TLSNoVerify,
ServerName: r.opts.TLSHost,
InsecureSkipVerify: resolver.opts.TLSNoVerify,
ServerName: resolver.opts.TLSHost,
}
}
r.opts.Logger.Debug("Using", dnsClient.Net, "for making the request")
resolver.opts.Logger.Debug("Using", dnsClient.Net, "for making the request")
resp.DNS, resp.RTT, err = dnsClient.Exchange(msg, r.opts.Request.Server)
resp.DNS, resp.RTT, err = dnsClient.Exchange(msg, resolver.opts.Request.Server)
if err != nil {
return util.Response{}, fmt.Errorf("standard: DNS exchange: %w", err)
}
r.opts.Logger.Info("Request successful")
resolver.opts.Logger.Info("Request successful")
if resp.DNS.MsgHdr.Truncated && !r.opts.Truncate {
if resp.DNS.MsgHdr.Truncated && !resolver.opts.Truncate {
fmt.Printf(";; Truncated, retrying with TCP\n\n")
dnsClient.Net = tcp
switch {
case r.opts.IPv4:
case resolver.opts.IPv4:
dnsClient.Net += "4"
case r.opts.IPv6:
case resolver.opts.IPv6:
dnsClient.Net += "6"
}
resp.DNS, resp.RTT, err = dnsClient.Exchange(msg, r.opts.Request.Server)
resp.DNS, resp.RTT, err = dnsClient.Exchange(msg, resolver.opts.Request.Server)
}
if err != nil {