mirror of
https://github.com/avwo/whistle.git
synced 2026-10-26 03:53:03 +08:00
refactor: refine code
This commit is contained in:
+13
-8
@@ -30,8 +30,6 @@ var getSNIServer = ca.getSNIServer;
|
||||
var LOCALHOST = '127.0.0.1';
|
||||
var tunnelTmplData = new LRU({max: 3000, maxAge: 30000});
|
||||
var TIMEOUT = 5000;
|
||||
var LOCAL_TIMEOUT = 3000;
|
||||
var AUTH_TIMEOUT = 3000;
|
||||
var CONN_TIMEOUT = 60000;
|
||||
var X_RE = /^x/;
|
||||
var proxy, server;
|
||||
@@ -810,8 +808,9 @@ module.exports = function(socket, hostname, next, isWebPort) {
|
||||
socket.on('end', request);
|
||||
var clientIp = socket.clientIp;
|
||||
var clientPort = socket.clientPort;
|
||||
var timeout = isWebPort ? null : (util.isLocalAddress(clientIp) ? LOCAL_TIMEOUT : TIMEOUT);
|
||||
timer = timeout && setTimeout(request, timeout);
|
||||
if (!isWebPort) {
|
||||
timer = setTimeout(request, TIMEOUT);
|
||||
}
|
||||
function request(chunk) {
|
||||
clearTimeout(timer);
|
||||
headersStr = chunk && chunk.toString();
|
||||
@@ -848,10 +847,16 @@ module.exports = function(socket, hostname, next, isWebPort) {
|
||||
} else if (chunk[0] != 22) {
|
||||
next(chunk);
|
||||
} else {
|
||||
var domain = hostname && getDomain(hostname);
|
||||
var recieveData, authTimer;
|
||||
|
||||
var useSNI = (!domain || !serverAgent.existsServer(domain)) && checkSNI(chunk);
|
||||
var useSNI = checkSNI(chunk);
|
||||
var domain = useSNI || domain;
|
||||
if (!domain) {
|
||||
return next(chunk);
|
||||
}
|
||||
domain = getDomain(domain);
|
||||
if (serverAgent.existsServer(domain)) {
|
||||
useSNI = false;
|
||||
}
|
||||
socket.pause();
|
||||
var checkTimeout = function() {
|
||||
authTimer = setTimeout(function() {
|
||||
@@ -865,7 +870,7 @@ module.exports = function(socket, hostname, next, isWebPort) {
|
||||
} else {
|
||||
next(chunk);
|
||||
}
|
||||
}, AUTH_TIMEOUT);
|
||||
}, TIMEOUT);
|
||||
};
|
||||
var handleConnect = function(port) {
|
||||
util.connect({
|
||||
|
||||
Reference in New Issue
Block a user