From 19bd5550ad4b440e4fdcd0d868c464babf8bfec5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=80=81=E4=B9=9D?= <366193849@qq.com>
Date: Wed, 8 Sep 2021 14:28:11 +0800
Subject: [PATCH] =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=87=8D=E5=91=BD=E5=90=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...dpHostedService.cs => DnsHostedService.cs} | 20 +++++++------------
FastGithub.Dns/DnsOverUdpServer.cs | 6 +++++-
FastGithub.Dns/ServiceCollectionExtensions.cs | 2 +-
3 files changed, 13 insertions(+), 15 deletions(-)
rename FastGithub.Dns/{DnsOverUdpHostedService.cs => DnsHostedService.cs} (79%)
diff --git a/FastGithub.Dns/DnsOverUdpHostedService.cs b/FastGithub.Dns/DnsHostedService.cs
similarity index 79%
rename from FastGithub.Dns/DnsOverUdpHostedService.cs
rename to FastGithub.Dns/DnsHostedService.cs
index 13ec6b0..e9beb03 100644
--- a/FastGithub.Dns/DnsOverUdpHostedService.cs
+++ b/FastGithub.Dns/DnsHostedService.cs
@@ -1,7 +1,5 @@
-using FastGithub.Configuration;
-using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Net;
@@ -13,30 +11,26 @@ namespace FastGithub.Dns
///
/// dns后台服务
///
- sealed class DnsOverUdpHostedService : BackgroundService
+ sealed class DnsHostedService : BackgroundService
{
private readonly DnsOverUdpServer dnsOverUdpServer;
private readonly IEnumerable conflictValidators;
- private readonly ILogger logger;
-
+ private readonly ILogger logger;
///
/// dns后台服务
///
///
///
- ///
///
- public DnsOverUdpHostedService(
+ public DnsHostedService(
DnsOverUdpServer dnsOverUdpServer,
IEnumerable conflictValidators,
- IOptionsMonitor options,
- ILogger logger)
+ ILogger logger)
{
this.dnsOverUdpServer = dnsOverUdpServer;
this.conflictValidators = conflictValidators;
- this.logger = logger;
- options.OnChange(opt => SystemDnsUtil.FlushResolverCache());
+ this.logger = logger;
}
///
@@ -54,7 +48,7 @@ namespace FastGithub.Dns
}
catch (Exception ex)
{
- this.logger.LogError($"DNS服务启动失败:{ex.Message}{Environment.NewLine}请配置系统或浏览器使用{nameof(FastGithub)}的DoH,或向系统hosts文件添加github相关域名的ip为127.0.0.1");
+ this.logger.LogError($"DNS服务启动失败:{ex.Message}{Environment.NewLine}请配置系统或浏览器使用{nameof(FastGithub)}的DoH:https://127.0.0.1/dns-query,或向系统hosts文件添加github相关域名的ip为127.0.0.1");
}
foreach (var item in this.conflictValidators)
diff --git a/FastGithub.Dns/DnsOverUdpServer.cs b/FastGithub.Dns/DnsOverUdpServer.cs
index ab121df..2102cbb 100644
--- a/FastGithub.Dns/DnsOverUdpServer.cs
+++ b/FastGithub.Dns/DnsOverUdpServer.cs
@@ -1,6 +1,7 @@
using DNS.Protocol;
using FastGithub.Configuration;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
using System;
using System.Net;
using System.Net.Sockets;
@@ -28,10 +29,13 @@ namespace FastGithub.Dns
///
public DnsOverUdpServer(
RequestResolver requestResolver,
- ILogger logger)
+ ILogger logger,
+ IOptionsMonitor options)
{
this.requestResolver = requestResolver;
this.logger = logger;
+
+ options.OnChange(opt => SystemDnsUtil.FlushResolverCache());
}
///
diff --git a/FastGithub.Dns/ServiceCollectionExtensions.cs b/FastGithub.Dns/ServiceCollectionExtensions.cs
index 1205a86..f3d26d6 100644
--- a/FastGithub.Dns/ServiceCollectionExtensions.cs
+++ b/FastGithub.Dns/ServiceCollectionExtensions.cs
@@ -21,7 +21,7 @@ namespace FastGithub
services.TryAddSingleton();
services.AddSingleton();
services.AddSingleton();
- return services.AddHostedService();
+ return services.AddHostedService();
}
}
}