From 45ad20a1b6394241f6f9f2c80170041c55f9077a Mon Sep 17 00:00:00 2001 From: Micooz Date: Thu, 15 Feb 2018 18:50:55 +0800 Subject: [PATCH] bin,core: remove workers --- bin/bootstrap.js | 15 +++------------ bin/init.js | 4 ---- src/core/hub.js | 11 ++++------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/bin/bootstrap.js b/bin/bootstrap.js index e07b6da..d24bb3b 100644 --- a/bin/bootstrap.js +++ b/bin/bootstrap.js @@ -1,4 +1,3 @@ -const cluster = require('cluster'); const fs = require('fs'); /** @@ -21,17 +20,9 @@ module.exports = function bootstrap(configPath, {Hub, Config}) { try { const config = obtainConfig(configPath); Config.test(config); - const workers = config.workers; - if (cluster.isMaster && workers > 0) { - for (let i = 0; i < workers; ++i) { - cluster.fork(); - } - console.log(`[bootstrap] started ${workers} workers`); - } else { - const hub = new Hub(config); - hub.run(); - process.on('SIGINT', () => hub.terminate(() => process.exit(0))); - } + const hub = new Hub(config); + hub.run(); + process.on('SIGINT', () => hub.terminate(() => process.exit(0))); } catch (err) { console.error(err); process.exit(-1); diff --git a/bin/init.js b/bin/init.js index d7afdf5..37922d0 100644 --- a/bin/init.js +++ b/bin/init.js @@ -50,7 +50,6 @@ module.exports = function init({isMinimal, isOverwrite}) { 'dns': [], 'dns_expire': 3600, 'timeout': timeout, - 'workers': 0, 'log_path': 'bs-client.log', 'log_level': 'info', 'log_max_days': 30 @@ -63,7 +62,6 @@ module.exports = function init({isMinimal, isOverwrite}) { delete clientJson.dns; delete clientJson.dns_expire; delete clientJson.timeout; - delete clientJson.workers; delete clientJson.log_path; delete clientJson.log_level; delete clientJson.log_max_days; @@ -84,7 +82,6 @@ module.exports = function init({isMinimal, isOverwrite}) { 'dns_expire': 3600, 'timeout': timeout, 'redirect': '', - 'workers': 0, 'log_path': 'bs-server.log', 'log_level': 'info', 'log_max_days': 30 @@ -98,7 +95,6 @@ module.exports = function init({isMinimal, isOverwrite}) { delete serverJson.dns_expire; delete serverJson.timeout; delete serverJson.redirect; - delete serverJson.workers; delete serverJson.log_path; delete serverJson.log_level; delete serverJson.log_max_days; diff --git a/src/core/hub.js b/src/core/hub.js index 4a86c68..db8df49 100644 --- a/src/core/hub.js +++ b/src/core/hub.js @@ -1,4 +1,3 @@ -import cluster from 'cluster'; import dgram from 'dgram'; import net from 'net'; import tls from 'tls'; @@ -22,8 +21,6 @@ function makeConnID() { export class Hub { - _wkId = cluster.worker ? cluster.worker.id : 0; - _tcpServer = null; _udpServer = null; @@ -57,7 +54,7 @@ export class Hub { this._tcpRelays.clear(); // server this._tcpServer.close(); - logger.info(`[hub-${this._wkId}] shutdown`); + logger.info(`[hub] shutdown`); // udp server this._udpServer.close(); typeof callback === 'function' && callback(); @@ -111,7 +108,7 @@ export class Hub { server.on('proxyConnection', this._onConnection); server.listen(address, () => { const service = `${this._config.local_protocol}://${this._config.local_host}:${this._config.local_port}`; - logger.info(`[hub-${this._wkId}] blinksocks client is running at ${service}`); + logger.info(`[hub] blinksocks client is running at ${service}`); resolve(server); }); }); @@ -125,7 +122,7 @@ export class Hub { }; const onListening = (server) => { const service = `${this._config.local_protocol}://${this._config.local_host}:${this._config.local_port}`; - logger.info(`[hub-${this._wkId}] blinksocks server is running at ${service}`); + logger.info(`[hub] blinksocks server is running at ${service}`); resolve(server); }; switch (this._config.local_protocol) { @@ -223,7 +220,7 @@ export class Hub { server.bind({address: this._config.local_host, port: this._config.local_port}, () => { const service = `udp://${this._config.local_host}:${this._config.local_port}`; - logger.info(`[hub-${this._wkId}] blinksocks udp server is running at ${service}`); + logger.info(`[hub] blinksocks udp server is running at ${service}`); resolve(server); }); });