mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-22 05:29:50 +00:00
Core: Fix startup error when dns
exists but fakedns
doesn't
Fixes https://github.com/XTLS/Xray-core/issues/4155
This commit is contained in:
parent
8cd9a74376
commit
743435d6e6
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user