WIP v0.20.x: switch to proxy-packer v2.x and comment readable
This commit is contained in:
parent
017b14351a
commit
78407f2a3e
|
@ -56,6 +56,7 @@ function _connect(state) {
|
||||||
conn.tunnelWritten = 0;
|
conn.tunnelWritten = 0;
|
||||||
|
|
||||||
conn.on('data', function onLocalData(chunk) {
|
conn.on('data', function onLocalData(chunk) {
|
||||||
|
//var chunk = conn.read();
|
||||||
if (conn.tunnelClosing) {
|
if (conn.tunnelClosing) {
|
||||||
console.warn("[onLocalData] received data for '"+cid+"' over socket after connection was ended");
|
console.warn("[onLocalData] received data for '"+cid+"' over socket after connection was ended");
|
||||||
return;
|
return;
|
||||||
|
@ -67,8 +68,10 @@ function _connect(state) {
|
||||||
// down the data we are getting to send over. We also want to pause all active connections
|
// down the data we are getting to send over. We also want to pause all active connections
|
||||||
// if any connections are paused to make things more fair so one connection doesn't get
|
// if any connections are paused to make things more fair so one connection doesn't get
|
||||||
// stuff waiting for all other connections to finish because it tried writing near the border.
|
// stuff waiting for all other connections to finish because it tried writing near the border.
|
||||||
var bufSize = wsHandlers.sendMessage(Packer.pack(tun, chunk));
|
var bufSize = wsHandlers.sendMessage(Packer.packHeader(tun, chunk));
|
||||||
if (pausedClients.length || bufSize > 1024*1024) {
|
// Sending 2 messages instead of copying the buffer
|
||||||
|
var bufSize2 = wsHandlers.sendMessage(chunk);
|
||||||
|
if (pausedClients.length || (bufSize + bufSize2) > 1024*1024) {
|
||||||
// console.log('[onLocalData] paused connection', cid, 'to allow websocket to catch up');
|
// console.log('[onLocalData] paused connection', cid, 'to allow websocket to catch up');
|
||||||
conn.pause();
|
conn.pause();
|
||||||
pausedClients.push(conn);
|
pausedClients.push(conn);
|
||||||
|
@ -80,14 +83,15 @@ function _connect(state) {
|
||||||
console.info("[onLocalEnd] connection '" + cid + "' ended, will probably close soon");
|
console.info("[onLocalEnd] connection '" + cid + "' ended, will probably close soon");
|
||||||
conn.tunnelClosing = true;
|
conn.tunnelClosing = true;
|
||||||
if (!sentEnd) {
|
if (!sentEnd) {
|
||||||
wsHandlers.sendMessage(Packer.pack(tun, null, 'end'));
|
wsHandlers.sendMessage(Packer.packHeader(tun, null, 'end'));
|
||||||
sentEnd = true;
|
sentEnd = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
conn.on('error', function onLocalError(err) {
|
conn.on('error', function onLocalError(err) {
|
||||||
console.info("[onLocalError] connection '" + cid + "' errored:", err);
|
console.info("[onLocalError] connection '" + cid + "' errored:", err);
|
||||||
if (!sentEnd) {
|
if (!sentEnd) {
|
||||||
wsHandlers.sendMessage(Packer.pack(tun, {message: err.message, code: err.code}, 'error'));
|
var packBody = true;
|
||||||
|
wsHandlers.sendMessage(Packer.packHeader(tun, {message: err.message, code: err.code}, 'error', packBody));
|
||||||
sentEnd = true;
|
sentEnd = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -95,7 +99,7 @@ function _connect(state) {
|
||||||
delete localclients[cid];
|
delete localclients[cid];
|
||||||
console.log('[onLocalClose] closed "' + cid + '" read:'+conn.tunnelRead+', wrote:'+conn.tunnelWritten+' (' + clientHandlers.count() + ' clients)');
|
console.log('[onLocalClose] closed "' + cid + '" read:'+conn.tunnelRead+', wrote:'+conn.tunnelWritten+' (' + clientHandlers.count() + ' clients)');
|
||||||
if (!sentEnd) {
|
if (!sentEnd) {
|
||||||
wsHandlers.sendMessage(Packer.pack(tun, null, hadErr && 'error' || 'end'));
|
wsHandlers.sendMessage(Packer.packHeader(tun, null, hadErr && 'error' || 'end'));
|
||||||
sentEnd = true;
|
sentEnd = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -119,11 +123,13 @@ function _connect(state) {
|
||||||
conn.tunnelRead += opts.data.byteLength;
|
conn.tunnelRead += opts.data.byteLength;
|
||||||
|
|
||||||
if (!conn.remotePaused && conn.bufferSize > 1024*1024) {
|
if (!conn.remotePaused && conn.bufferSize > 1024*1024) {
|
||||||
wsHandlers.sendMessage(Packer.pack(opts, conn.tunnelRead, 'pause'));
|
var packBody = true;
|
||||||
|
wsHandlers.sendMessage(Packer.packHeader(opts, conn.tunnelRead, 'pause', packBody));
|
||||||
conn.remotePaused = true;
|
conn.remotePaused = true;
|
||||||
|
|
||||||
conn.once('drain', function () {
|
conn.once('drain', function () {
|
||||||
wsHandlers.sendMessage(Packer.pack(opts, conn.tunnelRead, 'resume'));
|
var packBody = true;
|
||||||
|
wsHandlers.sendMessage(Packer.packHeader(opts, conn.tunnelRead, 'resume', packBody));
|
||||||
conn.remotePaused = false;
|
conn.remotePaused = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -188,7 +194,8 @@ function _connect(state) {
|
||||||
var cmd = [id, name].concat(Array.prototype.slice.call(arguments, 1));
|
var cmd = [id, name].concat(Array.prototype.slice.call(arguments, 1));
|
||||||
if (state.debug) { console.log('[DEBUG] command sending', cmd); }
|
if (state.debug) { console.log('[DEBUG] command sending', cmd); }
|
||||||
|
|
||||||
wsHandlers.sendMessage(Packer.pack(null, cmd, 'control'));
|
var packBody = true;
|
||||||
|
wsHandlers.sendMessage(Packer.packHeader(null, cmd, 'control', packBody));
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (pendingCommands[id]) {
|
if (pendingCommands[id]) {
|
||||||
console.warn('command', name, id, 'timed out');
|
console.warn('command', name, id, 'timed out');
|
||||||
|
@ -294,7 +301,8 @@ function _connect(state) {
|
||||||
err = { message: 'unknown command "'+cmd[1]+'"', code: 'E_UNKNOWN_COMMAND' };
|
err = { message: 'unknown command "'+cmd[1]+'"', code: 'E_UNKNOWN_COMMAND' };
|
||||||
}
|
}
|
||||||
|
|
||||||
wsHandlers.sendMessage(Packer.pack(null, [-cmd[0], err], 'control'));
|
var packBody = true;
|
||||||
|
wsHandlers.sendMessage(Packer.packHeader(null, [-cmd[0], err], 'control', packBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
, onmessage: function (tun) {
|
, onmessage: function (tun) {
|
||||||
|
@ -338,7 +346,8 @@ function _connect(state) {
|
||||||
console.log('[TunnelPause] remote tried pausing finished connection', cid);
|
console.log('[TunnelPause] remote tried pausing finished connection', cid);
|
||||||
// Often we have enough latency that we've finished sending before we're told to pause, so
|
// Often we have enough latency that we've finished sending before we're told to pause, so
|
||||||
// don't worry about sending back errors, since we won't be sending data over anyway.
|
// don't worry about sending back errors, since we won't be sending data over anyway.
|
||||||
// wsHandlers.sendMessage(Packer.pack(opts, {message: 'no matching connection', code: 'E_NO_CONN'}, 'error'));
|
// var packBody = true;
|
||||||
|
// wsHandlers.sendMessage(Packer.packHeader(opts, {message: 'no matching connection', code: 'E_NO_CONN'}, 'error', packBody));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
, onresume: function (opts) {
|
, onresume: function (opts) {
|
||||||
|
@ -349,7 +358,8 @@ function _connect(state) {
|
||||||
localclients[cid].resume();
|
localclients[cid].resume();
|
||||||
} else {
|
} else {
|
||||||
console.log('[TunnelResume] remote tried resuming finished connection', cid);
|
console.log('[TunnelResume] remote tried resuming finished connection', cid);
|
||||||
// wsHandlers.sendMessage(Packer.pack(opts, {message: 'no matching connection', code: 'E_NO_CONN'}, 'error'));
|
// var packBody = true;
|
||||||
|
// wsHandlers.sendMessage(Packer.packHeader(opts, {message: 'no matching connection', code: 'E_NO_CONN'}, 'error', packBody));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +376,7 @@ function _connect(state) {
|
||||||
|
|
||||||
, _onConnectError: function (cid, opts, err) {
|
, _onConnectError: function (cid, opts, err) {
|
||||||
console.info("[_onConnectError] opening '" + cid + "' failed because " + err.message);
|
console.info("[_onConnectError] opening '" + cid + "' failed because " + err.message);
|
||||||
wsHandlers.sendMessage(Packer.pack(opts, null, 'error'));
|
wsHandlers.sendMessage(Packer.packHeader(opts, null, 'error'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ module.exports = function (pkg) {
|
||||||
https.get(url, function (resp) {
|
https.get(url, function (resp) {
|
||||||
var str = '';
|
var str = '';
|
||||||
resp.on('data', function (chunk) {
|
resp.on('data', function (chunk) {
|
||||||
|
//var chunk = conn.read();
|
||||||
str += chunk.toString('utf8');
|
str += chunk.toString('utf8');
|
||||||
});
|
});
|
||||||
resp.on('end', function () {
|
resp.on('end', function () {
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
"js-yaml": "^3.11.0",
|
"js-yaml": "^3.11.0",
|
||||||
"jsonwebtoken": "^7.1.9",
|
"jsonwebtoken": "^7.1.9",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"proxy-packer": "^1.4.3",
|
"proxy-packer": "^2.0.0",
|
||||||
"ps-list": "^5.0.0",
|
"ps-list": "^5.0.0",
|
||||||
"recase": "^1.0.4",
|
"recase": "^1.0.4",
|
||||||
"redirect-https": "^1.1.5",
|
"redirect-https": "^1.1.5",
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
"serve-static": "^1.13.2",
|
"serve-static": "^1.13.2",
|
||||||
"sni": "^1.0.0",
|
"sni": "^1.0.0",
|
||||||
"socket-pair": "^1.0.3",
|
"socket-pair": "^1.0.3",
|
||||||
"ws": "^2.2.3"
|
"ws": "^2.3.1"
|
||||||
},
|
},
|
||||||
"trulyOptionalDependencies": {
|
"trulyOptionalDependencies": {
|
||||||
"bluebird": "^3.5.1"
|
"bluebird": "^3.5.1"
|
||||||
|
|
Loading…
Reference in New Issue