Commit a5f3cb5f authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

La context (#521)

* middleware/proxy: give Exchange a context

Make context.Context the first paramater in the Exchange method.
This is inline with all other query functions.

* up the version
parent 5f6c7682
......@@ -7,7 +7,7 @@ services:
language: go
go:
- 1.6
- 1.7
go_import_path: github.com/miekg/coredns
......
package proxy
import (
"context"
"net"
"time"
......@@ -24,7 +25,7 @@ func (d *dnsEx) OnShutdown(p *Proxy) error { return nil }
func (d *dnsEx) OnStartup(p *Proxy) error { return nil }
// Exchange implements the Exchanger interface.
func (d *dnsEx) Exchange(addr string, state request.Request) (*dns.Msg, error) {
func (d *dnsEx) Exchange(ctx context.Context, addr string, state request.Request) (*dns.Msg, error) {
co, err := net.DialTimeout(state.Proto(), addr, d.Timeout)
if err != nil {
return nil, err
......
package proxy
import (
"context"
"github.com/miekg/coredns/request"
"github.com/miekg/dns"
)
......@@ -8,7 +10,7 @@ import (
// Exchanger is an interface that specifies a type implementing a DNS resolver that
// can use whatever transport it likes.
type Exchanger interface {
Exchange(addr string, state request.Request) (*dns.Msg, error)
Exchange(ctx context.Context, addr string, state request.Request) (*dns.Msg, error)
Protocol() string
OnStartup(*Proxy) error
......
package proxy
import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
......@@ -42,7 +43,7 @@ func newGoogle(endpoint string, bootstrap []string) *google {
return &google{client: client, endpoint: dns.Fqdn(endpoint), bootstrapProxy: boot, quit: make(chan bool)}
}
func (g *google) Exchange(addr string, state request.Request) (*dns.Msg, error) {
func (g *google) Exchange(ctx context.Context, addr string, state request.Request) (*dns.Msg, error) {
v := url.Values{}
v.Set("name", state.Name())
......
......@@ -3,6 +3,7 @@ package proxy
// functions other middleware might want to use to do lookup in the same style as the proxy.
import (
"context"
"sync/atomic"
"time"
......@@ -91,7 +92,7 @@ func (p Proxy) lookup(state request.Request) (*dns.Msg, error) {
atomic.AddInt64(&host.Conns, 1)
reply, backendErr := upstream.Exchanger().Exchange(host.Name, state)
reply, backendErr := upstream.Exchanger().Exchange(context.TODO(), host.Name, state)
atomic.AddInt64(&host.Conns, -1)
......
......@@ -105,7 +105,7 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
atomic.AddInt64(&host.Conns, 1)
reply, backendErr := upstream.Exchanger().Exchange(host.Name, state)
reply, backendErr := upstream.Exchanger().Exchange(ctx, host.Name, state)
atomic.AddInt64(&host.Conns, -1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment