拆分项目

This commit is contained in:
xljiulang 2021-07-16 19:47:03 +08:00
parent 6b565c14d2
commit a3ff984c5c
15 changed files with 76 additions and 30 deletions

View File

@ -6,7 +6,7 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace FastGithub.ReverseProxy
namespace FastGithub.Dns.DnscryptProxy
{
/// <summary>
/// DnscryptProxy后台服务

View File

@ -0,0 +1,21 @@
using FastGithub.Dns.DnscryptProxy;
using Microsoft.Extensions.DependencyInjection;
namespace FastGithub
{
/// <summary>
/// DnscryptProxy的服务注册扩展
/// </summary>
public static class DnscryptProxyServiceCollectionExtensions
{
/// <summary>
/// 添加DnscryptProxy
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddDnscryptProxy(this IServiceCollection services)
{
return services.AddHostedService<DnscryptProxyHostedService>();
}
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="dnscrypt-proxy">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="dnscrypt-proxy.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="dnscrypt-proxy.toml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -4,16 +4,16 @@ using Microsoft.Extensions.DependencyInjection;
namespace FastGithub
{
/// <summary>
/// 服务注册扩展
/// dns服务注册扩展
/// </summary>
public static class DnsServerServiceCollectionExtensions
{
/// <summary>
/// 注册github的dns服务
/// 注册dns服务
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddGithubDns(this IServiceCollection services)
public static IServiceCollection AddDnsServer(this IServiceCollection services)
{
return services
.AddSingleton<RequestResolver>()

View File

@ -15,10 +15,4 @@
<ProjectReference Include="..\FastGithub.Core\FastGithub.Core.csproj" />
</ItemGroup>
<ItemGroup >
<None Update="dnscrypt-proxy*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -21,12 +21,12 @@ namespace FastGithub
private static readonly ConcurrentDictionary<string, Lazy<X509Certificate2>> domainCerts = new();
/// <summary>
/// 监听github的反向代理
/// 监听https的反向代理
/// </summary>
/// <param name="kestrel"></param>
/// <param name="caPublicCerPath"></param>
/// <param name="caPrivateKeyPath"></param>
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<ILoggerFactory>();
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)

View File

@ -9,16 +9,16 @@ using Yarp.ReverseProxy.Forwarder;
namespace FastGithub
{
/// <summary>
/// gitub反向代理的中间件扩展
/// https反向代理的中间件扩展
/// </summary>
public static class ReverseProxyApplicationBuilderExtensions
{
/// <summary>
/// 使用gitub反向代理中间件
/// 使用https反向代理中间件
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public static IApplicationBuilder UseGithubReverseProxy(this IApplicationBuilder app)
public static IApplicationBuilder UseHttpsReverseProxy(this IApplicationBuilder app)
{
var httpForwarder = app.ApplicationServices.GetRequiredService<IHttpForwarder>();
var httpClientHanlder = app.ApplicationServices.GetRequiredService<NoSniHttpClientHanlder>();

View File

@ -4,23 +4,22 @@ using Microsoft.Extensions.DependencyInjection;
namespace FastGithub
{
/// <summary>
/// gitub反向代理的服务注册扩展
/// https反向代理的服务注册扩展
/// </summary>
public static class ReverseProxyServiceCollectionExtensions
{
/// <summary>
/// gitub反向代理
/// 添加https反向代理
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddGithubReverseProxy(this IServiceCollection services)
public static IServiceCollection AddReverseProxy(this IServiceCollection services)
{
return services
.AddMemoryCache()
.AddHttpForwarder()
.AddSingleton<TrustedResolver>()
.AddTransient<NoSniHttpClientHanlder>()
.AddHostedService<DnscryptProxyHostedService>();
.AddTransient<NoSniHttpClientHanlder>();
}
}
}

View File

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

View File

@ -19,6 +19,7 @@
<ItemGroup>
<PackageReference Include="PInvoke.AdvApi32" Version="0.7.104" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
<ProjectReference Include="..\FastGithub.Dns.DnscryptProxy\FastGithub.Dns.DnscryptProxy.csproj" />
<ProjectReference Include="..\FastGithub.Dns\FastGithub.Dns.csproj" />
<ProjectReference Include="..\FastGithub.ReverseProxy\FastGithub.ReverseProxy.csproj" />
<ProjectReference Include="..\FastGithub.Upgrade\FastGithub.Upgrade.csproj" />

View File

@ -32,17 +32,19 @@ namespace FastGithub
})
.ConfigureServices((ctx, services) =>
{
services.AddAppUpgrade();
services.AddGithubDns();
services.AddGithubReverseProxy();
services.AddOptions<FastGithubOptions>()
.Bind(ctx.Configuration.GetSection(nameof(FastGithub)))
.Validate(opt => opt.TrustedDns.Validate() && opt.UntrustedDns.Validate(), "无效的Dns配置");
services
.AddAppUpgrade()
.AddDnsServer()
.AddReverseProxy()
.AddDnscryptProxy()
.AddOptions<FastGithubOptions>()
.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"));
});
}
}

View File

@ -23,7 +23,7 @@
"Yarp": "Warning",
"System": "Warning",
"Microsoft": "Warning",
"Microsoft.AspNetCore.Server.Kestrel": "Error"
"Microsoft.AspNetCore.Server.Kestrel": "None"
}
}
}