From 21a1d85af7d66b4fde627f17d5f5ed50b40aaee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E4=B9=9D?= <366193849@qq.com> Date: Wed, 29 Sep 2021 19:34:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.DomainResolve/DnsClient.cs | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/FastGithub.DomainResolve/DnsClient.cs b/FastGithub.DomainResolve/DnsClient.cs index f2721b4..330d34f 100644 --- a/FastGithub.DomainResolve/DnsClient.cs +++ b/FastGithub.DomainResolve/DnsClient.cs @@ -9,7 +9,6 @@ using Microsoft.Extensions.Options; using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Net; using System.Net.NetworkInformation; @@ -32,7 +31,6 @@ namespace FastGithub.DomainResolve private readonly ILogger logger; private readonly ConcurrentDictionary domainIPAddressCollection = new(); - private readonly ConcurrentDictionary semaphoreSlims = new(); private readonly IMemoryCache dnsCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); private readonly TimeSpan defaultEmptyTtl = TimeSpan.FromSeconds(30d); @@ -64,9 +62,9 @@ namespace FastGithub.DomainResolve /// public async IAsyncEnumerable ResolveAsync(string domain, [EnumeratorCancellation] CancellationToken cancellationToken) { - if (this.TryGetPingedIPAddresses(domain, out var addresses)) + if (this.domainIPAddressCollection.TryGetValue(domain, out var collection) && collection.Count > 0) { - foreach (var address in addresses) + foreach (var address in collection.ToArray()) { yield return address; } @@ -101,24 +99,6 @@ namespace FastGithub.DomainResolve } } - /// - /// 尝试获取域名下已经过ping排序的IP地址 - /// - /// - /// - /// - private bool TryGetPingedIPAddresses(string domain, [MaybeNullWhen(false)] out IPAddress[] addresses) - { - if (this.domainIPAddressCollection.TryGetValue(domain, out var collection) && collection.Count > 0) - { - addresses = collection.ToArray(); - return true; - } - - addresses = default; - return false; - } - /// /// 解析域名 /// @@ -190,7 +170,7 @@ namespace FastGithub.DomainResolve } catch (OperationCanceledException) { - this.logger.LogInformation($"dns://{dns}无法解析{domain}:请求超时"); + this.logger.LogInformation($"dns://{dns}无法解析{domain}:请求超时"); return Array.Empty(); } catch (Exception ex)