github.com/EagleQL/Xray-core@v1.4.3/app/dns/nameserver_fakedns.go (about) 1 package dns 2 3 import ( 4 "context" 5 6 "github.com/xtls/xray-core/common/net" 7 "github.com/xtls/xray-core/core" 8 "github.com/xtls/xray-core/features/dns" 9 ) 10 11 type FakeDNSServer struct { 12 fakeDNSEngine dns.FakeDNSEngine 13 } 14 15 func NewFakeDNSServer() *FakeDNSServer { 16 return &FakeDNSServer{} 17 } 18 19 func (FakeDNSServer) Name() string { 20 return "FakeDNS" 21 } 22 23 func (f *FakeDNSServer) QueryIP(ctx context.Context, domain string, _ dns.IPOption) ([]net.IP, error) { 24 if f.fakeDNSEngine == nil { 25 if err := core.RequireFeatures(ctx, func(fd dns.FakeDNSEngine) { 26 f.fakeDNSEngine = fd 27 }); err != nil { 28 return nil, newError("Unable to locate a fake DNS Engine").Base(err).AtError() 29 } 30 } 31 ips := f.fakeDNSEngine.GetFakeIPForDomain(domain) 32 33 netIP := toNetIP(ips) 34 if netIP == nil { 35 return nil, newError("Unable to convert IP to net ip").AtError() 36 } 37 38 newError(f.Name(), " got answer: ", domain, " -> ", ips).AtInfo().WriteToLog() 39 40 return netIP, nil 41 }