类型重命名
This commit is contained in:
		
							parent
							
								
									0f94f118ca
								
							
						
					
					
						commit
						81f6afdf8b
					
				@ -13,28 +13,28 @@ namespace FastGithub.Dns
 | 
				
			|||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// dns后台服务
 | 
					    /// dns后台服务
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    sealed class DnsHostedService : BackgroundService
 | 
					    sealed class DnsOverUdpHostedService : BackgroundService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly DnsServer dnsServer;
 | 
					        private readonly DnsOverUdpServer dnsOverUdpServer;
 | 
				
			||||||
        private readonly IEnumerable<IDnsValidator> dnsValidators;
 | 
					        private readonly IEnumerable<IConflictValidator> conflictValidators;
 | 
				
			||||||
        private readonly IOptionsMonitor<FastGithubOptions> options;
 | 
					        private readonly IOptionsMonitor<FastGithubOptions> options;
 | 
				
			||||||
        private readonly ILogger<DnsHostedService> logger;
 | 
					        private readonly ILogger<DnsOverUdpHostedService> logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// dns后台服务
 | 
					        /// dns后台服务
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="dnsServer"></param>
 | 
					        /// <param name="dnsOverUdpServer"></param>
 | 
				
			||||||
        /// <param name="dnsValidators"></param>
 | 
					        /// <param name="conflictValidators"></param>
 | 
				
			||||||
        /// <param name="options"></param> 
 | 
					        /// <param name="options"></param> 
 | 
				
			||||||
        /// <param name="logger"></param>
 | 
					        /// <param name="logger"></param>
 | 
				
			||||||
        public DnsHostedService(
 | 
					        public DnsOverUdpHostedService(
 | 
				
			||||||
            DnsServer dnsServer,
 | 
					            DnsOverUdpServer dnsOverUdpServer,
 | 
				
			||||||
            IEnumerable<IDnsValidator> dnsValidators,
 | 
					            IEnumerable<IConflictValidator> conflictValidators,
 | 
				
			||||||
            IOptionsMonitor<FastGithubOptions> options,
 | 
					            IOptionsMonitor<FastGithubOptions> options,
 | 
				
			||||||
            ILogger<DnsHostedService> logger)
 | 
					            ILogger<DnsOverUdpHostedService> logger)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.dnsServer = dnsServer;
 | 
					            this.dnsOverUdpServer = dnsOverUdpServer;
 | 
				
			||||||
            this.dnsValidators = dnsValidators;
 | 
					            this.conflictValidators = conflictValidators;
 | 
				
			||||||
            this.options = options;
 | 
					            this.options = options;
 | 
				
			||||||
            this.logger = logger;
 | 
					            this.logger = logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -54,14 +54,14 @@ namespace FastGithub.Dns
 | 
				
			|||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        public override async Task StartAsync(CancellationToken cancellationToken)
 | 
					        public override async Task StartAsync(CancellationToken cancellationToken)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var port = this.options.CurrentValue.Listen.DnsPort;
 | 
					            var dnsPort = this.options.CurrentValue.Listen.DnsPort;
 | 
				
			||||||
            this.dnsServer.Bind(IPAddress.Any, port);
 | 
					            this.dnsOverUdpServer.Bind(IPAddress.Any, dnsPort);
 | 
				
			||||||
            this.logger.LogInformation("DNS服务启动成功");
 | 
					            this.logger.LogInformation("DNS服务启动成功");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const int DNS_PORT = 53;
 | 
					            const int DNS_PORT = 53;
 | 
				
			||||||
            if (port != DNS_PORT)
 | 
					            if (dnsPort != DNS_PORT)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                this.logger.LogWarning($"由于使用了非标准DNS端口{port},你需要将{nameof(FastGithub)}设置为标准DNS的上游");
 | 
					                this.logger.LogWarning($"由于使用了非标准DNS端口{dnsPort},你需要将{nameof(FastGithub)}设置为标准DNS的上游");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (OperatingSystem.IsWindows())
 | 
					            else if (OperatingSystem.IsWindows())
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -85,7 +85,7 @@ namespace FastGithub.Dns
 | 
				
			|||||||
                this.logger.LogWarning($"不支持自动设置本机DNS,请手工添加{IPAddress.Loopback}做为连接网络的DNS的第一条记录");
 | 
					                this.logger.LogWarning($"不支持自动设置本机DNS,请手工添加{IPAddress.Loopback}做为连接网络的DNS的第一条记录");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            foreach (var item in this.dnsValidators)
 | 
					            foreach (var item in this.conflictValidators)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                await item.ValidateAsync();
 | 
					                await item.ValidateAsync();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -100,7 +100,7 @@ namespace FastGithub.Dns
 | 
				
			|||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
 | 
					        protected override Task ExecuteAsync(CancellationToken stoppingToken)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return this.dnsServer.ListenAsync(stoppingToken);
 | 
					            return this.dnsOverUdpServer.ListenAsync(stoppingToken);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@ -110,7 +110,7 @@ namespace FastGithub.Dns
 | 
				
			|||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        public override Task StopAsync(CancellationToken cancellationToken)
 | 
					        public override Task StopAsync(CancellationToken cancellationToken)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.dnsServer.Dispose();
 | 
					            this.dnsOverUdpServer.Dispose();
 | 
				
			||||||
            this.logger.LogInformation("DNS服务已停止");
 | 
					            this.logger.LogInformation("DNS服务已停止");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (OperatingSystem.IsWindows())
 | 
					            if (OperatingSystem.IsWindows())
 | 
				
			||||||
