smartproxy/ts/smartproxy.classes.smartproxy.ts

42 lines
1.7 KiB
TypeScript
Raw Permalink 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 13:21:57 +00:00
public reverseConfigs: 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 13:21:57 +00:00
public async updateReversConfigs(reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
2019-08-20 16:42:52 +00:00
// TODO search for old hostCandidates with that target
2019-08-22 13:21:57 +00:00
this.reverseConfigs = reverseConfigsArg;
if (this.proxyWorkerFunctions) {
await this.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs);
}
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'));
2019-08-22 13:21:57 +00:00
this.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs);
2019-08-22 13:09:48 +00:00
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(new plugins.smartspawn.Worker('./smartproxy.portproxy'));
await this.proxyWorkerFunctions.start();
2019-08-22 13:21:57 +00:00
console.log('successfully spawned portproxy and proxyworkers!');
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
}