diff --git a/app/dns/nameserver.go b/app/dns/nameserver.go index ecba9aff..de6e1686 100644 --- a/app/dns/nameserver.go +++ b/app/dns/nameserver.go @@ -35,7 +35,7 @@ type Client struct { var errExpectedIPNonMatch = errors.New("expectIPs not match") // NewServer creates a name server object according to the network destination url. -func NewServer(dest net.Destination, dispatcher routing.Dispatcher, queryStrategy QueryStrategy, fd dns.FakeDNSEngine) (Server, error) { +func NewServer(ctx context.Context, dest net.Destination, dispatcher routing.Dispatcher, queryStrategy QueryStrategy) (Server, error) { if address := dest.Address; address.Family().IsDomain() { u, err := url.Parse(address.Domain()) if err != nil { @@ -55,6 +55,10 @@ func NewServer(dest net.Destination, dispatcher routing.Dispatcher, queryStrateg case strings.EqualFold(u.Scheme, "tcp+local"): // DNS-over-TCP Local mode return NewTCPLocalNameServer(u, queryStrategy) case strings.EqualFold(u.String(), "fakedns"): + var fd dns.FakeDNSEngine + core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) { // FakeDNSEngine is optional + fd = fdns + }) return NewFakeDNSServer(fd), nil } } @@ -78,13 +82,9 @@ func NewClient( ) (*Client, error) { client := &Client{} - var fd dns.FakeDNSEngine err := core.RequireFeatures(ctx, func(dispatcher routing.Dispatcher) error { - core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) { // FakeDNSEngine is optional - fd = fdns - }) // Create a new server for each client for now - server, err := NewServer(ns.Address.AsDestination(), dispatcher, ns.GetQueryStrategy(), fd) + server, err := NewServer(ctx, ns.Address.AsDestination(), dispatcher, ns.GetQueryStrategy()) if err != nil { return errors.New("failed to create nameserver").Base(err).AtWarning() }