From abafeed7f5c352b516ae41fc3e2ef2f02c2e4edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E4=B9=9D?= <366193849@qq.com> Date: Sun, 26 Sep 2021 21:03:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=B8=E9=87=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.DomainResolve/DnsClient.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/FastGithub.DomainResolve/DnsClient.cs b/FastGithub.DomainResolve/DnsClient.cs index f89edc9..e60f20a 100644 --- a/FastGithub.DomainResolve/DnsClient.cs +++ b/FastGithub.DomainResolve/DnsClient.cs @@ -19,6 +19,8 @@ namespace FastGithub.DomainResolve /// sealed class DnsClient { + private const int DNS_PORT = 53; + private const string LOCALHOST = "localhost"; private readonly ILogger logger; private readonly ConcurrentDictionary semaphoreSlims = new(); @@ -56,13 +58,13 @@ namespace FastGithub.DomainResolve this.dnsCache.Set(key, value, this.dnsExpiration); var items = string.Join(", ", value.Select(item => item.ToString())); - this.logger.LogInformation($"{dns}:{domain}->[{items}]"); + this.logger.LogInformation($"dns://{dns}:{domain}->[{items}]"); } return value; } catch (Exception ex) { - this.logger.LogWarning($"{dns}无法解析{domain}:{ex.Message}"); + this.logger.LogWarning($"dns://{dns}无法解析{domain}:{ex.Message}"); return Array.Empty(); } finally @@ -80,12 +82,12 @@ namespace FastGithub.DomainResolve /// private async Task LookupCoreAsync(IPEndPoint dns, string domain, CancellationToken cancellationToken = default) { - if (domain == "localhost") + if (domain == LOCALHOST) { return new[] { IPAddress.Loopback }; } - var resolver = dns.Port == 53 + var resolver = dns.Port == DNS_PORT ? (IRequestResolver)new TcpRequestResolver(dns) : new UdpRequestResolver(dns, new TcpRequestResolver(dns), this.resolveTimeout);