diff --git a/samples/MiniDig/DnsCommand.cs b/samples/MiniDig/DnsCommand.cs index 37d478ed..3ca2d384 100644 --- a/samples/MiniDig/DnsCommand.cs +++ b/samples/MiniDig/DnsCommand.cs @@ -38,8 +38,6 @@ public abstract class DnsCommand public string[] OriginalArgs { get; } - public CommandOption PortArg { get; set; } - public CommandOption ServerArg { get; set; } public CommandOption TriesArg { get; set; } @@ -141,9 +139,7 @@ public TimeSpan GetMinimumTTL() return TimeSpan.Zero; } - - public int GetPortValue() => PortArg.HasValue() ? int.Parse(PortArg.Value()) : 53; - + public int GetTimeoutValue() => ConnectTimeoutArg.HasValue() ? int.Parse(ConnectTimeoutArg.Value()) : 5000; public int GetTriesValue() => TriesArg.HasValue() ? int.Parse(TriesArg.Value()) : 10; @@ -165,14 +161,9 @@ protected virtual void Configure() { ServerArg = App.Option( "-s | --server", - "The DNS server.", + "The DNS server # (multiple)", CommandOptionType.MultipleValue); - - PortArg = App.Option( - "-p | --port", - $"The port to use to connect to the DNS server [{NameServer.DefaultPort}].", - CommandOptionType.SingleValue); - + NoRecurseArg = App.Option( "-nr | --norecurse", "Non recurive mode.", diff --git a/samples/MiniDig/Program.cs b/samples/MiniDig/Program.cs index 2743fb11..124546c5 100644 --- a/samples/MiniDig/Program.cs +++ b/samples/MiniDig/Program.cs @@ -30,9 +30,9 @@ public static void Main(string[] args) //} //return; - var app = new CommandLineApplication(throwOnUnexpectedArg: false); + var app = new CommandLineApplication(throwOnUnexpectedArg: true); - var perfApplication = app.Command("perf", (perfApp) => new PerfCommand(perfApp, args), false); + var perfApplication = app.Command("perf", (perfApp) => new PerfCommand(perfApp, args), throwOnUnexpectedArg: true); var defaultCommand = new DigCommand(app, args); diff --git a/src/DnsClient/LookupClient.cs b/src/DnsClient/LookupClient.cs index affaf1a7..d4babe49 100644 --- a/src/DnsClient/LookupClient.cs +++ b/src/DnsClient/LookupClient.cs @@ -403,8 +403,6 @@ private void DisableEndpoint(NameServer server) _endpoints.ToList().ForEach(p => p.Enabled = true); } } - - Debug.WriteLine($"Disabling name server {server.Endpoint}."); } private class Audit diff --git a/src/DnsClient/project.json b/src/DnsClient/project.json index 783d2abd..7639392c 100644 --- a/src/DnsClient/project.json +++ b/src/DnsClient/project.json @@ -37,15 +37,21 @@ "frameworks": { "netstandard1.3": { "dependencies": { - "NETStandard.Library": "1.6.0", - "System.Net.NameResolution": "4.0.0", - "System.Net.NetworkInformation": "4.3.0" + "System.Collections": "4.3.0", + "System.Collections.Concurrent": "4.3.0", + "System.Linq": "4.3.0", + "System.Net.NameResolution": "4.3.0", + "System.Net.NetworkInformation": "4.3.0", + "System.Net.Sockets": "4.3.0", + "System.Runtime.Extensions": "4.3.0", + "System.Text.Encoding": "4.3.0", + "System.Threading": "4.3.0" }, "buildOptions": { "define": [ "XPLAT" ] } }, - "net451": { + "net45": { "frameworkAssemblies": { } } } -} +} \ No newline at end of file diff --git a/test/FullFrameworkOwinApp/Startup.cs b/test/FullFrameworkOwinApp/Startup.cs index 9aa4de4e..1394b7e2 100644 --- a/test/FullFrameworkOwinApp/Startup.cs +++ b/test/FullFrameworkOwinApp/Startup.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; -using System.Web; using DnsClient; using Owin; @@ -13,46 +11,39 @@ public class Startup { public void Configuration(IAppBuilder app) { - //var x = GetService("TenantConfigurationService").Result; - - // forced sync context within async owin, bad bad things will happen app.Run(ctx => { - //var task = Task.Factory.StartNew(()=> GetService("consul")); - //var uri = task.Unwrap().GetAwaiter().GetResult(); - var uri = GetService("consul").Result; - ctx.Response.Write(uri.OriginalString); + var query = ctx.Request.Query.Get("q") ?? Dns.GetHostName(); + // explicitly use Result here although middleware could be async + // just to test the bad blocking behavior of the owin stuff and see + // if QueryAsync produces a deadlock. + try + { + var ip = GetService(query).Result; + ctx.Response.Write($"{{ \"answer\": \"{ip.ToString()}\"}}"); + } + catch(Exception ex) + { + ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; + ctx.Response.Write(ex.InnerException?.Message ?? ex.Message); + } + return Task.FromResult(0); }); - - ////app.Run(async ctx => - ////{ - ////    await ctx.Response.WriteAsync((await GetService("TenantConfigurationService")).OriginalString); - ////    //return Task.FromResult(0); - ////}); } - private static async Task GetService(string serviceName) + private static async Task GetService(string query) { -            // TODO: What about the datacenter/tag features? -            var dnsQuery = string.Format("{0}.service.consul", serviceName); - var dnsClient = new LookupClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8600)); - var dnsResult = await dnsClient.QueryAsync(dnsQuery, QueryType.SRV).ConfigureAwait(false); - - var srv = dnsResult.Answers.SrvRecords().FirstOrDefault(); - if (srv == null) - { - throw new InvalidOperationException($"SRV record not found for {dnsQuery}"); - } + var dnsClient = new LookupClient(); + var dnsResult = await dnsClient.QueryAsync(query, QueryType.ANY).ConfigureAwait(false); - var ip = dnsResult.Additionals.ARecords().FirstOrDefault(p => p.QueryName == srv.Target)?.Address; - if (ip == null) + var aRecord = dnsResult.Answers.ARecords().FirstOrDefault(); + if (aRecord == null) { - throw new InvalidOperationException($"Invalid DNS response. A record missing for {srv.Target}"); + throw new InvalidOperationException($"Record not found for {query}"); } - // TODO: HTTP scheme is hard-coded!!! - return new Uri($"http://{ip}:{srv.Port}", UriKind.Absolute); + return aRecord.Address; } } } \ No newline at end of file