超级优化
parent
1a41eca5e3
commit
c0f5c32734
|
@ -325,7 +325,7 @@ module.exports = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
interval: 300000,
|
interval: 300000,
|
||||||
hostnameList: ['github.com'],
|
hostnameList: ['github.com'],
|
||||||
dnsProviders: ['usa', 'quad9', 'rubyfish']
|
dnsProviders: ['safe360', 'cloudflare', 'rubyfish']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
"@vue/cli-service": "~4.5.0",
|
"@vue/cli-service": "~4.5.0",
|
||||||
"@vue/eslint-config-standard": "^5.1.2",
|
"@vue/eslint-config-standard": "^5.1.2",
|
||||||
"babel-eslint": "^10.1.0",
|
"babel-eslint": "^10.1.0",
|
||||||
"electron": "17.1.0",
|
"electron": "30.0.3",
|
||||||
"electron-devtools-installer": "^3.1.0",
|
"electron-devtools-installer": "^3.1.0",
|
||||||
"electron-icon-builder": "^2.0.1",
|
"electron-icon-builder": "^2.0.1",
|
||||||
"eslint": "^6.7.2",
|
"eslint": "^6.7.2",
|
||||||
|
|
|
@ -32,6 +32,12 @@
|
||||||
<a-radio-button value="https://mirrors.aliyun.com/pypi/simple/">
|
<a-radio-button value="https://mirrors.aliyun.com/pypi/simple/">
|
||||||
aliyun镜像
|
aliyun镜像
|
||||||
</a-radio-button>
|
</a-radio-button>
|
||||||
|
<a-radio-button value="https://mirrors.bfsu.edu.cn/pypi/web/simple">
|
||||||
|
北京外国语大学镜像
|
||||||
|
</a-radio-button>
|
||||||
|
<a-radio-button value="https://mirror.nju.edu.cn/pypi/web/simple">
|
||||||
|
南京大学镜像
|
||||||
|
</a-radio-button>
|
||||||
</a-radio-group>
|
</a-radio-group>
|
||||||
<div class="form-help">设置后立即生效,即使关闭ds也会继续保持</div>
|
<div class="form-help">设置后立即生效,即使关闭ds也会继续保持</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
|
@ -4,48 +4,43 @@ const BaseDNS = require('./base')
|
||||||
const log = require('../../utils/util.log')
|
const log = require('../../utils/util.log')
|
||||||
const dohQueryAsync = promisify(doh.query)
|
const dohQueryAsync = promisify(doh.query)
|
||||||
|
|
||||||
const PRESETS = {
|
module.exports = class DNSOverHTTPS extends BaseDNS {
|
||||||
'github.com': ['20.27.177.113', '20.205.243.166', '20.200.245.247'],
|
constructor(dnsServer) {
|
||||||
'api.github.com': ['20.27.177.116', '20.205.243.168', '20.200.245.245']
|
|
||||||
}
|
|
||||||
|
|
||||||
class DNSOverHTTPS extends BaseDNS {
|
|
||||||
constructor (dnsServer) {
|
|
||||||
super()
|
super()
|
||||||
this.dnsServer = dnsServer
|
this.dnsServer = dnsServer
|
||||||
this.lastLookupError = null // 添加属性来记录最后一次查询错误
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processQueryResult (result) {
|
async _lookup(hostname) {
|
||||||
if (result.answers.length === 0) {
|
// 直接判断域名是否为example.com
|
||||||
log.error('该域名没有ip地址解析:', result.name)
|
if (hostname === 'github.com') {
|
||||||
return []
|
log.info('域名github.com使用内置IP集')
|
||||||
|
// 返回预设的IP地址集
|
||||||
|
return ['20.27.177.113', '20.205.243.166', '20.200.245.247']
|
||||||
|
// 20.27.177.113日本(三网平均延时88MS(三网优秀)) 20.205.243.166新加坡(三网平均延时96MS(电信联通106.5平均延时,移动平均77MS)) 20.200.245.247韩国(三网平均108ms(移动平均120ms))
|
||||||
}
|
}
|
||||||
return result.answers
|
// 直接判断域名是否为example.com
|
||||||
.filter(item => item.type === 'A')
|
if (hostname === 'github.com') {
|
||||||
.map(item => item.data)
|
log.info('域名github.com使用内置IP集')
|
||||||
}
|
// 返回预设的IP地址集
|
||||||
|
return ['20.27.177.116', '20.205.243.168', '20.200.245.245']
|
||||||
async _lookup (hostname) {
|
|
||||||
const preset = PRESETS[hostname]
|
|
||||||
if (preset) {
|
|
||||||
log.debug(`使用预设IP集:${hostname}`)
|
|
||||||
return preset
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await dohQueryAsync({ url: this.dnsServer }, [{ type: 'A', name: hostname }])
|
const result = await dohQueryAsync({ url: this.dnsServer }, [{ type: 'A', name: hostname }])
|
||||||
const ips = this.processQueryResult(result)
|
if (result.answers.length === 0) {
|
||||||
if (ips.length > 0) {
|
// 说明没有获取到ip
|
||||||
log.info('获取到域名地址:', hostname, ips)
|
log.info('该域名没有ip地址解析:', hostname)
|
||||||
|
return []
|
||||||
}
|
}
|
||||||
this.lastLookupError = null // 重置错误记录
|
const ret = result.answers.filter(item => item.type === 'A').map(item => item.data)
|
||||||
return ips
|
if (ret.length === 0) {
|
||||||
|
log.info('该域名没有IPv4地址解析:', hostname)
|
||||||
|
} else {
|
||||||
|
log.info('获取到域名地址:', hostname, JSON.stringify(ret))
|
||||||
|
}
|
||||||
|
return ret
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error('DNS查询错误:', hostname, ', DNS服务器:', this.dnsServer, ', 错误:', e)
|
log.warn('DNS query error:', hostname, ', dns:', this.dnsServer, ', error:', e)
|
||||||
this.lastLookupError = e // 记录错误
|
return []
|
||||||
throw e // 重新抛出错误,让调用者处理
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = DNSOverHTTPS
|
|
Loading…
Reference in New Issue