2
0
xljiulang 4 жил өмнө
parent
commit
e2bd4dac50

+ 6 - 3
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)

+ 4 - 11
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("反向代理服务启动成功");
         }
 
         /// <summary>
@@ -76,8 +68,9 @@ namespace FastGithub
         {
             return listenOptions.UseHttps(https =>
             {
+                const string defaultDomain = "github.com";
                 var certs = new ConcurrentDictionary<string, X509Certificate2>();
-                https.ServerCertificateSelector = (ctx, domain) => certs.GetOrAdd(domain, CreateCert);
+                https.ServerCertificateSelector = (ctx, domain) => certs.GetOrAdd(domain ?? defaultDomain, CreateCert);
             });
 
             X509Certificate2 CreateCert(string domain)