update logger
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
const VERSION = '0.1.7';
|
const VERSION = '0.1.8';
|
||||||
|
|
||||||
module.exports.VERSION = VERSION;
|
module.exports.VERSION = VERSION;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "shadowsocks-over-websocket",
|
"name": "shadowsocks-over-websocket",
|
||||||
"version": "0.1.7",
|
"version": "0.1.8",
|
||||||
"description": "A fast tunnel proxy that helps you bypass firewalls",
|
"description": "A fast tunnel proxy that helps you bypass firewalls",
|
||||||
"main": "tcprelay.js",
|
"main": "tcprelay.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
32
tcprelay.js
32
tcprelay.js
@@ -3,6 +3,7 @@ const path = require('path');
|
|||||||
const log4js = require('log4js');
|
const log4js = require('log4js');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
const Encryptor = require('shadowsocks/lib/shadowsocks/encrypt').Encryptor;
|
const Encryptor = require('shadowsocks/lib/shadowsocks/encrypt').Encryptor;
|
||||||
|
const WSErrorCode = require('ws/lib/ErrorCodes');
|
||||||
|
|
||||||
const MAX_CONNECTIONS = 50000;
|
const MAX_CONNECTIONS = 50000;
|
||||||
|
|
||||||
@@ -265,8 +266,14 @@ TCPRelay.prototype.handleConnectionByServer = function(connection) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
targetConnection.setKeepAlive(true, 5000);
|
|
||||||
targetConnection.on('end', function() {
|
targetConnection.on('end', function() {
|
||||||
|
logger.info(`[${connectionId}]: end event of target connection has been triggered`);
|
||||||
|
stage = STAGE_DESTROYED;
|
||||||
|
connection.close();
|
||||||
|
});
|
||||||
|
targetConnection.on('close', function(hadError) {
|
||||||
|
logger.info(`[${connectionId}]: close event[had error = ${hadError}] of target connection has been triggered`);
|
||||||
|
stage = STAGE_DESTROYED;
|
||||||
connection.close();
|
connection.close();
|
||||||
});
|
});
|
||||||
targetConnection.on('error', function(error) {
|
targetConnection.on('error', function(error) {
|
||||||
@@ -292,11 +299,8 @@ TCPRelay.prototype.handleConnectionByServer = function(connection) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connection.on('ping', function() {
|
connection.on('close', function(code, reason) {
|
||||||
return connection.pong('', false, true);
|
logger.info(`[${connectionId}]: close event[code = '${WSErrorCode[code]}'] of local connection has been triggered`);
|
||||||
});
|
|
||||||
connection.on('close', function(hadError) {
|
|
||||||
logger.info(`[${connectionId}]: close event[had error = ${hadError}] of local connection has been triggered`);
|
|
||||||
connections[connectionId] = null;
|
connections[connectionId] = null;
|
||||||
targetConnection && targetConnection.destroy();
|
targetConnection && targetConnection.destroy();
|
||||||
});
|
});
|
||||||
@@ -322,14 +326,14 @@ TCPRelay.prototype.handleConnectionByLocal = function(connection) {
|
|||||||
|
|
||||||
var stage = STAGE_INIT;
|
var stage = STAGE_INIT;
|
||||||
var connectionId = (globalConnectionId++) % MAX_CONNECTIONS;
|
var connectionId = (globalConnectionId++) % MAX_CONNECTIONS;
|
||||||
var serverConnection, cmd, addressHeader, ping;
|
var serverConnection, cmd, addressHeader;
|
||||||
|
|
||||||
var canWriteToLocalConnection = true;
|
var canWriteToLocalConnection = true;
|
||||||
var dataCache = [];
|
var dataCache = [];
|
||||||
|
|
||||||
logger.info(`[${connectionId}]: accept connection from client`);
|
logger.info(`[${connectionId}]: accept connection from client`);
|
||||||
connections[connectionId] = connection;
|
connections[connectionId] = connection;
|
||||||
connection.setKeepAlive(true, 10000);
|
connection.setKeepAlive(false);
|
||||||
connection.on('data', function(data) {
|
connection.on('data', function(data) {
|
||||||
logger.debug(`[${connectionId}]: read data[length = ${data.length}] from client connection at stage[${STAGE[stage]}]`);
|
logger.debug(`[${connectionId}]: read data[length = ${data.length}] from client connection at stage[${STAGE[stage]}]`);
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
@@ -382,10 +386,6 @@ TCPRelay.prototype.handleConnectionByLocal = function(connection) {
|
|||||||
dataCache = null;
|
dataCache = null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ping = setInterval(function() {
|
|
||||||
serverConnection.ping('', false, true);
|
|
||||||
}, 30000);
|
|
||||||
});
|
});
|
||||||
serverConnection.on('message', function(data) {
|
serverConnection.on('message', function(data) {
|
||||||
logger.debug(`[${connectionId}]: read data[length = ${data.length}] from server connection`);
|
logger.debug(`[${connectionId}]: read data[length = ${data.length}] from server connection`);
|
||||||
@@ -394,14 +394,12 @@ TCPRelay.prototype.handleConnectionByLocal = function(connection) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
serverConnection.on('error', function(error) {
|
serverConnection.on('error', function(error) {
|
||||||
ping && clearInterval(ping);
|
|
||||||
logger.error(`[${connectionId}]: an error of server connection occured`, error);
|
logger.error(`[${connectionId}]: an error of server connection occured`, error);
|
||||||
stage = STAGE_DESTROYED;
|
stage = STAGE_DESTROYED;
|
||||||
connection.end();
|
connection.end();
|
||||||
});
|
});
|
||||||
serverConnection.on('close', function() {
|
serverConnection.on('close', function(code, reason) {
|
||||||
logger.info(`[${connectionId}]: server connection is closed`);
|
logger.info(`[${connectionId}]: close event[code = '${WSErrorCode[code]}'] of server connection has been triggered`);
|
||||||
ping && clearInterval(ping);
|
|
||||||
stage = STAGE_DESTROYED;
|
stage = STAGE_DESTROYED;
|
||||||
connection.end();
|
connection.end();
|
||||||
});
|
});
|
||||||
@@ -425,8 +423,8 @@ TCPRelay.prototype.handleConnectionByLocal = function(connection) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
connection.on('end', function() {
|
connection.on('end', function() {
|
||||||
stage = STAGE_DESTROYED;
|
|
||||||
logger.info(`[${connectionId}]: end event of client connection has been triggered`);
|
logger.info(`[${connectionId}]: end event of client connection has been triggered`);
|
||||||
|
stage = STAGE_DESTROYED;
|
||||||
});
|
});
|
||||||
connection.on('close', function(hadError) {
|
connection.on('close', function(hadError) {
|
||||||
logger.info(`[${connectionId}]: close event[had error = ${hadError}] of client connection has been triggered`);
|
logger.info(`[${connectionId}]: close event[had error = ${hadError}] of client connection has been triggered`);
|
||||||
|
|||||||
Reference in New Issue
Block a user