From e2bd4dac5059bbe02aa9fab143fd2276b8bad30c Mon Sep 17 00:00:00 2001 From: xljiulang <366193849@qq.com> Date: Wed, 14 Jul 2021 00:04:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ttl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.Dns/GithubRequestResolver.cs | 9 ++++++--- .../KestrelServerOptionsExtensions.cs | 15 ++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/FastGithub.Dns/GithubRequestResolver.cs b/FastGithub.Dns/GithubRequestResolver.cs index 8420874..e7d36f0 100644 --- a/FastGithub.Dns/GithubRequestResolver.cs +++ b/FastGithub.Dns/GithubRequestResolver.cs @@ -5,6 +5,7 @@ using FastGithub.Scanner; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using System; using System.Linq; using System.Net.Sockets; using System.Threading; @@ -56,17 +57,19 @@ namespace FastGithub.Dns if (address != null) { - var ttl = this.options.CurrentValue.GithubTTL; if (this.options.CurrentValue.UseReverseProxy == false) { + var ttl = this.options.CurrentValue.GithubTTL; var record = new IPAddressResourceRecord(question.Name, address, ttl); response.AnswerRecords.Add(record); this.logger.LogInformation(record.ToString()); } else { - var hostName = System.Net.Dns.GetHostName(); - var addresses = await System.Net.Dns.GetHostAddressesAsync(hostName); + var localhost = System.Net.Dns.GetHostName(); + var addresses = await System.Net.Dns.GetHostAddressesAsync(localhost); + var ttl = TimeSpan.FromMinutes(1d); + foreach (var item in addresses) { if (item.AddressFamily == AddressFamily.InterNetwork) diff --git a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs index 5755cdf..0a9534b 100644 --- a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs +++ b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System; using System.Collections.Concurrent; -using System.IO; using System.Security.Cryptography.X509Certificates; namespace FastGithub @@ -27,15 +26,8 @@ namespace FastGithub var logger = loggerFactory.CreateLogger($"{nameof(FastGithub)}{nameof(ReverseProxy)}"); TryInstallCaCert(caPublicCerPath, logger); - try - { - kestrel.ListenAnyIP(443, listen => listen.UseGithubHttps(caPublicCerPath, caPrivateKeyPath)); - logger.LogInformation("反向代理服务启动成功"); - } - catch (IOException ex) - { - logger.LogError($"无法开启反向代理功能:{ex.Message}"); - } + kestrel.ListenAnyIP(443, listen => listen.UseGithubHttps(caPublicCerPath, caPrivateKeyPath)); + logger.LogInformation("反向代理服务启动成功"); } /// @@ -76,8 +68,9 @@ namespace FastGithub { return listenOptions.UseHttps(https => { + const string defaultDomain = "github.com"; var certs = new ConcurrentDictionary(); - https.ServerCertificateSelector = (ctx, domain) => certs.GetOrAdd(domain, CreateCert); + https.ServerCertificateSelector = (ctx, domain) => certs.GetOrAdd(domain ?? defaultDomain, CreateCert); }); X509Certificate2 CreateCert(string domain)