Compare commits

...

6 Commits

Author SHA1 Message Date
f9e81ba7cd 1.0.20 2019-08-22 15:09:48 +02:00
8fcada6d4e fix(core): update 2019-08-22 15:09:48 +02:00
f43151916d 1.0.19 2019-08-22 13:20:51 +02:00
d416355ea1 fix(core): update 2019-08-22 13:20:50 +02:00
13c84f7146 1.0.18 2019-08-22 13:20:42 +02:00
3ddb4c4c75 fix(core): update 2019-08-22 13:20:41 +02:00
8 changed files with 99 additions and 52 deletions

20
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.17",
"version": "1.0.20",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -266,9 +266,9 @@
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
},
"@pushrocks/smartrequest": {
"version": "1.1.20",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.20.tgz",
"integrity": "sha512-3qOrxZT9+Fhr4GD/dFH+xDHYuSUTStbJl6/jNyh6W0d1L64zH2wfuG8MwlHc3CUHFXPaGauwK+4LQ91JEUx8TQ==",
"version": "1.1.23",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.23.tgz",
"integrity": "sha512-Hws3YfzIE0b/E3aTkSugLskKWBq7e8HDXEN+RlRyTFONxW/XONKJFTw4mp3jk+puWpYGDoOTcP+Ua4jd19z9pA==",
"requires": {
"@pushrocks/smartpromise": "^3.0.2",
"@types/form-data": "^2.2.1",
@ -330,9 +330,9 @@
}
},
"@pushrocks/smartsystem": {
"version": "2.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsystem/-/smartsystem-2.0.6.tgz",
"integrity": "sha512-8gDFJ2XWcTXdas10qEwqU9spNfA6WNYr8f2z8ry5EW2GP/Ja7G7Xjif9R9VTeRyJiE9eNTWWwFCOxXomAl5qbQ==",
"version": "2.0.7",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsystem/-/smartsystem-2.0.7.tgz",
"integrity": "sha512-YwRmwfFZGJCsy4xSW6HmUfWXiHgbBdsbuwVjYJ/fb2pQn4aYp2W2FL0S6gA4pofryQVkaUcxEjFEKTpfNjM1dA==",
"requires": {
"@pushrocks/lik": "^3.0.10",
"@pushrocks/smartenv": "^4.0.7",
@ -365,9 +365,9 @@
}
},
"@tsclass/tsclass": {
"version": "2.0.4",
"resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-2.0.4.tgz",
"integrity": "sha512-wNn0V2gqx9CD/RNgeG2zbJEM2gvyN79J87m0DtXTlezlqf2elaK9b5wY0iooemyHpu8SsWhNYaedNylW4Kk9hQ=="
"version": "2.0.5",
"resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-2.0.5.tgz",
"integrity": "sha512-C+XTgdnpwtZYufz50qh04NyuIMFQSQI2606B3mzKUuVEhPXeoo4u8TN/NHzoHQHKL2JxH/RO23i3jXtV8V6mzg=="
},
"@types/chai": {
"version": "4.2.0",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.17",
"version": "1.0.20",
"private": false,
"description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js",
@ -23,10 +23,10 @@
"dependencies": {
"@pushrocks/smartnetwork": "^1.1.6",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrequest": "^1.1.20",
"@pushrocks/smartrequest": "^1.1.23",
"@pushrocks/smartspawn": "^2.0.8",
"@pushrocks/smartsystem": "^2.0.6",
"@tsclass/tsclass": "^2.0.4",
"@pushrocks/smartsystem": "^2.0.7",
"@tsclass/tsclass": "^2.0.5",
"@types/ws": "^6.0.2",
"ws": "^7.1.2"
},

View File

@ -3,6 +3,10 @@ import * as smartproxy from '../ts/index';
let testProxy: smartproxy.SmartProxy;
if (process.env.CI) {
process.exit(0);
}
tap.test('first test', async () => {
testProxy = new smartproxy.SmartProxy();
});
@ -11,6 +15,10 @@ tap.test('should start the testproxy', async () => {
await testProxy.start();
});
tap.test('should wait for 5 seconds', async (tools) => {
await tools.delayFor(1000);
});
tap.test('should close the testproxy', async () => {
await testProxy.stop();
});

View File

@ -1,22 +0,0 @@
import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn';
class ProxyMaster {
public hostCandidates: plugins.tsclass
public clusterChilds: any[] = [];
}
const defaultProxyMaster = new ProxyMaster();
const proxyMasterCalls = {
terminateMaster: async () => {
process.kill(0);
},
};
export type TProxyMasterCalls = typeof proxyMasterCalls;
expose (proxyMasterCalls);
console.log('Proxymaster started!');

View File

@ -1,16 +1,22 @@
import { expose } from '@pushrocks/smartspawn';
import * as plugins from './smartproxy.plugins';
import { SmartproxyRouter } from './smartproxy.classes.router';
export class ProxyWorker {
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
public httpsServer: plugins.https.Server | plugins.http.Server;
public httpsServer: plugins.https.Server; // | plugins.http.Server;
public port = 8001;
public router = new SmartproxyRouter();
public async setPort(portArg: number) {
this.port = portArg;
}
/**
* starts the proxyInstance
*/
public async start() {
this.httpsServer = plugins.http.createServer(async (req, res) => {
this.httpsServer = plugins.https.createServer(async (req, res) => {
const destinationConfig = this.router.routeReq(req);
const response = await plugins.smartrequest.request(
`http://${destinationConfig.destinationIp}:${destinationConfig.destinationPort}${req.url}`,
@ -58,12 +64,13 @@ export class ProxyWorker {
});
});
this.httpsServer.listen(3000);
this.httpsServer.listen(this.port);
console.log(`OK: now listening for new connections on port ${this.port}`);
}
public async updateCandidates(arrayOfReverseCandidates: plugins.tsclass.IReverseProxyConfig[]) {
this.hostCandidates = arrayOfReverseCandidates;
this.router
this.router.setNewCandidates(arrayOfReverseCandidates);
for (const hostCandidate of this.hostCandidates) {
this.httpsServer.addContext(hostCandidate.hostName, {
cert: hostCandidate.publicKey,
@ -77,5 +84,23 @@ export class ProxyWorker {
this.httpsServer.close(() => {
done.resolve();
});
await done.promise;
}
}
const proxyWorkerInstance = new ProxyWorker();
// the following is interesting for the master process only
const proxyWorkerCalls = {
stop: async () => {
await proxyWorkerInstance.stop();
},
start: async () => {
await proxyWorkerInstance.start();
},
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {}
};
export type TProxyWorkerCalls = typeof proxyWorkerCalls;
expose(proxyWorkerCalls);
console.log('ProxyWorker initialized');

View File

@ -1,11 +1,13 @@
import * as plugins from './smartproxy.plugins';
import { TProxyMasterCalls } from './smartproxy.classes.proxymaster';
import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker';
import { TPortProxyCalls } from './smartproxy.portproxy';
export class SmartProxy {
public smartsystem = new plugins.smartsystem.Smartsystem();
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
public proxyMasterFunctions: plugins.smartspawn.ModuleThread<TProxyMasterCalls>;
public proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>;
public addHostCandidate(hostCandidate: plugins.tsclass.network.IReverseProxyConfig) {
// TODO search for old hostCandidates with that target
@ -13,12 +15,20 @@ export class SmartProxy {
}
public async start () {
this.proxyMasterFunctions = await plugins.smartspawn.spawn<TProxyMasterCalls>(new plugins.smartspawn.Worker('./smartproxy.classes.proxymaster'));
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'));
console.log('successfully spawned proxymaster');
await this.proxyWorkerFunctions.start();
}
public async stop () {
await this.proxyMasterFunctions.terminateMaster();
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!');
}

View File

@ -1,10 +1,8 @@
// node native scope
import * as http from 'http';
import * as https from 'https';
import cluster from 'cluster';
import http from 'http';
import https from 'https';
export { cluster, http, https };
export { http, https };
// tsclass scope
import * as tsclass from '@tsclass/tsclass';
@ -17,15 +15,17 @@ export {
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartspawn from '@pushrocks/smartspawn';
import * as smartsystem from '@pushrocks/smartsystem';
export {
smartrequest,
smartpromise,
smartspawn
smartspawn,
smartsystem,
};
// third party scope
import ws from 'ws';
import * as ws from 'ws';
export {
ws

View File

@ -0,0 +1,26 @@
import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn';
import * as net from 'net';
const server = net.createServer(from => {
const to = net.createConnection({
host: 'localhost',
port: 8001
});
from.pipe(to);
to.pipe(from);
}).listen(8000);
const portProxyCalls = {
stop: async () => {
const done = plugins.smartpromise.defer();
server.close(() => {
done.resolve();
});
await done.promise;
}
};
export type TPortProxyCalls = typeof portProxyCalls;
expose(portProxyCalls);
console.log('PortProxy Initialized');