@ -12,10 +12,10 @@ namespace FastGithub.Dns
 | 
				
			|||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// dns服务器
 | 
					    /// dns服务器
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    sealed class DnsServer : IDisposable
 | 
					    sealed class DnsOverUdpServer : IDisposable
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly RequestResolver requestResolver;
 | 
					        private readonly RequestResolver requestResolver;
 | 
				
			||||||
        private readonly ILogger<DnsServer> logger;
 | 
					        private readonly ILogger<DnsOverUdpServer> logger;
 | 
				
			||||||
        private readonly Socket socket = new(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
 | 
					        private readonly Socket socket = new(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
 | 
				
			||||||
        private readonly byte[] buffer = new byte[ushort.MaxValue];
 | 
					        private readonly byte[] buffer = new byte[ushort.MaxValue];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -24,9 +24,9 @@ namespace FastGithub.Dns
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="requestResolver"></param>
 | 
					        /// <param name="requestResolver"></param>
 | 
				
			||||||
        /// <param name="logger"></param>
 | 
					        /// <param name="logger"></param>
 | 
				
			||||||
        public DnsServer(
 | 
					        public DnsOverUdpServer(
 | 
				
			||||||
            RequestResolver requestResolver,
 | 
					            RequestResolver requestResolver,
 | 
				
			||||||
            ILogger<DnsServer> logger)
 | 
					            ILogger<DnsOverUdpServer> logger)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.requestResolver = requestResolver;
 | 
					            this.requestResolver = requestResolver;
 | 
				
			||||||
            this.logger = logger;
 | 
					            this.logger = logger;
 | 
				
			||||||
@ -10,28 +10,28 @@ using System.Threading.Tasks;
 | 
				
			|||||||
namespace FastGithub.Dns
 | 
					namespace FastGithub.Dns
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// host文件配置验证器
 | 
					    /// host文件冲突验证器
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    sealed class HostsValidator : IDnsValidator
 | 
					    sealed class HostsConflictValidator : IConflictValidator
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly FastGithubConfig fastGithubConfig;
 | 
					        private readonly FastGithubConfig fastGithubConfig;
 | 
				
			||||||
        private readonly ILogger<HostsValidator> logger;
 | 
					        private readonly ILogger<HostsConflictValidator> logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// host文件配置验证器
 | 
					        /// host文件冲突验证器
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="fastGithubConfig"></param>
 | 
					        /// <param name="fastGithubConfig"></param>
 | 
				
			||||||
        /// <param name="logger"></param>
 | 
					        /// <param name="logger"></param>
 | 
				
			||||||
        public HostsValidator(
 | 
					        public HostsConflictValidator(
 | 
				
			||||||
            FastGithubConfig fastGithubConfig,
 | 
					            FastGithubConfig fastGithubConfig,
 | 
				
			||||||
            ILogger<HostsValidator> logger)
 | 
					            ILogger<HostsConflictValidator> logger)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.fastGithubConfig = fastGithubConfig;
 | 
					            this.fastGithubConfig = fastGithubConfig;
 | 
				
			||||||
            this.logger = logger;
 | 
					            this.logger = logger;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 验证host文件的域名解析配置 
 | 
					        /// 验证冲突 
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        public async Task ValidateAsync()
 | 
					        public async Task ValidateAsync()
 | 
				
			||||||
@ -3,12 +3,12 @@
 | 
				
			|||||||
namespace FastGithub.Dns
 | 
					namespace FastGithub.Dns
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// Dns验证器
 | 
					    /// Dns冲突验证器
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    interface IDnsValidator
 | 
					    interface IConflictValidator
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 验证
 | 
					        /// 验证冲突
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        Task ValidateAsync();
 | 
					        Task ValidateAsync();
 | 
				
			||||||
@ -8,23 +8,23 @@ using System.Threading.Tasks;
 | 
				
			|||||||
namespace FastGithub.Dns
 | 
					namespace FastGithub.Dns
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// 代理验证
 | 
					    /// 代理冲突验证
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    sealed class ProxyValidtor : IDnsValidator
 | 
					    sealed class ProxyConflictValidtor : IConflictValidator
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly IOptions<FastGithubOptions> options;
 | 
					        private readonly IOptions<FastGithubOptions> options;
 | 
				
			||||||
        private readonly ILogger<ProxyValidtor> logger;
 | 
					        private readonly ILogger<ProxyConflictValidtor> logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public ProxyValidtor(
 | 
					        public ProxyConflictValidtor(
 | 
				
			||||||
            IOptions<FastGithubOptions> options,
 | 
					            IOptions<FastGithubOptions> options,
 | 
				
			||||||
            ILogger<ProxyValidtor> logger)
 | 
					            ILogger<ProxyConflictValidtor> logger)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.options = options;
 | 
					            this.options = options;
 | 
				
			||||||
            this.logger = logger;
 | 
					            this.logger = logger;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 验证是否使用了代理
 | 
					        /// 验证冲突
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        public Task ValidateAsync()
 | 
					        public Task ValidateAsync()
 | 
				
			||||||
@ -17,11 +17,11 @@ namespace FastGithub
 | 
				
			|||||||
        public static IServiceCollection AddDnsServer(this IServiceCollection services)
 | 
					        public static IServiceCollection AddDnsServer(this IServiceCollection services)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            services.TryAddSingleton<RequestResolver>();
 | 
					            services.TryAddSingleton<RequestResolver>();
 | 
				
			||||||
            services.TryAddSingleton<DnsServer>();
 | 
					            services.TryAddSingleton<DnsOverUdpServer>();
 | 
				
			||||||
            services.TryAddSingleton<DnsOverHttpsMiddleware>();
 | 
					            services.TryAddSingleton<DnsOverHttpsMiddleware>();
 | 
				
			||||||
            services.AddSingleton<IDnsValidator, HostsValidator>();
 | 
					            services.AddSingleton<IConflictValidator, HostsConflictValidator>();
 | 
				
			||||||
            services.AddSingleton<IDnsValidator, ProxyValidtor>();
 | 
					            services.AddSingleton<IConflictValidator, ProxyConflictValidtor>();
 | 
				
			||||||
            return services.AddHostedService<DnsHostedService>();
 | 
					            return services.AddHostedService<DnsOverUdpHostedService>();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -8,18 +8,18 @@ using System.Threading.Tasks;
 | 
				
			|||||||
namespace FastGithub.ReverseProxy
 | 
					namespace FastGithub.ReverseProxy
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// github的ssh处理者
 | 
					    /// github的ssh代理处理者
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    sealed class GithubSshHandler : ConnectionHandler
 | 
					    sealed class GithubSshProxyHandler : ConnectionHandler
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly IDomainResolver domainResolver;
 | 
					        private readonly IDomainResolver domainResolver;
 | 
				
			||||||
        private readonly DnsEndPoint githubSshEndPoint = new("ssh.github.com", 443);
 | 
					        private readonly DnsEndPoint githubSshEndPoint = new("ssh.github.com", 443);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// github的ssh处理者
 | 
					        /// github的ssh代理处理者
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="domainResolver"></param>
 | 
					        /// <param name="domainResolver"></param>
 | 
				
			||||||
        public GithubSshHandler(IDomainResolver domainResolver)
 | 
					        public GithubSshProxyHandler(IDomainResolver domainResolver)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.domainResolver = domainResolver;
 | 
					            this.domainResolver = domainResolver;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -82,7 +82,7 @@ namespace FastGithub
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                kestrel.Listen(IPAddress.Any, sshPort, listen => listen.UseConnectionHandler<GithubSshHandler>());
 | 
					                kestrel.Listen(IPAddress.Any, sshPort, listen => listen.UseConnectionHandler<GithubSshProxyHandler>());
 | 
				
			||||||
                logger.LogInformation("已监听github的ssh代理");
 | 
					                logger.LogInformation("已监听github的ssh代理");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user