relay.js
function TorRelay(opts) {
    var self = this;
    opts = opts || {};

    if (!opts.hasOwnProperty('autoCredentials')) {
        opts.autoCredentials = true;
    }
    this.dataDirectory = opts.dataDirectory || null;

    if (!opts.hasOwnProperty('cleanUpOnExit')) {
        this.cleanUpOnExit = true;
    } else {
        this.cleanUpOnExit = opts.cleanUpOnExit;
    }
    if (opts.hasOwnProperty('retries')) {
        this.retries = opts.retries;
    }
    if (opts.hasOwnProperty('timeout')) {
        this.timeout = opts.timeout;
    }

    /**
     * Configuration of the services
     * @type {{control: {password: (string|*), port: (string|*|null)}, socks: {port: (string|*|null)}}}
     */
    this.service = {
        control: {
            password:  opts.controlPassword || (opts.autoCredentials ? createCredential() : null),
            port: opts.controlPort || null
        },
        socks: {
            username: opts.socksUsername || null,
            password: opts.socksPassword || null,
            port: opts.socksPort || null
        }
    };

    if (!opts.hasOwnProperty('socksUsername') && opts.autoCredentials) {
        this.service.socks.username = createCredential();
    }
    if (!opts.hasOwnProperty('socksPassword') && opts.autoCredentials) {
        this.service.socks.password = createCredential();
    }


    process.on('exit', function () {
        if (self.process && self.cleanUpOnExit) {
            console.error('Killing tor sub-process');
            self.process.kill('SIGTERM');
            self.process.kill('SIGKILL');
        }
    });

}
function TorRelay(opts) {
    var self = this;
    opts = opts || {};

    if (!opts.hasOwnProperty('autoCredentials')) {
        opts.autoCredentials = true;
    }
    this.dataDirectory = opts.dataDirectory || null;

    if (!opts.hasOwnProperty('cleanUpOnExit')) {
        this.cleanUpOnExit = true;
    } else {
        this.cleanUpOnExit = opts.cleanUpOnExit;
    }
    if (opts.hasOwnProperty('retries')) {
        this.retries = opts.retries;
    }
    if (opts.hasOwnProperty('timeout')) {
        this.timeout = opts.timeout;
    }

    /**
     * Configuration of the services
     * @type {{control: {password: (string|*), port: (string|*|null)}, socks: {port: (string|*|null)}}}
     */
    this.service = {
        control: {
            password:  opts.controlPassword || (opts.autoCredentials ? createCredential() : null),
            port: opts.controlPort || null
        },
        socks: {
            username: opts.socksUsername || null,
            password: opts.socksPassword || null,
            port: opts.socksPort || null
        }
    };

    if (!opts.hasOwnProperty('socksUsername') && opts.autoCredentials) {
        this.service.socks.username = createCredential();
    }
    if (!opts.hasOwnProperty('socksPassword') && opts.autoCredentials) {
        this.service.socks.password = createCredential();
    }


    process.on('exit', function () {
        if (self.process && self.cleanUpOnExit) {
            console.error('Killing tor sub-process');
            self.process.kill('SIGTERM');
            self.process.kill('SIGKILL');
        }
    });

}
function TorRelay ( opts ) { var self = this ; opts = opts || { } ; if ( ! opts . hasOwnProperty ( 'autoCredentials' ) ) { opts . autoCredentials = true ; } this . dataDirectory = opts . dataDirectory || null ; if ( ! opts . hasOwnProperty ( 'cleanUpOnExit' ) ) { this . cleanUpOnExit = true ; } else { this . cleanUpOnExit = opts . cleanUpOnExit ; } if ( opts . hasOwnProperty ( 'retries' ) ) { this . retries = opts . retries ; } if ( opts . hasOwnProperty ( 'timeout' ) ) { this . timeout = opts . timeout ; } /**
     * Configuration of the services
     * @type {{control: {password: (string|*), port: (string|*|null)}, socks: {port: (string|*|null)}}}
     */ this . service = { control : { password : opts . controlPassword || ( opts . autoCredentials ? createCredential ( ) : null ) , port : opts . controlPort || null } , socks : { username : opts . socksUsername || null , password : opts . socksPassword || null , port : opts . socksPort || null } } ; if ( ! opts . hasOwnProperty ( 'socksUsername' ) && opts . autoCredentials ) { this . service . socks . username = createCredential ( ) ; } if ( ! opts . hasOwnProperty ( 'socksPassword' ) && opts . autoCredentials ) { this . service . socks . password = createCredential ( ) ; } process . on ( 'exit' , function ( ) { if ( self . process && self . cleanUpOnExit ) { console . error ( 'Killing tor sub-process' ) ; self . process . kill ( 'SIGTERM' ) ; self . process . kill ( 'SIGKILL' ) ; } } ) ; }
Relay class for tor relays
@param {{}} [opts] - Options for relay
@param {boolean} [opts.autoCredentials] - Automatically create credentials
@param {boolean} [opts.cleanUpOnExit=true] - Remove temporary dir an close unused child-processes on exit
@param {string} [opts.dataDirectory] - Specify a directory to store tor data (default is an auto-created temporary dir, this will be removed if cleanUpOnExit is true)
@param {string} [opts.controlPassword] - Password for tor control (default is a random password)
@param {string} [opts.controlPort] - Port for tor control (default is a random free port)
@param {number} [opts.retries=5] - Number of retries to find a circuit
@param {string} [opts.socksPort] - Port for socks5 (default is a random free port)
@param {string} [opts.socksUsername] - Username for socks5 (default is a random like a password)
@param {string} [opts.socksPassword] - Password for socks5 (default is a random password)
@param {number} [opts.timeout=60000] - Timeout for finding a circuit
@constructor
Relay class for tor relays