DoH Delete old code

This commit is contained in:
Vladimir 2022-04-13 19:32:36 +03:00
parent 4a7ab13bf5
commit 0d21ee7d0d

View file

@ -2,13 +2,8 @@ package resolver
import ( import (
"context" "context"
"encoding/base64"
"errors" "errors"
"fmt"
"io/ioutil"
"net" "net"
"net/http"
"strings"
"time" "time"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -45,7 +40,7 @@ func (pr *PlainResolver) Query(ctx context.Context, q *Query) (*RRCache, error)
// create query // create query
dnsQuery := new(dns.Msg) dnsQuery := new(dns.Msg)
dnsQuery.SetQuestion(q.FQDN, uint16(q.QType)) dnsQuery.SetQuestion(q.FQDN, uint16(q.QType))
var reply *dns.Msg
// get timeout from context and config // get timeout from context and config
var timeout time.Duration var timeout time.Duration
if deadline, ok := ctx.Deadline(); !ok { if deadline, ok := ctx.Deadline(); !ok {
@ -57,51 +52,32 @@ func (pr *PlainResolver) Query(ctx context.Context, q *Query) (*RRCache, error)
timeout = defaultRequestTimeout timeout = defaultRequestTimeout
} }
if strings.HasPrefix(pr.resolver.ServerAddress, "https:") { // create client
buf, err := dnsQuery.Pack() dnsClient := &dns.Client{
Timeout: timeout,
Dialer: &net.Dialer{
Timeout: timeout,
LocalAddr: getLocalAddr("udp"),
},
}
if err != nil { // query server
return nil, err reply, ttl, err := dnsClient.Exchange(dnsQuery, pr.resolver.ServerAddress)
log.Tracer(ctx).Tracef("resolver: query took %s", ttl)
// error handling
if err != nil {
// Hint network environment at failed connection if err is not a timeout.
var nErr net.Error
if errors.As(err, &nErr) && !nErr.Timeout() {
netenv.ReportFailedConnection()
} }
b64dns := base64.RawStdEncoding.EncodeToString(buf) return nil, err
url := fmt.Sprintf("%s/dns-query?dns=%s", pr.resolver.ServerAddress, b64dns) }
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
reply := new(dns.Msg)
reply.Unpack(body)
} else {
// create client
dnsClient := &dns.Client{
Timeout: timeout,
Dialer: &net.Dialer{
Timeout: timeout,
LocalAddr: getLocalAddr("udp"),
},
}
// query server // check if blocked
reply, ttl, err := dnsClient.Exchange(dnsQuery, pr.resolver.ServerAddress) if pr.resolver.IsBlockedUpstream(reply) {
log.Tracer(ctx).Tracef("resolver: query took %s", ttl) return nil, &BlockedUpstreamError{pr.resolver.Info.DescriptiveName()}
// error handling
if err != nil {
// Hint network environment at failed connection if err is not a timeout.
var nErr net.Error
if errors.As(err, &nErr) && !nErr.Timeout() {
netenv.ReportFailedConnection()
}
return nil, err
}
// check if blocked
if pr.resolver.IsBlockedUpstream(reply) {
return nil, &BlockedUpstreamError{pr.resolver.Info.DescriptiveName()}
}
} }
// hint network environment at successful connection // hint network environment at successful connection