optimize: 优化 dnsLookup.js 的日志。
parent
599bacbca8
commit
b2b6d14aba
|
@ -42,18 +42,17 @@ module.exports = function createConnectHandler (sslConnectInterceptor, middlewar
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
log.info(`未匹配到任何 sslConnectInterceptors,不拦截请求,直接连接目标服务器: ${hostname}:${port}`)
|
log.info(`未匹配到任何 sslConnectInterceptors,不拦截请求,直接连接目标服务器: ${hostname}:${port}`)
|
||||||
connect(req, cltSocket, head, hostname, port, dnsConfig/*, sniRegexpMap */)
|
connect(req, cltSocket, head, hostname, port, dnsConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function connect (req, cltSocket, head, hostname, port, dnsConfig/* , sniRegexpMap */) {
|
function connect (req, cltSocket, head, hostname, port, dnsConfig) {
|
||||||
// tunneling https
|
// tunneling https
|
||||||
// log.info('connect:', hostname, port)
|
// log.info('connect:', hostname, port)
|
||||||
const start = new Date()
|
const start = new Date()
|
||||||
const isDnsIntercept = {}
|
const isDnsIntercept = {}
|
||||||
const hostport = `${hostname}:${port}`
|
const hostport = `${hostname}:${port}`
|
||||||
// const replaceSni = matchUtil.matchHostname(sniRegexpMap, hostname, 'sni')
|
|
||||||
try {
|
try {
|
||||||
const options = {
|
const options = {
|
||||||
port,
|
port,
|
||||||
|
|
|
@ -4,16 +4,18 @@ const defaultDns = require('dns')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createLookupFunc: function (dns, action, target, isDnsIntercept) {
|
createLookupFunc: function (dns, action, target, isDnsIntercept) {
|
||||||
|
target = target ? (', target: ' + target) : ''
|
||||||
|
|
||||||
return (hostname, options, callback) => {
|
return (hostname, options, callback) => {
|
||||||
const tester = speedTest.getSpeedTester(hostname)
|
const tester = speedTest.getSpeedTester(hostname)
|
||||||
if (tester && tester.ready) {
|
if (tester && tester.ready) {
|
||||||
const aliveIpObj = tester.pickFastAliveIpObj()
|
const aliveIpObj = tester.pickFastAliveIpObj()
|
||||||
if (aliveIpObj) {
|
if (aliveIpObj) {
|
||||||
log.info(`----- ${action}: ${target}, use alive ip from dns '${aliveIpObj.dns}': ${aliveIpObj.host} -----`)
|
log.info(`----- ${action}: ${hostname}, use alive ip from dns '${aliveIpObj.dns}': ${aliveIpObj.host}${target} -----`)
|
||||||
callback(null, aliveIpObj.host, 4)
|
callback(null, aliveIpObj.host, 4)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
log.info(`----- ${action}: ${target}, no alive ip, tester:`, tester)
|
log.info(`----- ${action}: ${hostname}, no alive ip${target}, tester:`, tester)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dns.lookup(hostname).then(ip => {
|
dns.lookup(hostname).then(ip => {
|
||||||
|
@ -38,16 +40,16 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isTestFailedIp === false) {
|
if (isTestFailedIp === false) {
|
||||||
log.info(`----- ${action}: ${target}, use ip from dns '${dns.name}': ${ip} -----`)
|
log.info(`----- ${action}: ${hostname}, use ip from dns '${dns.name}': ${ip}${target} -----`)
|
||||||
callback(null, ip, 4)
|
callback(null, ip, 4)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
// 使用默认dns
|
// 使用默认dns
|
||||||
log.info(`----- ${action}: ${target}, use hostname by default DNS: ${hostname}, skip test failed ip from dns '${dns.name}: ${ip}', options:`, options)
|
log.info(`----- ${action}: ${hostname}, use hostname by default DNS: ${hostname}, skip test failed ip from dns '${dns.name}: ${ip}'${target}, options:`, options)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 使用默认dns
|
// 使用默认dns
|
||||||
log.info(`----- ${action}: ${target}, use hostname by default DNS: ${hostname}, options:`, options, ', dns:', dns)
|
log.info(`----- ${action}: ${hostname}, use hostname by default DNS: ${hostname}${target}, options:`, options, ', dns:', dns)
|
||||||
}
|
}
|
||||||
defaultDns.lookup(hostname, options, callback)
|
defaultDns.lookup(hostname, options, callback)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue