Skip to content

Commit 6ae357d

Browse files
authored
Revert doh (miekg#800)
* Revert "Require URLs for DOH addresses (miekg#684)" This reverts commit 8ccae88. * Revert "WIP: DNS-over-HTTPS support for Client.Exchange API (miekg#671)" This reverts commit 64746df. Signed-off-by: Miek Gieben <[email protected]> * Finish revert of DoH Signed-off-by: Miek Gieben <[email protected]> * Add back in the race condition comment Signed-off-by: Miek Gieben <[email protected]>
1 parent 915ca3d commit 6ae357d

File tree

3 files changed

+1
-103
lines changed

3 files changed

+1
-103
lines changed

client.go

+1-82
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@ import (
77
"context"
88
"crypto/tls"
99
"encoding/binary"
10-
"fmt"
1110
"io"
12-
"io/ioutil"
1311
"net"
14-
"net/http"
1512
"strings"
1613
"time"
1714
)
1815

1916
const (
2017
dnsTimeout time.Duration = 2 * time.Second
2118
tcpIdleTimeout time.Duration = 8 * time.Second
22-
23-
dohMimeType = "application/dns-message"
2419
)
2520

2621
// A Conn represents a connection to a DNS server.
@@ -44,7 +39,6 @@ type Client struct {
4439
DialTimeout time.Duration // net.DialTimeout, defaults to 2 seconds, or net.Dialer.Timeout if expiring earlier - overridden by Timeout when that value is non-zero
4540
ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections, defaults to 2 seconds - overridden by Timeout when that value is non-zero
4641
WriteTimeout time.Duration // net.Conn.SetWriteTimeout value for connections, defaults to 2 seconds - overridden by Timeout when that value is non-zero
47-
HTTPClient *http.Client // The http.Client to use for DNS-over-HTTPS
4842
TsigSecret map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>, zonename must be in canonical form (lowercase, fqdn, see RFC 4034 Section 6.2)
4943
SingleInflight bool // if true suppress multiple outstanding queries for the same Qname, Qtype and Qclass
5044
group singleflight
@@ -132,11 +126,6 @@ func (c *Client) Dial(address string) (conn *Conn, err error) {
132126
// attribute appropriately
133127
func (c *Client) Exchange(m *Msg, address string) (r *Msg, rtt time.Duration, err error) {
134128
if !c.SingleInflight {
135-
if c.Net == "https" {
136-
// TODO(tmthrgd): pipe timeouts into exchangeDOH
137-
return c.exchangeDOH(context.TODO(), m, address)
138-
}
139-
140129
return c.exchange(m, address)
141130
}
142131

@@ -149,11 +138,6 @@ func (c *Client) Exchange(m *Msg, address string) (r *Msg, rtt time.Duration, er
149138
cl = cl1
150139
}
151140
r, rtt, err, shared := c.group.Do(m.Question[0].Name+t+cl, func() (*Msg, time.Duration, error) {
152-
if c.Net == "https" {
153-
// TODO(tmthrgd): pipe timeouts into exchangeDOH
154-
return c.exchangeDOH(context.TODO(), m, address)
155-
}
156-
157141
return c.exchange(m, address)
158142
})
159143
if r != nil && shared {
@@ -199,67 +183,6 @@ func (c *Client) exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro
199183
return r, rtt, err
200184
}
201185

202-
func (c *Client) exchangeDOH(ctx context.Context, m *Msg, a string) (r *Msg, rtt time.Duration, err error) {
203-
p, err := m.Pack()
204-
if err != nil {
205-
return nil, 0, err
206-
}
207-
208-
req, err := http.NewRequest(http.MethodPost, a, bytes.NewReader(p))
209-
if err != nil {
210-
return nil, 0, err
211-
}
212-
213-
req.Header.Set("Content-Type", dohMimeType)
214-
req.Header.Set("Accept", dohMimeType)
215-
216-
hc := http.DefaultClient
217-
if c.HTTPClient != nil {
218-
hc = c.HTTPClient
219-
}
220-
221-
if ctx != context.Background() && ctx != context.TODO() {
222-
req = req.WithContext(ctx)
223-
}
224-
225-
t := time.Now()
226-
227-
resp, err := hc.Do(req)
228-
if err != nil {
229-
return nil, 0, err
230-
}
231-
defer closeHTTPBody(resp.Body)
232-
233-
if resp.StatusCode != http.StatusOK {
234-
return nil, 0, fmt.Errorf("dns: server returned HTTP %d error: %q", resp.StatusCode, resp.Status)
235-
}
236-
237-
if ct := resp.Header.Get("Content-Type"); ct != dohMimeType {
238-
return nil, 0, fmt.Errorf("dns: unexpected Content-Type %q; expected %q", ct, dohMimeType)
239-
}
240-
241-
p, err = ioutil.ReadAll(resp.Body)
242-
if err != nil {
243-
return nil, 0, err
244-
}
245-
246-
rtt = time.Since(t)
247-
248-
r = new(Msg)
249-
if err := r.Unpack(p); err != nil {
250-
return r, 0, err
251-
}
252-
253-
// TODO: TSIG? Is it even supported over DoH?
254-
255-
return r, rtt, nil
256-
}
257-
258-
func closeHTTPBody(r io.ReadCloser) error {
259-
io.Copy(ioutil.Discard, io.LimitReader(r, 8<<20))
260-
return r.Close()
261-
}
262-
263186
// ReadMsg reads a message from the connection co.
264187
// If the received message contains a TSIG record the transaction signature
265188
// is verified. This method always tries to return the message, however if an
@@ -559,10 +482,6 @@ func DialTimeoutWithTLS(network, address string, tlsConfig *tls.Config, timeout
559482
// context, if present. If there is both a context deadline and a configured
560483
// timeout on the client, the earliest of the two takes effect.
561484
func (c *Client) ExchangeContext(ctx context.Context, m *Msg, a string) (r *Msg, rtt time.Duration, err error) {
562-
if !c.SingleInflight && c.Net == "https" {
563-
return c.exchangeDOH(ctx, m, a)
564-
}
565-
566485
var timeout time.Duration
567486
if deadline, ok := ctx.Deadline(); !ok {
568487
timeout = 0
@@ -571,7 +490,7 @@ func (c *Client) ExchangeContext(ctx context.Context, m *Msg, a string) (r *Msg,
571490
}
572491
// not passing the context to the underlying calls, as the API does not support
573492
// context. For timeouts you should set up Client.Dialer and call Client.Exchange.
574-
// TODO(tmthrgd): this is a race condition
493+
// TODO(tmthrgd,miekg): this is a race condition.
575494
c.Dialer = &net.Dialer{Timeout: timeout}
576495
return c.Exchange(m, a)
577496
}

client_test.go

-20
Original file line numberDiff line numberDiff line change
@@ -589,23 +589,3 @@ func TestConcurrentExchanges(t *testing.T) {
589589
}
590590
}
591591
}
592-
593-
func TestDoHExchange(t *testing.T) {
594-
const addrstr = "https://dns.cloudflare.com/dns-query"
595-
596-
m := new(Msg)
597-
m.SetQuestion("miek.nl.", TypeSOA)
598-
599-
cl := &Client{Net: "https"}
600-
601-
r, _, err := cl.Exchange(m, addrstr)
602-
if err != nil {
603-
t.Fatalf("failed to exchange: %v", err)
604-
}
605-
606-
if r == nil || r.Rcode != RcodeSuccess {
607-
t.Errorf("failed to get an valid answer\n%v", r)
608-
}
609-
610-
// TODO: proper tests for this
611-
}

leak_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func interestingGoroutines() (gs []string) {
2929
strings.Contains(stack, "closeWriteAndWait") ||
3030
strings.Contains(stack, "testing.Main(") ||
3131
strings.Contains(stack, "testing.(*T).Run(") ||
32-
strings.Contains(stack, "created by net/http.(*http2Transport).newClientConn") ||
3332
// These only show up with GOTRACEBACK=2; Issue 5005 (comment 28)
3433
strings.Contains(stack, "runtime.goexit") ||
3534
strings.Contains(stack, "created by runtime.gc") ||

0 commit comments

Comments
 (0)