diff --git a/FastGithub.DomainResolve/DnsClient.cs b/FastGithub.DomainResolve/DnsClient.cs index 330d34f..2d0807d 100644 --- a/FastGithub.DomainResolve/DnsClient.cs +++ b/FastGithub.DomainResolve/DnsClient.cs @@ -54,6 +54,15 @@ namespace FastGithub.DomainResolve this.logger = logger; } + /// + /// 预加载 + /// + /// 域名 + public void Prefetch(string domain) + { + this.domainIPAddressCollection.TryAdd(domain, new IPAddressCollection()); + } + /// /// 解析域名 /// diff --git a/FastGithub.DomainResolve/DomainResolver.cs b/FastGithub.DomainResolve/DomainResolver.cs index 67e24c5..e65fb14 100644 --- a/FastGithub.DomainResolve/DomainResolver.cs +++ b/FastGithub.DomainResolve/DomainResolver.cs @@ -22,6 +22,15 @@ namespace FastGithub.DomainResolve this.dnsClient = dnsClient; } + /// + /// 载加载 + /// + /// 域名 + public void Prefetch(string domain) + { + this.dnsClient.Prefetch(domain); + } + /// /// 解析ip /// diff --git a/FastGithub.DomainResolve/IDomainResolver.cs b/FastGithub.DomainResolve/IDomainResolver.cs index e651d0f..4a1f4a7 100644 --- a/FastGithub.DomainResolve/IDomainResolver.cs +++ b/FastGithub.DomainResolve/IDomainResolver.cs @@ -10,6 +10,12 @@ namespace FastGithub.DomainResolve /// public interface IDomainResolver { + /// + /// 载加载 + /// + /// 域名 + void Prefetch(string domain); + /// /// 解析ip /// diff --git a/FastGithub.Http/HttpClientHandler.cs b/FastGithub.Http/HttpClientHandler.cs index 2b23dab..2ae92a8 100644 --- a/FastGithub.Http/HttpClientHandler.cs +++ b/FastGithub.Http/HttpClientHandler.cs @@ -120,7 +120,7 @@ namespace FastGithub.Http } } - throw new AggregateException("没有可连接成功的IP", innerExceptions); + throw new AggregateException("找不到任何可成功连接的IP", innerExceptions); } /// diff --git a/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs b/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs index 6a8a9ca..da281aa 100644 --- a/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs +++ b/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs @@ -1,6 +1,7 @@ using DNS.Protocol; using DNS.Protocol.ResourceRecords; using FastGithub.Configuration; +using FastGithub.DomainResolve; using FastGithub.WinDiverts; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -23,8 +24,11 @@ namespace FastGithub.PacketIntercept.Dns sealed class DnsInterceptor : IDnsInterceptor { private const string DNS_FILTER = "udp.DstPort == 53"; + private readonly FastGithubConfig fastGithubConfig; + private readonly IDomainResolver domainResolver; private readonly ILogger logger; + private readonly TimeSpan ttl = TimeSpan.FromMinutes(10d); /// @@ -37,16 +41,18 @@ namespace FastGithub.PacketIntercept.Dns /// dns拦截器 /// /// + /// /// /// public DnsInterceptor( FastGithubConfig fastGithubConfig, + IDomainResolver domainResolver, ILogger logger, IOptionsMonitor options) { this.fastGithubConfig = fastGithubConfig; this.logger = logger; - + this.domainResolver = domainResolver; options.OnChange(_ => DnsFlushResolverCache()); } @@ -129,6 +135,9 @@ namespace FastGithub.PacketIntercept.Dns return; } + // dns预加载 + this.domainResolver.Prefetch(domain.ToString()); + // dns响应数据 var response = Response.FromRequest(request); var record = new IPAddressResourceRecord(domain, IPAddress.Loopback, this.ttl); diff --git a/FastGithub.PacketIntercept/FastGithub.PacketIntercept.csproj b/FastGithub.PacketIntercept/FastGithub.PacketIntercept.csproj index 2c8b98c..d3fca22 100644 --- a/FastGithub.PacketIntercept/FastGithub.PacketIntercept.csproj +++ b/FastGithub.PacketIntercept/FastGithub.PacketIntercept.csproj @@ -14,5 +14,6 @@ +