smartproxy/ts/smartproxy.classes.smartproxy.ts

36 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-08-20 16:42:52 +00:00
import * as plugins from './smartproxy.plugins';
2019-08-22 10:49:29 +00:00
2019-08-22 13:09:48 +00:00
import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker';
import { TPortProxyCalls } from './smartproxy.portproxy';
2019-08-20 16:42:52 +00:00
export class SmartProxy {
2019-08-22 13:09:48 +00:00
public smartsystem = new plugins.smartsystem.Smartsystem();
2019-08-22 10:49:29 +00:00
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
2019-08-22 13:09:48 +00:00
public proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>;
2019-08-20 16:42:52 +00:00
2019-08-22 10:49:29 +00:00
public addHostCandidate(hostCandidate: plugins.tsclass.network.IReverseProxyConfig) {
2019-08-20 16:42:52 +00:00
// TODO search for old hostCandidates with that target
this.hostCandidates.push(hostCandidate);
2019-08-20 16:43:15 +00:00
}
2019-08-20 16:42:52 +00:00
2019-08-22 10:49:29 +00:00
public async start () {
2019-08-22 13:09:48 +00:00
this.proxyWorkerFunctions = await plugins.smartspawn.spawn<TProxyWorkerCalls>(new plugins.smartspawn.Worker('./smartproxy.classes.proxyworker'));
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(new plugins.smartspawn.Worker('./smartproxy.portproxy'));
2019-08-22 10:49:29 +00:00
console.log('successfully spawned proxymaster');
2019-08-22 13:09:48 +00:00
await this.proxyWorkerFunctions.start();
2019-08-20 16:42:52 +00:00
}
2019-08-22 10:49:29 +00:00
public async stop () {
2019-08-22 13:09:48 +00:00
await this.proxyWorkerFunctions.stop();
await plugins.smartspawn.Thread.terminate(this.portProxyFunctions);
console.log('proxy worker stopped');
await this.portProxyFunctions.stop();
await plugins.smartspawn.Thread.terminate(this.proxyWorkerFunctions);
console.log('portproxy stopped');
console.log('Terminated all childs!');
2019-08-20 16:42:52 +00:00
}
2019-08-21 21:41:06 +00:00
2019-08-21 21:54:55 +00:00
2019-08-20 16:42:52 +00:00
}