Adds remove_by_name and new_identity_by_name methods to TorPool
This commit is contained in:
parent
5f8fde9039
commit
38bf4d7c6a
|
@ -40,15 +40,23 @@ Removes a number of instances
|
||||||
|
|
||||||
# removeInstanceAt(Integrer)
|
# removeInstanceAt(Integrer)
|
||||||
|
|
||||||
Remove a specific instance from the pool
|
Remove a specific instance from the pool by it's index
|
||||||
|
|
||||||
# newIps()
|
# removeInstanceByName(String)
|
||||||
|
|
||||||
Change the Tor Circuit on all instances
|
Remove a specific instance from the pool by it's name
|
||||||
|
|
||||||
# newIpAt(Integrer)
|
# newIdentites()
|
||||||
|
|
||||||
Change the Tor Circuit on a specific instance
|
Get new identites for all instances
|
||||||
|
|
||||||
|
# newIdentityAt(Integrer)
|
||||||
|
|
||||||
|
Get a new identity for a specific instance by it's index
|
||||||
|
|
||||||
|
# newIdentityByName(String)
|
||||||
|
|
||||||
|
Get a new identity for a specific instance by it's name
|
||||||
|
|
||||||
# nextInstance()
|
# nextInstance()
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,15 @@ class ControlServer {
|
||||||
});
|
});
|
||||||
}).bind(this) );
|
}).bind(this) );
|
||||||
|
|
||||||
|
server.expose('removeInstanceByName', (function (instance_name) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.torPool.remove_by_name(instance_name, (error) => {
|
||||||
|
if (error) reject(error);
|
||||||
|
else resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).bind(this) );
|
||||||
|
|
||||||
server.expose('newIdentites', (function() {
|
server.expose('newIdentites', (function() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.torPool.new_identites((error) => {
|
this.torPool.new_identites((error) => {
|
||||||
|
@ -79,6 +88,15 @@ class ControlServer {
|
||||||
});
|
});
|
||||||
}).bind(this));
|
}).bind(this));
|
||||||
|
|
||||||
|
server.expose('newIdentityByName', (function(name) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.torPool.new_identity_by_name(name, (error) => {
|
||||||
|
if (error) reject(error);
|
||||||
|
else resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).bind(this));
|
||||||
|
|
||||||
/* Begin Deprecated */
|
/* Begin Deprecated */
|
||||||
|
|
||||||
server.expose('newIps', (function() {
|
server.expose('newIps', (function() {
|
||||||
|
|
|
@ -97,6 +97,10 @@ class TorPool extends EventEmitter {
|
||||||
return this.add(instances, callback);
|
return this.add(instances, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance_by_name(name) {
|
||||||
|
return this.instances.filter((i) => i.definition.Name === name)[0];
|
||||||
|
}
|
||||||
|
|
||||||
remove(instances, callback) {
|
remove(instances, callback) {
|
||||||
let instances_to_remove = this._instances.splice(0, instances);
|
let instances_to_remove = this._instances.splice(0, instances);
|
||||||
async.each(instances_to_remove, (instance, next) => {
|
async.each(instances_to_remove, (instance, next) => {
|
||||||
|
@ -105,10 +109,15 @@ class TorPool extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_at(instance_index, callback) {
|
remove_at(instance_index, callback) {
|
||||||
let instance = this._instances.slice(instance_index, 1);
|
let instance = this._instances.splice(instance_index, 1);
|
||||||
instance.exit(() => {
|
instance.exit(callback);
|
||||||
callback();
|
}
|
||||||
});
|
|
||||||
|
remove_by_name(instance_name, callback) {
|
||||||
|
let instance = this.instance_by_name(instance_name);
|
||||||
|
if (!instance) return callback && callback(new Error(`Instance "${name}" not found`));
|
||||||
|
let instance_index = (this.instances.indexOf(instance));;
|
||||||
|
return this.remove_at(instance_index, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
next() {
|
next() {
|
||||||
|
@ -136,6 +145,12 @@ class TorPool extends EventEmitter {
|
||||||
this.instances[index].new_identity(callback);
|
this.instances[index].new_identity(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_identity_by_name(name, callback) {
|
||||||
|
let instance = this.instance_by_name(name);
|
||||||
|
if (!instance) return callback && callback(new Error(`Instance "${name}" not found`));
|
||||||
|
instance.new_identity(callback);
|
||||||
|
}
|
||||||
|
|
||||||
/* Begin Deprecated */
|
/* Begin Deprecated */
|
||||||
|
|
||||||
new_ips(callback) {
|
new_ips(callback) {
|
||||||
|
|
|
@ -68,6 +68,14 @@ class TorProcess extends EventEmitter {
|
||||||
return this._controller || null;
|
return this._controller || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getConfig(callback) {
|
||||||
|
if (!this.controller) {
|
||||||
|
return callback(new Error(`Controller is not connected`));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
create(callback) {
|
create(callback) {
|
||||||
async.auto({
|
async.auto({
|
||||||
dnsPort: (callback) => getPort().then(port => callback(null, port)),
|
dnsPort: (callback) => getPort().then(port => callback(null, port)),
|
||||||
|
|
Loading…
Reference in a new issue