From 7d7b67948bb726f252e2ad37302bfaf425c2b522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Wed, 17 Nov 2021 09:37:30 +0800 Subject: [PATCH] =?UTF-8?q?dns=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.DomainResolve/DnsClient.cs | 8 ++------ FastGithub.DomainResolve/DomainResolver.cs | 11 ++++++++--- .../IPAddressElapsedCollection.cs | 5 +++++ FastGithub/appsettings.json | 8 ++++---- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/FastGithub.DomainResolve/DnsClient.cs b/FastGithub.DomainResolve/DnsClient.cs index 64e8e90..1453fcf 100644 --- a/FastGithub.DomainResolve/DnsClient.cs +++ b/FastGithub.DomainResolve/DnsClient.cs @@ -117,20 +117,16 @@ namespace FastGithub.DomainResolve var result = await this.LookupCoreAsync(dns, endPoint, cancellationToken); this.dnsCache.Set(key, result.Addresses, result.TimeToLive); - - var items = string.Join(", ", result.Addresses.Select(item => item.ToString())); - this.logger.LogInformation($"dns://{dns}:{endPoint.Host}->[{items}]"); - return result.Addresses; } catch (OperationCanceledException) { - this.logger.LogInformation($"dns://{dns}无法解析{endPoint.Host}:请求超时"); + this.logger.LogWarning($"dns://{dns}无法解析{endPoint.Host}:请求超时"); return Array.Empty(); } catch (Exception ex) { - this.logger.LogInformation($"dns://{dns}无法解析{endPoint.Host}:{ex.Message}"); + this.logger.LogWarning($"dns://{dns}无法解析{endPoint.Host}:{ex.Message}"); return Array.Empty(); } finally diff --git a/FastGithub.DomainResolve/DomainResolver.cs b/FastGithub.DomainResolve/DomainResolver.cs index 23d1fe2..e205413 100644 --- a/FastGithub.DomainResolve/DomainResolver.cs +++ b/FastGithub.DomainResolve/DomainResolver.cs @@ -1,4 +1,5 @@ using FastGithub.Configuration; +using Microsoft.Extensions.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -16,16 +17,19 @@ namespace FastGithub.DomainResolve sealed class DomainResolver : IDomainResolver { private readonly DnsClient dnsClient; + private readonly ILogger logger; private readonly ConcurrentDictionary dnsEndPointAddressElapseds = new(); /// /// 域名解析器 - /// + /// /// - public DomainResolver(DnsClient dnsClient) + /// + public DomainResolver(DnsClient dnsClient, ILogger logger) { this.dnsClient = dnsClient; - } + this.logger = logger; + } /// /// 解析ip @@ -52,6 +56,7 @@ namespace FastGithub.DomainResolve { if (this.dnsEndPointAddressElapseds.TryGetValue(endPoint, out var addressElapseds) && addressElapseds.IsEmpty == false) { + this.logger.LogInformation($"{endPoint.Host}: {addressElapseds}"); foreach (var addressElapsed in addressElapseds) { yield return addressElapsed.Adddress; diff --git a/FastGithub.DomainResolve/IPAddressElapsedCollection.cs b/FastGithub.DomainResolve/IPAddressElapsedCollection.cs index bef3dfc..09fcf04 100644 --- a/FastGithub.DomainResolve/IPAddressElapsedCollection.cs +++ b/FastGithub.DomainResolve/IPAddressElapsedCollection.cs @@ -76,5 +76,10 @@ namespace FastGithub.DomainResolve { return this.addressElapseds.GetEnumerator(); } + + public override string ToString() + { + return $"[{string.Join(',', this.addressElapseds.Select(item => item.Adddress))}]"; + } } } diff --git a/FastGithub/appsettings.json b/FastGithub/appsettings.json index f7907bc..8aef856 100644 --- a/FastGithub/appsettings.json +++ b/FastGithub/appsettings.json @@ -2,9 +2,10 @@ // 新增的子配置文件appsettings.*.json,重启应用程序才生效 "FastGithub": { "HttpProxyPort": 38457, // http代理端口,linux/osx平台使用 - "FallbackDns": [ // dnscrypt-proxy不可用时使用 + "FallbackDns": [ // 以下dns必须要支持tcp "114.114.114.114:53", - "119.29.29.29:53" + "119.29.29.29:53", + "208.67.222.222:53" ], "DomainConfigs": { "*.fastgithub.com": { // 域名的*表示除.之外0到多个任意字符 @@ -28,8 +29,7 @@ "Override": { "Yarp": "Warning", "System": "Warning", - "Microsoft": "Warning", - "FastGithub.DomainResolve": "Warning", + "Microsoft": "Warning", "Microsoft.AspNetCore.Server.Kestrel": "Error" } }