From 182e1695efb974dfa85bce5dce646751cf829930 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 19 Aug 2019 17:17:25 +0800 Subject: [PATCH] fix a bug --- component/fakedns/middleware.go | 2 +- component/fakedns/resolver.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/component/fakedns/middleware.go b/component/fakedns/middleware.go index 176408a..7fe1088 100644 --- a/component/fakedns/middleware.go +++ b/component/fakedns/middleware.go @@ -113,7 +113,7 @@ func hostResolve(hosts *T.Trie, r *D.Msg) *D.Msg { return msg } -func newHandler(hosts *T.Trie, pool *F.Pool, backendDNS []string) D.HandlerFunc { +func newHandler(hosts *T.Trie, pool *F.Pool, backendDNS []string) handler { return func(w D.ResponseWriter, r *D.Msg) { msg := resolve(hosts, pool, backendDNS, r) w.WriteMsg(msg) diff --git a/component/fakedns/resolver.go b/component/fakedns/resolver.go index 43e7ade..8177dc4 100644 --- a/component/fakedns/resolver.go +++ b/component/fakedns/resolver.go @@ -22,11 +22,13 @@ const ( dnsFakeIPRange = "198.18.0.0/15" ) +type handler = D.HandlerFunc + type Resolver struct { b []string + h handler p *F.Pool t *T.Trie - h D.HandlerFunc *D.Server ServeAddr string @@ -86,7 +88,7 @@ func (r *Resolver) Resolve(request []byte) ([]byte, error) { return nil, errors.New("cannot handle dns query: invalid question length") } - msg := resolve(r.h, r.p, r.b, req) + msg := resolve(r.t, r.p, r.b, req) if msg == nil { return nil, errors.New("cannot resolve dns query: msg is nil") } @@ -126,9 +128,9 @@ func NewResolver(a, h, b string) (*Resolver, error) { handler := newHandler(tree, pool, backendDNS) return &Resolver{ b: backendDNS, + h: handler, p: pool, t: tree, - h: handler, ServeAddr: a, }, nil }