增加Listen的配置文件(#34)
This commit is contained in:
parent
b530db4240
commit
4499c640f5
@ -7,6 +7,11 @@ namespace FastGithub.Configuration
|
||||
/// </summary>
|
||||
public class FastGithubOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 监听配置
|
||||
/// </summary>
|
||||
public ListenConfig Listen { get; set; } = new ListenConfig();
|
||||
|
||||
/// <summary>
|
||||
/// 未污染的dns
|
||||
/// </summary>
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
namespace FastGithub.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// 监听选项
|
||||
/// 监听配置
|
||||
/// </summary>
|
||||
public class FastGithubListenOptions
|
||||
public record ListenConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 监听的ssh端口
|
||||
/// </summary>
|
||||
public int SshPort { get; set; } = 22;
|
||||
public int SshPort { get; init; } = 22;
|
||||
|
||||
/// <summary>
|
||||
/// 监听的dns端口
|
||||
/// </summary>
|
||||
public int DnsPort { get; set; } = 53;
|
||||
public int DnsPort { get; init; } = 53;
|
||||
}
|
||||
}
|
||||
@ -17,7 +17,7 @@ namespace FastGithub.Dns
|
||||
{
|
||||
private readonly DnsServer dnsServer;
|
||||
private readonly IEnumerable<IDnsValidator> dnsValidators;
|
||||
private readonly IOptions<FastGithubListenOptions> listenOptions;
|
||||
private readonly IOptionsMonitor<FastGithubOptions> options;
|
||||
private readonly ILogger<DnsHostedService> logger;
|
||||
|
||||
/// <summary>
|
||||
@ -25,19 +25,17 @@ namespace FastGithub.Dns
|
||||
/// </summary>
|
||||
/// <param name="dnsServer"></param>
|
||||
/// <param name="dnsValidators"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="listenOptions"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="logger"></param>
|
||||
public DnsHostedService(
|
||||
DnsServer dnsServer,
|
||||
IEnumerable<IDnsValidator> dnsValidators,
|
||||
IOptionsMonitor<FastGithubOptions> options,
|
||||
IOptions<FastGithubListenOptions> listenOptions,
|
||||
ILogger<DnsHostedService> 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
|
||||
/// <returns></returns>
|
||||
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服务启动成功");
|
||||
|
||||
|
||||
@ -72,8 +72,8 @@ namespace FastGithub
|
||||
/// <param name="kestrel"></param>
|
||||
public static void ListenGithubSshProxy(this KestrelServerOptions kestrel)
|
||||
{
|
||||
var listenOptions = kestrel.ApplicationServices.GetRequiredService<IOptions<FastGithubListenOptions>>();
|
||||
var sshPort = listenOptions.Value.SshPort;
|
||||
var listenOptions = kestrel.ApplicationServices.GetRequiredService<IOptions<FastGithubOptions>>();
|
||||
var sshPort = listenOptions.Value.Listen.SshPort;
|
||||
var logger = kestrel.GetLogger();
|
||||
|
||||
if (LocalMachine.CanListenTcp(sshPort) == false)
|
||||
|
||||
@ -27,7 +27,6 @@ namespace FastGithub
|
||||
/// <param name="services"></param>
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.Configure<FastGithubListenOptions>(this.Configuration);
|
||||
services.Configure<FastGithubOptions>(this.Configuration.GetSection(nameof(FastGithub)));
|
||||
|
||||
services.AddConfiguration();
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user