From 12c00baecc49da456d27b9149c9457d7f53f52ec Mon Sep 17 00:00:00 2001 From: Zachary Boyd Date: Wed, 9 May 2018 21:30:51 -0700 Subject: [PATCH] Updates README to reflect changes. Uses instance name when reporting process info --- README.md | 13 +++++++++---- src/TorProcess.js | 8 ++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1b12598..447baba 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The following command line switches and their environment variable equivalents a |-h, --httpPort |HTTP_PORT |Port the HTTP proxy will bind to| |-l, --logLevel |LOG_LEVEL |Log level (defaults to "info") set to "null" to disable logging. To see a log of all network traffic set logLevel to "verbose"| |-p, --parentDataDirectory|PARENT_DATA_DIRECTORY |Parent directory that will contain the data directories for the instances| -|-b, --loadBalanceMethod|LOAD_BALANCE_METHOD|Method that will be used to sort the instances between each request. Currently supports "round_robin" and "weighted".| +|-b, --loadBalanceMethod|LOAD_BALANCE_METHOD |Method that will be used to sort the instances between each request. Currently supports "round_robin" and "weighted".| For example: `tor-router -j 3 -s 9050` would start the proxy with 3 tor instances and listen for SOCKS connections on 9050. ## Configuration @@ -60,19 +60,24 @@ Using the configuration file you can set a default configuration for all Tor ins } ``` -You can also specify a configuration for individual instances by setting the "instances" field to an array instead of an integer +You can also specify a configuration for individual instances by setting the "instances" field to an array instead of an integer. + +Instances can optionally be assigned name and a weight. If the `loadBalanceMethod` config variable is set to "weighted" the weight field will determine how frequently the instance is used. If the instance is assigned a name the data directory will be preserved when the process is killed saving time when Tor is restarted. ``` { + "loadBalanceMethod": "weighted", "instances": [ { + "Name": "instance-1" + "Weight": 10, "Config": { - "DataDirectory": "/tmp/my-tor-dir1" } }, { + "Name": "instance-2", + "Weight": 5, "Config": { - "DataDirectory": "/tmp/my-tor-dir2" } } ] diff --git a/src/TorProcess.js b/src/TorProcess.js index 0fd88e4..f31bf36 100644 --- a/src/TorProcess.js +++ b/src/TorProcess.js @@ -29,10 +29,14 @@ class TorProcess extends EventEmitter { } new_ip() { - this.logger.info(`[tor-${this.process.pid}]: has requested a new identity`); + this.logger.info(`[tor-${this.instance_name}]: has requested a new identity`); this.process.kill('SIGHUP'); } + get instance_name() { + return (this.definition && this.definition.Name) || this.process.pid; + } + get dns_port() { return this._dns_port || null; } @@ -88,7 +92,7 @@ class TorProcess extends EventEmitter { this.once('ready', () => { this.ready = true; - this.logger && this.logger.info(`[tor-${tor.pid}]: tor is ready`); + this.logger && this.logger.info(`[tor-${this.instance_name}]: tor is ready`); }); tor.stdout.on('data', (data) => {