refactor: 修复usa dns服务器本身被污染的问题

pull/67/head
xiaojunnuo 2021-03-22 23:16:25 +08:00
parent b2ece8ffc1
commit 8cba411cfa
11 changed files with 69 additions and 72 deletions

View File

@ -47,14 +47,14 @@ module.exports = {
'github'
],
desc: 'clone加速复制链接脚本'
},
'/.*': {
proxy: 'gh.docmirror.top/_proxy',
backup: [
'github.com'
],
desc: '如果出现dev-sidecar报错可能是加速地址dns被污染了需要将本条配置删除'
}
// '/.*': {
// proxy: 'gh.docmirror.top/_proxy',
// backup: [
// 'github.com'
// ],
// desc: '如果出现dev-sidecar报错可能是加速地址dns被污染了需要将本条配置删除'
// }
},
'api.github.com': {
'^/_private/browser/stats$': {
@ -76,19 +76,18 @@ module.exports = {
'.*': { proxy: 'customer-stories-feed.fastgit.org' }
},
// google cdn
'www.google.com': {
'/recaptcha/.*': { proxy: 'www.recaptcha.net' },
'.*': {
proxy: 'gg.docmirror.top/_yxorp',
desc: '呀,被你发现了,偷偷的用,别声张'
}
},
// 'www.google.com': {
// '/recaptcha/.*': { proxy: 'www.recaptcha.net' },
// '.*': {
// proxy: 'gg.docmirror.top/_yxorp',
// desc: '呀,被你发现了,偷偷的用,别声张'
// }
// },
'ajax.googleapis.com': {
'.*': {
proxy: 'ajax.loli.net',
test: 'ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'
}
},
'fonts.googleapis.com': {
'.*': {
@ -112,9 +111,9 @@ module.exports = {
backup: ['fonts-gstatic.proxy.ustclug.org']
}
},
'clients*.google.com': { '.*': { abort: true } },
'www.googleapis.com': { '.*': { abort: true } },
'lh*.googleusercontent.com': { '.*': { abort: true } },
// 'clients*.google.com': { '.*': { abort: true } },
// 'www.googleapis.com': { '.*': { abort: true } },
// 'lh*.googleusercontent.com': { '.*': { abort: true } },
// mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.0/napi-v3-win32-x64.tar.gz
'*.s3.amazonaws.com': {
'/sqlite3/.*': {
@ -155,21 +154,20 @@ module.exports = {
},
usa: {
type: 'https',
server: 'https://cloudflare-dns.com/dns-query',
server: 'https://1.1.1.1/dns-query',
cacheSize: 1000
}
},
},
mapping: {
'assets.fastgit.org': 'usa',
// 'assets.fastgit.org': 'usa',
'*yarnpkg.com': 'usa',
'*cloudfront.net': 'usa',
'*github.io': 'usa',
'img.shields.io': 'usa',
'*.github.com': 'usa',
'*.githubusercontent.com': 'usa',
'*.githubassets.com': 'usa',
// "解决push的时候需要输入密码的问题",
'github.com': 'usa',
'*github.com': 'usa',
'*.vuepress.vuejs.org': 'usa',
'gh.docmirror.top': 'usa'
}

View File

@ -1,6 +1,6 @@
module.exports = {
name: '梯子',
enabled: true,
enabled: false,
server: {
},
serverDefault: {

View File

@ -93,10 +93,10 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"
"@docmirror/mitmproxy@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.3.3.tgz#dcef8fb8d4d552f556a6c60691db4d887efa40c6"
integrity sha512-YZdVaw3h+zv4Nq70JE4kwAMAtJJyCySSUI2NggG+y6dlr3Pztz7/yQG5Dx6WWYnUmfCWzDO+V3yHkxMBJ/ffGQ==
"@docmirror/mitmproxy@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.4.0.tgz#e4df4b0e9aa96896d7baa3680f22969872ad43ef"
integrity sha512-RAFcSqKD8huDPaUFs7k/pSijOc4PC0+JRp5dOk6NYfNDveKsJuPf1fjqbb6HqmbByjE+c+M09lwU3yX/XXqw9A==
dependencies:
agentkeepalive "^2.1.1"
child_process "^1.0.2"

View File

@ -1,3 +0,0 @@
const { ChoiceCache } = require('./index')
module.exports = new ChoiceCache()

View File

@ -28,24 +28,6 @@ class DynamicChoice {
this.createTime = new Date()
}
/**
* 设置新的backup列表
* @param backupList
*/
setBackupList (backupList) {
this.backup = backupList
let defaultTotal = backupList.length
for (const item of backupList) {
if (this.count[item]) {
continue
}
this.count[item] = { value: item, total: defaultTotal, error: 0, keepErrorCount: 0, successRate: 0.5 }
defaultTotal--
}
this.value = backupList.shift()
this.doCount(this.value, false)
}
doRank () {
// 将count里面根据权重排序
const list = []
@ -61,6 +43,24 @@ class DynamicChoice {
this.setBackupList(backup)
}
/**
* 设置新的backup列表
* @param backupList
*/
setBackupList (backupList) {
this.backup = backupList
let defaultTotal = backupList.length
for (const item of backupList) {
if (this.count[item]) {
continue
}
this.count[item] = { value: item, total: defaultTotal, error: 0, keepErrorCount: 0, successRate: 0.5 }
defaultTotal--
}
this.value = backupList.shift()
this.doCount(this.value, false)
}
countStart (value) {
this.doCount(value, false)
}
@ -92,12 +92,12 @@ class DynamicChoice {
count.error++
count.keepErrorCount++
} else {
count.total++
count.total += 10
}
count.successRate = 1.0 - (count.error / count.total)
if (isError && this.value === value) {
// 连续错误4次,切换下一个
if (count.keepErrorCount >= 4) {
// 连续错误10次,切换下一个
if (count.keepErrorCount >= 10) {
this.changeNext(count)
}
// 成功率小于50%,切换下一个

View File

@ -58,7 +58,7 @@ module.exports = class BaseDNS {
ipList.push(hostname) // 把原域名加入到统计里去
ipCache.setBackupList(ipList)
log.info(`[dns counter]:${hostname}`, ipCache.value, ipList, JSON.stringify(ipCache))
log.info(`[DNS] ${hostname} -> ${ipCache.value} (${new Date() - t} ms)`)
return ipCache.value

View File

@ -26,7 +26,7 @@ module.exports = class DNSOverHTTPS extends BaseDNS {
}
return ret
} catch (err) {
log.info('dns query error', hostname, err.message)
log.info('dns query error', hostname, this.dnsServer, err.message)
return []
}
}

View File

@ -1,12 +1,13 @@
const dnstls = require('dns-over-tls')
const BaseDNS = require('./base')
const log = require('../../utils/util.log')
module.exports = class DNSOverTLS extends BaseDNS {
async _lookup (hostname) {
const { answers } = await dnstls.query(hostname)
const answer = answers.find(answer => answer.type === 'A' && answer.class === 'IN')
log.info('dns lookup', hostname, answer)
if (answer) {
return answer.data
}

View File

@ -10,7 +10,6 @@ module.exports = {
for (const bk of interceptOpt.backup) {
backup.push(bk)
}
const key = interceptOpt.key
const count = RequestCounter.getOrCreate(key, backup)
if (count.value == null) {

View File

@ -109,8 +109,10 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
dns.lookup(hostname).then(ip => {
isDnsIntercept = { dns, hostname, ip }
if (ip !== hostname) {
log.info(`request url :${url},use ip :${ip}`)
callback(null, ip, 4)
} else {
log.info(`request url :${url},use hostname :${hostname}`)
defaultDns.lookup(hostname, options, callback)
}
})

View File

@ -8,27 +8,27 @@ const dnsProviders = dns.initDNS({
},
usa: {
type: 'https',
server: 'https://cloudflare-dns.com/dns-query',
server: 'https://1.1.1.1/dns-query',
cacheSize: 1000
}
})
// let hostname = 'www.yonsz.com'
// dnsProviders.usa.lookup(hostname)
const hostname0 = 'github.com'
dnsProviders.usa.lookup(hostname0)
dnsProviders.usa.lookup(hostname0)
dnsProviders.usa.lookup(hostname0)
// const hostname = 'api.github.com'
// dnsProviders.usa.lookup(hostname)
const hostname1 = 'api.github.com'
dnsProviders.usa.lookup(hostname1)
const hostname2 = 'hk.docmirror.cn'
dnsProviders.usa.lookup(hostname2)
const hostname3 = 'github.docmirror.cn'
dnsProviders.usa.lookup(hostname3)
const hostname4 = 'gh.docmirror.top'
dnsProviders.usa.lookup(hostname4)
const hostname5 = 'gh2.docmirror.top'
dnsProviders.usa.lookup(hostname5)
// const hostname1 = 'api.github.com'
// dnsProviders.usa.lookup(hostname1)
//
// const hostname2 = 'hk.docmirror.cn'
// dnsProviders.usa.lookup(hostname2)
// const hostname3 = 'github.docmirror.cn'
// dnsProviders.usa.lookup(hostname3)
// const hostname4 = 'gh.docmirror.top'
// dnsProviders.usa.lookup(hostname4)
// const hostname5 = 'gh2.docmirror.top'
// dnsProviders.usa.lookup(hostname5)