使用8.8.8.8dns服务器

This commit is contained in:
陈国伟 2021-11-29 14:09:19 +08:00
parent a13aee0c60
commit 94e52b0729
2 changed files with 6 additions and 5 deletions

View File

@ -9,6 +9,7 @@ using Microsoft.Extensions.Options;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
@ -33,7 +34,7 @@ namespace FastGithub.DomainResolve
private readonly ConcurrentDictionary<string, SemaphoreSlim> semaphoreSlims = new(); private readonly ConcurrentDictionary<string, SemaphoreSlim> semaphoreSlims = new();
private readonly IMemoryCache dnsLookupCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); private readonly IMemoryCache dnsLookupCache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
private readonly TimeSpan minTimeToLive = TimeSpan.FromSeconds(30d); private readonly TimeSpan minTimeToLive = TimeSpan.FromMinutes(1d);
private readonly TimeSpan maxTimeToLive = TimeSpan.FromMinutes(10d); private readonly TimeSpan maxTimeToLive = TimeSpan.FromMinutes(10d);
private readonly int resolveTimeout = (int)TimeSpan.FromSeconds(4d).TotalMilliseconds; private readonly int resolveTimeout = (int)TimeSpan.FromSeconds(4d).TotalMilliseconds;
@ -130,10 +131,10 @@ namespace FastGithub.DomainResolve
{ {
return Array.Empty<IPAddress>(); return Array.Empty<IPAddress>();
} }
catch (SocketException ex) catch (IOException ex) when (ex.InnerException is SocketException)
{ {
this.logger.LogWarning($"{endPoint.Host}@{dns}->{ex.Message}"); this.logger.LogWarning($"{endPoint.Host}@{dns}->{ex.Message}");
return this.dnsLookupCache.Set(key, Array.Empty<IPAddress>(), this.minTimeToLive); return this.dnsLookupCache.Set(key, Array.Empty<IPAddress>(), this.maxTimeToLive);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -3,8 +3,8 @@
"FastGithub": { "FastGithub": {
"HttpProxyPort": 38457, // httplinux/osx使 "HttpProxyPort": 38457, // httplinux/osx使
"FallbackDns": [ // dnstcp "FallbackDns": [ // dnstcp
"114.114.114.114:53", "8.8.8.8:53",
"119.29.29.29:53" "114.114.114.114:53"
], ],
"DomainConfigs": { "DomainConfigs": {
"*.fastgithub.com": { // *.0 "*.fastgithub.com": { // *.0