diff --git a/FastGithub.ReverseProxy/DnscryptProxyHostedService.cs b/FastGithub.Dns.DnscryptProxy/DnscryptProxyHostedService.cs similarity index 98% rename from FastGithub.ReverseProxy/DnscryptProxyHostedService.cs rename to FastGithub.Dns.DnscryptProxy/DnscryptProxyHostedService.cs index 9ef2cfe..7cb5934 100644 --- a/FastGithub.ReverseProxy/DnscryptProxyHostedService.cs +++ b/FastGithub.Dns.DnscryptProxy/DnscryptProxyHostedService.cs @@ -6,7 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace FastGithub.ReverseProxy +namespace FastGithub.Dns.DnscryptProxy { /// /// DnscryptProxy后台服务 diff --git a/FastGithub.Dns.DnscryptProxy/DnscryptProxyServiceCollectionExtensions.cs b/FastGithub.Dns.DnscryptProxy/DnscryptProxyServiceCollectionExtensions.cs new file mode 100644 index 0000000..1dd6e59 --- /dev/null +++ b/FastGithub.Dns.DnscryptProxy/DnscryptProxyServiceCollectionExtensions.cs @@ -0,0 +1,21 @@ +using FastGithub.Dns.DnscryptProxy; +using Microsoft.Extensions.DependencyInjection; + +namespace FastGithub +{ + /// + /// DnscryptProxy的服务注册扩展 + /// + public static class DnscryptProxyServiceCollectionExtensions + { + /// + /// 添加DnscryptProxy + /// + /// + /// + public static IServiceCollection AddDnscryptProxy(this IServiceCollection services) + { + return services.AddHostedService(); + } + } +} diff --git a/FastGithub.Dns.DnscryptProxy/FastGithub.Dns.DnscryptProxy.csproj b/FastGithub.Dns.DnscryptProxy/FastGithub.Dns.DnscryptProxy.csproj new file mode 100644 index 0000000..cd49fe2 --- /dev/null +++ b/FastGithub.Dns.DnscryptProxy/FastGithub.Dns.DnscryptProxy.csproj @@ -0,0 +1,23 @@ + + + + net5.0 + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/FastGithub.ReverseProxy/dnscrypt-proxy b/FastGithub.Dns.DnscryptProxy/dnscrypt-proxy similarity index 100% rename from FastGithub.ReverseProxy/dnscrypt-proxy rename to FastGithub.Dns.DnscryptProxy/dnscrypt-proxy diff --git a/FastGithub.ReverseProxy/dnscrypt-proxy.exe b/FastGithub.Dns.DnscryptProxy/dnscrypt-proxy.exe similarity index 100% rename from FastGithub.ReverseProxy/dnscrypt-proxy.exe rename to FastGithub.Dns.DnscryptProxy/dnscrypt-proxy.exe diff --git a/FastGithub.ReverseProxy/dnscrypt-proxy.toml b/FastGithub.Dns.DnscryptProxy/dnscrypt-proxy.toml similarity index 100% rename from FastGithub.ReverseProxy/dnscrypt-proxy.toml rename to FastGithub.Dns.DnscryptProxy/dnscrypt-proxy.toml diff --git a/FastGithub.Dns/DnsServerServiceCollectionExtensions.cs b/FastGithub.Dns/DnsServerServiceCollectionExtensions.cs index 1321ee1..e5d9a72 100644 --- a/FastGithub.Dns/DnsServerServiceCollectionExtensions.cs +++ b/FastGithub.Dns/DnsServerServiceCollectionExtensions.cs @@ -4,16 +4,16 @@ using Microsoft.Extensions.DependencyInjection; namespace FastGithub { /// - /// 服务注册扩展 + /// dns服务注册扩展 /// public static class DnsServerServiceCollectionExtensions { /// - /// 注册github的dns服务 + /// 注册dns服务 /// /// /// - public static IServiceCollection AddGithubDns(this IServiceCollection services) + public static IServiceCollection AddDnsServer(this IServiceCollection services) { return services .AddSingleton() diff --git a/FastGithub.ReverseProxy/FastGithub.ReverseProxy.csproj b/FastGithub.ReverseProxy/FastGithub.ReverseProxy.csproj index 08cff91..57a0ed9 100644 --- a/FastGithub.ReverseProxy/FastGithub.ReverseProxy.csproj +++ b/FastGithub.ReverseProxy/FastGithub.ReverseProxy.csproj @@ -15,10 +15,4 @@ - - - PreserveNewest - - - diff --git a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs index 47d865d..648ab2d 100644 --- a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs +++ b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs @@ -21,12 +21,12 @@ namespace FastGithub private static readonly ConcurrentDictionary> domainCerts = new(); /// - /// 监听github的反向代理 + /// 监听https的反向代理 /// /// /// /// - public static void ListenGithubReverseProxy(this KestrelServerOptions kestrel, string caPublicCerPath, string caPrivateKeyPath) + public static void ListenHttpsReverseProxy(this KestrelServerOptions kestrel, string caPublicCerPath, string caPrivateKeyPath) { var loggerFactory = kestrel.ApplicationServices.GetRequiredService(); var logger = loggerFactory.CreateLogger($"{nameof(FastGithub)}.{nameof(ReverseProxy)}"); @@ -37,7 +37,7 @@ namespace FastGithub https.ServerCertificateSelector = (ctx, domain) => GetOrCreateCert(domain))); - logger.LogInformation("反向代理服务启动成功"); + logger.LogInformation("https反向代理服务启动成功"); X509Certificate2 GetOrCreateCert(string key) diff --git a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs index bfac93d..d3d9bc8 100644 --- a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs +++ b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs @@ -9,16 +9,16 @@ using Yarp.ReverseProxy.Forwarder; namespace FastGithub { /// - /// gitub反向代理的中间件扩展 + /// https反向代理的中间件扩展 /// public static class ReverseProxyApplicationBuilderExtensions { /// - /// 使用gitub反向代理中间件 + /// 使用https反向代理中间件 /// /// /// - public static IApplicationBuilder UseGithubReverseProxy(this IApplicationBuilder app) + public static IApplicationBuilder UseHttpsReverseProxy(this IApplicationBuilder app) { var httpForwarder = app.ApplicationServices.GetRequiredService(); var httpClientHanlder = app.ApplicationServices.GetRequiredService(); diff --git a/FastGithub.ReverseProxy/ReverseProxyServiceCollectionExtensions.cs b/FastGithub.ReverseProxy/ReverseProxyServiceCollectionExtensions.cs index c954b0b..0e099ed 100644 --- a/FastGithub.ReverseProxy/ReverseProxyServiceCollectionExtensions.cs +++ b/FastGithub.ReverseProxy/ReverseProxyServiceCollectionExtensions.cs @@ -4,23 +4,22 @@ using Microsoft.Extensions.DependencyInjection; namespace FastGithub { /// - /// gitub反向代理的服务注册扩展 + /// https反向代理的服务注册扩展 /// public static class ReverseProxyServiceCollectionExtensions { /// - /// gitub反向代理 + /// 添加https反向代理 /// /// /// - public static IServiceCollection AddGithubReverseProxy(this IServiceCollection services) + public static IServiceCollection AddReverseProxy(this IServiceCollection services) { return services .AddMemoryCache() .AddHttpForwarder() .AddSingleton() - .AddTransient() - .AddHostedService(); + .AddTransient(); } } } diff --git a/FastGithub.sln b/FastGithub.sln index 0c59484..cfee8aa 100644 --- a/FastGithub.sln +++ b/FastGithub.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.Upgrade", "FastG EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.ReverseProxy", "FastGithub.ReverseProxy\FastGithub.ReverseProxy.csproj", "{28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FastGithub.Dns.DnscryptProxy", "FastGithub.Dns.DnscryptProxy\FastGithub.Dns.DnscryptProxy.csproj", "{CA5B4643-DD1B-42D1-BAF0-589FB0A0D4A4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Debug|Any CPU.Build.0 = Debug|Any CPU {28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Release|Any CPU.ActiveCfg = Release|Any CPU {28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Release|Any CPU.Build.0 = Release|Any CPU + {CA5B4643-DD1B-42D1-BAF0-589FB0A0D4A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA5B4643-DD1B-42D1-BAF0-589FB0A0D4A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA5B4643-DD1B-42D1-BAF0-589FB0A0D4A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA5B4643-DD1B-42D1-BAF0-589FB0A0D4A4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FastGithub/FastGithub.csproj b/FastGithub/FastGithub.csproj index 63dcf0e..f59eb0f 100644 --- a/FastGithub/FastGithub.csproj +++ b/FastGithub/FastGithub.csproj @@ -19,6 +19,7 @@ + diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs index e827f73..222b653 100644 --- a/FastGithub/Program.cs +++ b/FastGithub/Program.cs @@ -32,17 +32,19 @@ namespace FastGithub }) .ConfigureServices((ctx, services) => { - services.AddAppUpgrade(); - services.AddGithubDns(); - services.AddGithubReverseProxy(); - services.AddOptions() - .Bind(ctx.Configuration.GetSection(nameof(FastGithub))) - .Validate(opt => opt.TrustedDns.Validate() && opt.UntrustedDns.Validate(), "无效的Dns配置"); + services + .AddAppUpgrade() + .AddDnsServer() + .AddReverseProxy() + .AddDnscryptProxy() + .AddOptions() + .Bind(ctx.Configuration.GetSection(nameof(FastGithub))) + .Validate(opt => opt.TrustedDns.Validate() && opt.UntrustedDns.Validate(), "无效的Dns配置"); }) .ConfigureWebHostDefaults(web => { - web.Configure(app => app.UseGithubReverseProxy()); - web.UseKestrel(kestrel => kestrel.ListenGithubReverseProxy("FastGithub.cer", "FastGithub.key")); + web.Configure(app => app.UseHttpsReverseProxy()); + web.UseKestrel(kestrel => kestrel.ListenHttpsReverseProxy("FastGithub.cer", "FastGithub.key")); }); } } diff --git a/FastGithub/appsettings.json b/FastGithub/appsettings.json index 530937f..251f6fb 100644 --- a/FastGithub/appsettings.json +++ b/FastGithub/appsettings.json @@ -23,7 +23,7 @@ "Yarp": "Warning", "System": "Warning", "Microsoft": "Warning", - "Microsoft.AspNetCore.Server.Kestrel": "Error" + "Microsoft.AspNetCore.Server.Kestrel": "None" } } }