mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 10:13:14 -05:00
Cleanup: put middleware helper functions in pkgs (#245)
Move all (almost all) Go files in middleware into their own packages. This makes for better naming and discoverability. Lot of changes elsewhere to make this change. The middleware.State was renamed to request.Request which is better, but still does not cover all use-cases. It was also moved out middleware because it is used by `dnsserver` as well. A pkg/dnsutil packages was added for shared, handy, dns util functions. All normalize functions are now put in normalize.go
This commit is contained in:
@@ -7,7 +7,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -54,18 +55,19 @@ func New(hosts []string) Proxy {
|
||||
// Lookup will use name and type to forge a new message and will send that upstream. It will
|
||||
// set any EDNS0 options correctly so that downstream will be able to process the reply.
|
||||
// Lookup is not suitable for forwarding request. Ssee for that.
|
||||
func (p Proxy) Lookup(state middleware.State, name string, tpe uint16) (*dns.Msg, error) {
|
||||
func (p Proxy) Lookup(state request.Request, name string, tpe uint16) (*dns.Msg, error) {
|
||||
req := new(dns.Msg)
|
||||
req.SetQuestion(name, tpe)
|
||||
state.SizeAndDo(req)
|
||||
|
||||
return p.lookup(state, req)
|
||||
}
|
||||
|
||||
func (p Proxy) Forward(state middleware.State) (*dns.Msg, error) {
|
||||
func (p Proxy) Forward(state request.Request) (*dns.Msg, error) {
|
||||
return p.lookup(state, state.Req)
|
||||
}
|
||||
|
||||
func (p Proxy) lookup(state middleware.State, r *dns.Msg) (*dns.Msg, error) {
|
||||
func (p Proxy) lookup(state request.Request, r *dns.Msg) (*dns.Msg, error) {
|
||||
var (
|
||||
reply *dns.Msg
|
||||
err error
|
||||
@@ -84,9 +86,9 @@ func (p Proxy) lookup(state middleware.State, r *dns.Msg) (*dns.Msg, error) {
|
||||
|
||||
atomic.AddInt64(&host.Conns, 1)
|
||||
if state.Proto() == "tcp" {
|
||||
reply, err = middleware.Exchange(p.Client.TCP, r, host.Name)
|
||||
reply, _, err = p.Client.TCP.Exchange(r, host.Name)
|
||||
} else {
|
||||
reply, err = middleware.Exchange(p.Client.UDP, r, host.Name)
|
||||
reply, _, err = p.Client.UDP.Exchange(r, host.Name)
|
||||
}
|
||||
atomic.AddInt64(&host.Conns, -1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user