optimize: 优化 dnsLookup.js 的日志。
parent
599bacbca8
commit
b2b6d14aba
|
@ -42,18 +42,17 @@ module.exports = function createConnectHandler (sslConnectInterceptor, middlewar
|
|||
})
|
||||
} else {
|
||||
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
|
||||
// log.info('connect:', hostname, port)
|
||||
const start = new Date()
|
||||
const isDnsIntercept = {}
|
||||
const hostport = `${hostname}:${port}`
|
||||
// const replaceSni = matchUtil.matchHostname(sniRegexpMap, hostname, 'sni')
|
||||
try {
|
||||
const options = {
|
||||
port,
|
||||
|
|
|
@ -4,16 +4,18 @@ const defaultDns = require('dns')
|
|||
|
||||
module.exports = {
|
||||
createLookupFunc: function (dns, action, target, isDnsIntercept) {
|
||||
target = target ? (', target: ' + target) : ''
|
||||
|
||||
return (hostname, options, callback) => {
|
||||
const tester = speedTest.getSpeedTester(hostname)
|
||||
if (tester && tester.ready) {
|
||||
const aliveIpObj = tester.pickFastAliveIpObj()
|
||||
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)
|
||||
return
|
||||
} 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 => {
|
||||
|
@ -38,16 +40,16 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
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)
|
||||
return
|
||||
} else {
|
||||
// 使用默认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 {
|
||||
// 使用默认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)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue