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)