Compare commits

...

14 Commits

Author SHA1 Message Date
9c49b9a9e5 1.0.25 2019-08-23 00:48:14 +02:00
f7259a6309 fix(core): update 2019-08-23 00:48:14 +02:00
7c4d9cf301 1.0.24 2019-08-23 00:41:39 +02:00
5ddee94f99 fix(core): update 2019-08-23 00:41:38 +02:00
209e5644c0 1.0.23 2019-08-22 16:22:20 +02:00
128c9f9751 fix(core): update 2019-08-22 16:22:19 +02:00
0dfb763b17 1.0.22 2019-08-22 16:14:50 +02:00
2883d2b926 fix(core): update 2019-08-22 16:14:50 +02:00
4113bf551e 1.0.21 2019-08-22 15:21:57 +02:00
2896c92c04 fix(core): update 2019-08-22 15:21:57 +02:00
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
9 changed files with 130 additions and 181 deletions

View File

@ -1,5 +1,7 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
variables:
GIT_STRATEGY: clone
cache:
paths:
@ -38,11 +40,11 @@ snyk:
# test stage
# ====================
testLTS:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/

96
package-lock.json generated
View File

@ -1,19 +1,9 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.18",
"version": "1.0.25",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@airbnb/node-memwatch": {
"version": "1.0.2",
"resolved": "https://verdaccio.lossless.one/@airbnb%2fnode-memwatch/-/node-memwatch-1.0.2.tgz",
"integrity": "sha512-2R+MEEMSTUdKwQ6NFWkyA/UNoSjL1tMldZqJbZpgXSwNMBzlNlkUWEXKu9RqTTMkDqJRfGJ2VDs8gPlPK2APDQ==",
"dev": true,
"requires": {
"bindings": "^1.3.0",
"nan": "^2.9.2"
}
},
"@babel/code-frame": {
"version": "7.5.5",
"resolved": "https://verdaccio.lossless.one/@babel%2fcode-frame/-/code-frame-7.5.5.tgz",
@ -307,14 +297,13 @@
}
},
"@pushrocks/smartspawn": {
"version": "2.0.8",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartspawn/-/smartspawn-2.0.8.tgz",
"integrity": "sha512-3ohykcFhQhsblWlc8uZddb/8EBXBhd7tv8oKcvA7EnM3PLLEn6GTM9rSptLWmdhYli7IZQW+rtHCZoSSY1/+9w==",
"version": "2.0.9",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartspawn/-/smartspawn-2.0.9.tgz",
"integrity": "sha512-PKg4UWmIBc4kE92V91VNsarxaDu3EWvhNtxybvnka/V82m4iZVWKpxGYt0fLsUj6vqJDla/wnkZImiBTlYGLcg==",
"requires": {
"@pushrocks/smartpromise": "^3.0.2",
"spawn-wrap": "^1.4.2",
"threads": "1.0.0-beta.4",
"tiny-worker": "^2.2.0"
"threads": "1.0.0-beta.4"
}
},
"@pushrocks/smartstring": {
@ -330,9 +319,9 @@
}
},
"@pushrocks/smartsystem": {
"version": "2.0.7",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsystem/-/smartsystem-2.0.7.tgz",
"integrity": "sha512-YwRmwfFZGJCsy4xSW6HmUfWXiHgbBdsbuwVjYJ/fb2pQn4aYp2W2FL0S6gA4pofryQVkaUcxEjFEKTpfNjM1dA==",
"version": "2.0.8",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsystem/-/smartsystem-2.0.8.tgz",
"integrity": "sha512-lBruo1Ikai35oiDMy3Lx1NhddTMynCCd8MTx4dBU22a0HnNYZRKxTITuPAfIDD3VB94ZpEGbAvzblnZpuFFkMQ==",
"requires": {
"@pushrocks/lik": "^3.0.10",
"@pushrocks/smartenv": "^4.0.7",
@ -352,15 +341,14 @@
}
},
"@pushrocks/tapbundle": {
"version": "3.0.11",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.11.tgz",
"integrity": "sha512-s7epZfJZX+LsBVmIYvoaY4WtgPvRLnHZMVTpQAPJGMBqxJAQxhQ2wvGJjmqMAGhhznAHI6t4g+m0KTp3vFIRVg==",
"version": "3.0.13",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.13.tgz",
"integrity": "sha512-23O4UMBafCuD+RnUlXNvtT9DGbL1HMD+xZE1Zcr7Ll7WvgxUgRQQfk9kq6qbLLbjaRe1J2Ijsgh1HuZbBaucLQ==",
"dev": true,
"requires": {
"@pushrocks/early": "^3.0.3",
"@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartpromise": "^3.0.2",
"leakage": "^0.4.0",
"smartchai": "^2.0.1"
}
},
@ -554,15 +542,6 @@
"resolved": "https://verdaccio.lossless.one/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"bindings": {
"version": "1.5.0",
"resolved": "https://verdaccio.lossless.one/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"dev": true,
"requires": {
"file-uri-to-path": "1.0.0"
}
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://verdaccio.lossless.one/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -830,12 +809,6 @@
"once": "^1.4.0"
}
},
"es6-error": {
"version": "4.1.1",
"resolved": "https://verdaccio.lossless.one/es6-error/-/es6-error-4.1.1.tgz",
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
"dev": true
},
"es6-promise": {
"version": "4.2.8",
"resolved": "https://verdaccio.lossless.one/es6-promise/-/es6-promise-4.2.8.tgz",
@ -857,7 +830,8 @@
"esm": {
"version": "3.2.25",
"resolved": "https://verdaccio.lossless.one/esm/-/esm-3.2.25.tgz",
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA=="
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==",
"optional": true
},
"esprima": {
"version": "4.0.1",
@ -895,12 +869,6 @@
"escape-string-regexp": "^1.0.5"
}
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://verdaccio.lossless.one/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"dev": true
},
"find-up": {
"version": "3.0.0",
"resolved": "https://verdaccio.lossless.one/find-up/-/find-up-3.0.0.tgz",
@ -1147,25 +1115,6 @@
"invert-kv": "^2.0.0"
}
},
"leakage": {
"version": "0.4.0",
"resolved": "https://verdaccio.lossless.one/leakage/-/leakage-0.4.0.tgz",
"integrity": "sha512-x7gYK5n5dPkHDZWJ2Kh8Ag1hZNzUh+HtXn8Bv1aDdN6o6ONPCJ8sOfFq+kxcULJFp3lXaCjXb3iXOLmQRbBLwA==",
"dev": true,
"requires": {
"@airbnb/node-memwatch": "^1.0.2",
"es6-error": "^4.0.2",
"left-pad": "^1.1.3",
"minimist": "^1.2.0",
"pretty-bytes": "^4.0.2"
}
},
"left-pad": {
"version": "1.3.0",
"resolved": "https://verdaccio.lossless.one/left-pad/-/left-pad-1.3.0.tgz",
"integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==",
"dev": true
},
"locate-path": {
"version": "3.0.0",
"resolved": "https://verdaccio.lossless.one/locate-path/-/locate-path-3.0.0.tgz",
@ -1267,12 +1216,6 @@
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "1.2.0",
"resolved": "https://verdaccio.lossless.one/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://verdaccio.lossless.one/mkdirp/-/mkdirp-0.5.1.tgz",
@ -1306,12 +1249,6 @@
"resolved": "https://verdaccio.lossless.one/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"nan": {
"version": "2.14.0",
"resolved": "https://verdaccio.lossless.one/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==",
"dev": true
},
"nice-try": {
"version": "1.0.5",
"resolved": "https://verdaccio.lossless.one/nice-try/-/nice-try-1.0.5.tgz",
@ -1496,12 +1433,6 @@
"is-number-like": "^1.0.3"
}
},
"pretty-bytes": {
"version": "4.0.2",
"resolved": "https://verdaccio.lossless.one/pretty-bytes/-/pretty-bytes-4.0.2.tgz",
"integrity": "sha1-sr+C5zUNZcbDOqlaqlpPYyf2HNk=",
"dev": true
},
"process-nextick-args": {
"version": "2.0.1",
"resolved": "https://verdaccio.lossless.one/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
@ -1828,6 +1759,7 @@
"version": "2.2.0",
"resolved": "https://verdaccio.lossless.one/tiny-worker/-/tiny-worker-2.2.0.tgz",
"integrity": "sha512-/DnTni0fPjjOlqA6BNcUo6pxyfbViJZ7vxwA+RZ+gF0dBevxp0sropQFVZ4NS5PRgQ8J7EBu8zMJYKwoNo5aWg==",
"optional": true,
"requires": {
"esm": "^3.2.22"
}

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartproxy",
"version": "1.0.18",
"version": "1.0.25",
"private": false,
"description": "a proxy for handling high workloads of proxying",
"main": "dist/index.js",
@ -9,13 +9,13 @@
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild)",
"build": "(tsbuild --web)",
"format": "(gitzone format)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.2",
"tslint": "^5.19.0",
"tslint-config-prettier": "^1.15.0"
@ -24,8 +24,8 @@
"@pushrocks/smartnetwork": "^1.1.6",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrequest": "^1.1.23",
"@pushrocks/smartspawn": "^2.0.8",
"@pushrocks/smartsystem": "^2.0.7",
"@pushrocks/smartspawn": "^2.0.9",
"@pushrocks/smartsystem": "^2.0.8",
"@tsclass/tsclass": "^2.0.5",
"@types/ws": "^6.0.2",
"ws": "^7.1.2"

