恢复预设IP功能

release-2.0.0.2
王良 2025-03-04 00:30:29 +08:00
parent 4097a34c78
commit 4e56d4dc2c
4 changed files with 6 additions and 35 deletions

View File

@ -84,7 +84,7 @@ module.exports = class BaseDNS {
async _lookupInternal (hostname) {
// 获取当前域名的预设IP列表
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList')
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, `matched preSetIpList(${this.dnsName})`)
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
if (hostnamePreSetIpList.length > 0) {
hostnamePreSetIpList = hostnamePreSetIpList.slice()

View File

@ -68,16 +68,14 @@ module.exports = {
return dnsMap
},
hasDnsLookup (dnsConfig, hostname) {
let providerName = null
// 先匹配 预设IP配置
const hostnamePreSetIpList = matchUtil.matchHostname(dnsConfig.preSetIpList, hostname, 'matched preSetIpList')
const hostnamePreSetIpList = matchUtil.matchHostname(dnsConfig.preSetIpList, hostname, 'matched preSetIpList(hasDnsLookup)')
if (hostnamePreSetIpList) {
return dnsConfig.dnsMap.PreSet
}
// 再匹配 DNS映射配置
providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
const providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
// 由于DNS中的usa已重命名为cloudflare所以做以下处理为了向下兼容
if (providerName === 'usa' && dnsConfig.dnsMap.usa == null && dnsConfig.dnsMap.cloudflare != null) {

View File

@ -1,40 +1,13 @@
const matchUtil = require('../../utils/util.match')
const BaseDNS = require('./base')
function mapToList (ipMap) {
const ipList = []
for (const key in ipMap) {
if (ipMap[key]) { // 配置为 ture 时才生效
ipList.push(key)
}
}
return ipList
}
module.exports = class DNSOverPreSetIpList extends BaseDNS {
constructor (preSetIpList) {
super()
this.preSetIpList = preSetIpList
super('PreSet', null, preSetIpList)
this.name = 'PreSet'
this.type = 'PreSet'
}
async _lookup (hostname) {
// 获取当前域名的预设IP列表
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList')
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
if (hostnamePreSetIpList.length > 0) {
hostnamePreSetIpList = hostnamePreSetIpList.slice()
} else {
hostnamePreSetIpList = mapToList(hostnamePreSetIpList)
}
if (hostnamePreSetIpList.length > 0) {
return hostnamePreSetIpList
}
}
// 未预设当前域名的IP列表
async _lookup (_hostname) {
return []
}
}

View File

@ -79,7 +79,7 @@ class SpeedTester {
}
async getFromOneDns (dns) {
return await dns._lookup(this.hostname)
return await dns._lookupInternal(this.hostname)
}
async test () {