diff --git a/FastGithub.Configuration/FastGithubOptions.cs b/FastGithub.Configuration/FastGithubOptions.cs index 6813525..e50884a 100644 --- a/FastGithub.Configuration/FastGithubOptions.cs +++ b/FastGithub.Configuration/FastGithubOptions.cs @@ -7,6 +7,11 @@ namespace FastGithub.Configuration /// public class FastGithubOptions { + /// + /// 监听配置 + /// + public ListenConfig Listen { get; set; } = new ListenConfig(); + /// /// 未污染的dns /// diff --git a/FastGithub.Configuration/FastGithubListenOptions.cs b/FastGithub.Configuration/ListenConfig.cs similarity index 61% rename from FastGithub.Configuration/FastGithubListenOptions.cs rename to FastGithub.Configuration/ListenConfig.cs index 3955490..c209ab9 100644 --- a/FastGithub.Configuration/FastGithubListenOptions.cs +++ b/FastGithub.Configuration/ListenConfig.cs @@ -1,18 +1,18 @@ namespace FastGithub.Configuration { /// - /// 监听选项 + /// 监听配置 /// - public class FastGithubListenOptions + public record ListenConfig { /// /// 监听的ssh端口 /// - public int SshPort { get; set; } = 22; + public int SshPort { get; init; } = 22; /// /// 监听的dns端口 /// - public int DnsPort { get; set; } = 53; + public int DnsPort { get; init; } = 53; } } diff --git a/FastGithub.Dns/DnsHostedService.cs b/FastGithub.Dns/DnsHostedService.cs index 8b91f97..dec1c70 100644 --- a/FastGithub.Dns/DnsHostedService.cs +++ b/FastGithub.Dns/DnsHostedService.cs @@ -17,7 +17,7 @@ namespace FastGithub.Dns { private readonly DnsServer dnsServer; private readonly IEnumerable dnsValidators; - private readonly IOptions listenOptions; + private readonly IOptionsMonitor options; private readonly ILogger logger; /// @@ -25,19 +25,17 @@ namespace FastGithub.Dns /// /// /// - /// - /// + /// /// public DnsHostedService( DnsServer dnsServer, IEnumerable dnsValidators, IOptionsMonitor options, - IOptions listenOptions, ILogger logger) { this.dnsServer = dnsServer; this.dnsValidators = dnsValidators; - this.listenOptions = listenOptions; + this.options = options; this.logger = logger; options.OnChange(opt => @@ -56,7 +54,7 @@ namespace FastGithub.Dns /// public override async Task StartAsync(CancellationToken cancellationToken) { - var port = this.listenOptions.Value.DnsPort; + var port = this.options.CurrentValue.Listen.DnsPort; this.dnsServer.Bind(IPAddress.Any, port); this.logger.LogInformation("DNS服务启动成功"); diff --git a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs index 61abc8b..9ca702b 100644 --- a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs +++ b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs @@ -72,8 +72,8 @@ namespace FastGithub /// public static void ListenGithubSshProxy(this KestrelServerOptions kestrel) { - var listenOptions = kestrel.ApplicationServices.GetRequiredService>(); - var sshPort = listenOptions.Value.SshPort; + var listenOptions = kestrel.ApplicationServices.GetRequiredService>(); + var sshPort = listenOptions.Value.Listen.SshPort; var logger = kestrel.GetLogger(); if (LocalMachine.CanListenTcp(sshPort) == false) diff --git a/FastGithub/Startup.cs b/FastGithub/Startup.cs index 412298b..2d14eb6 100644 --- a/FastGithub/Startup.cs +++ b/FastGithub/Startup.cs @@ -27,7 +27,6 @@ namespace FastGithub /// public void ConfigureServices(IServiceCollection services) { - services.Configure(this.Configuration); services.Configure(this.Configuration.GetSection(nameof(FastGithub))); services.AddConfiguration(); diff --git a/FastGithub/appsettings.json b/FastGithub/appsettings.json index 9c80f83..44858aa 100644 --- a/FastGithub/appsettings.json +++ b/FastGithub/appsettings.json @@ -1,6 +1,10 @@ { // 新增的子配置文件appsettings.*.json,重启应用程序才生效 "FastGithub": { + "Listen": { + "SshPort": 22, // ssh监听的端口,修改后重启应用才生效 + "DnsPort": 53 // dns监听的端口,修改后重启应用才生效 + }, "PureDns": { // 用于解析DomainConfigs的域名 "IPAddress": "127.0.0.1", "Port": 5533 // 5533指向dnscrypt-proxy