aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-02-11 16:56:04 +0000
committerGravatar GitHub <noreply@github.com> 2017-02-11 16:56:04 +0000
commita5f3cb5fe542f792bd8289daa5fffb6137b81999 (patch)
tree8db738da60c6d84e5e5aa91e8a0d4f75f7d320ee
parent5f6c7682becc254c08addc06d1a95e30561a87e6 (diff)
downloadcoredns-a5f3cb5fe542f792bd8289daa5fffb6137b81999.tar.gz
coredns-a5f3cb5fe542f792bd8289daa5fffb6137b81999.tar.zst
coredns-a5f3cb5fe542f792bd8289daa5fffb6137b81999.zip
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
-rw-r--r--.travis.yml2
-rw-r--r--middleware/proxy/dns.go3
-rw-r--r--middleware/proxy/exchanger.go4
-rw-r--r--middleware/proxy/google.go3
-rw-r--r--middleware/proxy/lookup.go3
-rw-r--r--middleware/proxy/proxy.go2
6 files changed, 11 insertions, 6 deletions
diff --git a/.travis.yml b/.travis.yml
index 0be7425b3..78df3d1a6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,7 +7,7 @@ services:
language: go
go:
- - 1.6
+ - 1.7
go_import_path: github.com/miekg/coredns
diff --git a/middleware/proxy/dns.go b/middleware/proxy/dns.go
index 4fde48e40..45d8e3e2e 100644
--- a/middleware/proxy/dns.go
+++ b/middleware/proxy/dns.go
@@ -1,6 +1,7 @@
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
diff --git a/middleware/proxy/exchanger.go b/middleware/proxy/exchanger.go
index 78c80b8b6..d5c17e349 100644
--- a/middleware/proxy/exchanger.go
+++ b/middleware/proxy/exchanger.go
@@ -1,6 +1,8 @@
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
diff --git a/middleware/proxy/google.go b/middleware/proxy/google.go
index 5efb84960..4d82ec914 100644
--- a/middleware/proxy/google.go
+++ b/middleware/proxy/google.go
@@ -1,6 +1,7 @@
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())
diff --git a/middleware/proxy/lookup.go b/middleware/proxy/lookup.go
index 56dc0eb4c..9c736aa63 100644
--- a/middleware/proxy/lookup.go
+++ b/middleware/proxy/lookup.go
@@ -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)
diff --git a/middleware/proxy/proxy.go b/middleware/proxy/proxy.go
index 1a595d99e..ca57d7575 100644
--- a/middleware/proxy/proxy.go
+++ b/middleware/proxy/proxy.go
@@ -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)