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: ...@@ -7,7 +7,7 @@ services:
language: go language: go
go: go:
- 1.6 - 1.7
go_import_path: github.com/miekg/coredns go_import_path: github.com/miekg/coredns
......
package proxy package proxy
import ( import (
"context"
"net" "net"
"time" "time"
...@@ -24,7 +25,7 @@ func (d *dnsEx) OnShutdown(p *Proxy) error { return nil } ...@@ -24,7 +25,7 @@ func (d *dnsEx) OnShutdown(p *Proxy) error { return nil }
func (d *dnsEx) OnStartup(p *Proxy) error { return nil } func (d *dnsEx) OnStartup(p *Proxy) error { return nil }
// Exchange implements the Exchanger interface. // 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) co, err := net.DialTimeout(state.Proto(), addr, d.Timeout)
if err != nil { if err != nil {
return nil, err return nil, err
......
package proxy package proxy
import ( import (
"context"
"github.com/miekg/coredns/request" "github.com/miekg/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
...@@ -8,7 +10,7 @@ import ( ...@@ -8,7 +10,7 @@ import (
// Exchanger is an interface that specifies a type implementing a DNS resolver that // Exchanger is an interface that specifies a type implementing a DNS resolver that
// can use whatever transport it likes. // can use whatever transport it likes.
type Exchanger interface { 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 Protocol() string
OnStartup(*Proxy) error OnStartup(*Proxy) error
......
package proxy package proxy
import ( import (
"context"
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
...@@ -42,7 +43,7 @@ func newGoogle(endpoint string, bootstrap []string) *google { ...@@ -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)} 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 := url.Values{}
v.Set("name", state.Name()) v.Set("name", state.Name())
......
...@@ -3,6 +3,7 @@ package proxy ...@@ -3,6 +3,7 @@ package proxy
// functions other middleware might want to use to do lookup in the same style as the proxy. // functions other middleware might want to use to do lookup in the same style as the proxy.
import ( import (
"context"
"sync/atomic" "sync/atomic"
"time" "time"
...@@ -91,7 +92,7 @@ func (p Proxy) lookup(state request.Request) (*dns.Msg, error) { ...@@ -91,7 +92,7 @@ func (p Proxy) lookup(state request.Request) (*dns.Msg, error) {
atomic.AddInt64(&host.Conns, 1) 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) atomic.AddInt64(&host.Conns, -1)
......
...@@ -105,7 +105,7 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( ...@@ -105,7 +105,7 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
atomic.AddInt64(&host.Conns, 1) 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) 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