修改ttl

This commit is contained in:
xljiulang 2021-07-14 00:04:57 +08:00
parent a3517d9d3a
commit e2bd4dac50
2 changed files with 10 additions and 14 deletions

View File

@ -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)

View File

@ -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,16 +26,9 @@ 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}");
}
}
/// <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)