View File

@ -11,8 +11,8 @@ tap.test('should start the testproxy', async () => {
await testProxy.start();
});
tap.test('should wait for 5 seconds', async (tools) => {
await tools.delayFor(5000);
tap.test('should wait for 5 seconds', async tools => {
await tools.delayFor(1000);
});
tap.test('should close the testproxy', async () => {

View File

@ -1,50 +0,0 @@
import { expose } from '@pushrocks/smartspawn';
import * as plugins from './smartproxy.plugins';
import * as cluster from 'cluster';
class ProxyMaster {
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
public clusterChilds: any[] = [];
public smartsystem = new plugins.smartsystem.Smartsystem();
public async start() {
if (cluster.isMaster) {
console.log('ProxyMaster registered as cluster master');
console.log(`should spawn ${this.smartsystem.cpus.length} workers`);
for (const cpu of this.smartsystem.cpus) {
cluster.fork();
}
} else {
const proxyworkerMod = await import('./smartproxy.classes.proxyworker');
const proxyWorkerInstance = new proxyworkerMod.ProxyWorker();
console.log('Proxymaster registered a ProxyWorker!');
const data = new Uint8Array(Buffer.from('Hello Node.js'));
fs.writeFile('message.txt', data, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
}
}
}
const defaultProxyMaster = new ProxyMaster();
if (!cluster.isMaster) {
defaultProxyMaster.start();
}
console.log('hi');
// the following is interesting for the master process only
const proxyMasterCalls = {
terminateMaster: async () => {
process.kill(0);
},
start: async () => {
await defaultProxyMaster.start();
},
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
}
};
export type TProxyMasterCalls = typeof proxyMasterCalls;
expose (proxyMasterCalls);

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}`,
@ -32,38 +38,42 @@ export class ProxyWorker {
});
});
const Websocket = await import('ws');
// Enable websockets
const wss = new plugins.ws.Server({ server: this.httpsServer });
wss.on('connection', function connection(ws) {
const wscConnected = plugins.smartpromise.defer();
const wsc = new plugins.ws(`${ws.url}`);
const wsc = new Websocket.default(`${ws.url}`);
wsc.on('open', () => {
wscConnected.resolve();
});
ws.on('message', async (message) => {
ws.on('message', async message => {
await wscConnected.promise;
wsc.emit('message', message);
});
wsc.on('message', (message) => {
wsc.on('message', message => {
ws.emit('message', message);
});
// handle closing
ws.on('close', (message) => {
ws.on('close', message => {
wsc.close();
});
wsc.on('close', (message) => {
wsc.on('close', message => {
ws.close();
});
});
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 +87,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,26 +1,45 @@
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 reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
public proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>;
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
public proxyMasterFunctions: plugins.smartspawn.ModuleThread<TProxyMasterCalls>;
public addHostCandidate(hostCandidate: plugins.tsclass.network.IReverseProxyConfig) {
public async updateReversConfigs(
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
) {
// TODO search for old hostCandidates with that target
this.hostCandidates.push(hostCandidate);
this.reverseConfigs = reverseConfigsArg;
if (this.proxyWorkerFunctions) {
await this.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs);
}
}
public async start () {
this.proxyMasterFunctions = await plugins.smartspawn.spawn<TProxyMasterCalls>(new plugins.smartspawn.Worker('./smartproxy.classes.proxymaster'));
console.log('successfully spawned proxymaster');
await this.proxyMasterFunctions.start();
public async start() {
this.proxyWorkerFunctions = await plugins.smartspawn.spawn<TProxyWorkerCalls>(
new plugins.smartspawn.Worker('./smartproxy.classes.proxyworker')
);
this.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs);
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(
new plugins.smartspawn.Worker('./smartproxy.portproxy')
);
await this.proxyWorkerFunctions.start();
console.log('successfully spawned portproxy and proxyworkers!');
}
public async stop () {
await this.proxyMasterFunctions.terminateMaster();
public async stop() {
await this.proxyWorkerFunctions.stop();
await plugins.smartspawn.Thread.terminate(this.proxyWorkerFunctions);
console.log('proxy worker stopped');
await this.portProxyFunctions.stop();
await plugins.smartspawn.Thread.terminate(this.portProxyFunctions);
console.log('portproxy stopped');
console.log('Terminated all childs!');
}
}

View File

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

View File

@ -0,0 +1,28 @@
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');