Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c49b9a9e5 | |||
f7259a6309 | |||
7c4d9cf301 | |||
5ddee94f99 | |||
209e5644c0 | |||
128c9f9751 | |||
0dfb763b17 | |||
2883d2b926 | |||
4113bf551e | |||
2896c92c04 |
@ -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
96
package-lock.json
generated
@ -1,19 +1,9 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "1.0.20",
|
||||
"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"
|
||||
}
|
||||
|
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "1.0.20",
|
||||
"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"
|
||||
|
@ -3,10 +3,6 @@ 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();
|
||||
});
|
||||
@ -15,7 +11,7 @@ tap.test('should start the testproxy', async () => {
|
||||
await testProxy.start();
|
||||
});
|
||||
|
||||
tap.test('should wait for 5 seconds', async (tools) => {
|
||||
tap.test('should wait for 5 seconds', async tools => {
|
||||
await tools.delayFor(1000);
|
||||
});
|
||||
|
||||
|
@ -38,28 +38,31 @@ 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();
|
||||
});
|
||||
});
|
||||
@ -103,4 +106,4 @@ const proxyWorkerCalls = {
|
||||
|
||||
export type TProxyWorkerCalls = typeof proxyWorkerCalls;
|
||||
expose(proxyWorkerCalls);
|
||||
console.log('ProxyWorker initialized');
|
||||
console.log('ProxyWorker initialized');
|
||||
|
@ -5,31 +5,41 @@ import { TPortProxyCalls } from './smartproxy.portproxy';
|
||||
|
||||
export class SmartProxy {
|
||||
public smartsystem = new plugins.smartsystem.Smartsystem();
|
||||
public hostCandidates: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||
public reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||
public proxyWorkerFunctions: plugins.smartspawn.ModuleThread<TProxyWorkerCalls>;
|
||||
public portProxyFunctions: plugins.smartspawn.ModuleThread<TPortProxyCalls>;
|
||||
|
||||
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.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');
|
||||
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 () {
|
||||
public async stop() {
|
||||
await this.proxyWorkerFunctions.stop();
|
||||
await plugins.smartspawn.Thread.terminate(this.portProxyFunctions);
|
||||
await plugins.smartspawn.Thread.terminate(this.proxyWorkerFunctions);
|
||||
console.log('proxy worker stopped');
|
||||
await this.portProxyFunctions.stop();
|
||||
await plugins.smartspawn.Thread.terminate(this.proxyWorkerFunctions);
|
||||
await plugins.smartspawn.Thread.terminate(this.portProxyFunctions);
|
||||
console.log('portproxy stopped');
|
||||
console.log('Terminated all childs!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,9 +7,7 @@ export { http, https };
|
||||
// tsclass scope
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
export {
|
||||
tsclass
|
||||
};
|
||||
export { tsclass };
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
@ -17,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 * as ws from 'ws';
|
||||
|
||||
export {
|
||||
ws
|
||||
};
|
||||
export { ws };
|
||||
|
@ -1,14 +1,16 @@
|
||||
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({
|
||||
const server = net
|
||||
.createServer(from => {
|
||||
const to = net.createConnection({
|
||||
host: 'localhost',
|
||||
port: 8001
|
||||
});
|
||||
from.pipe(to);
|
||||
to.pipe(from);
|
||||
}).listen(8000);
|
||||
});
|
||||
from.pipe(to);
|
||||
to.pipe(from);
|
||||
})
|
||||
.listen(8000);
|
||||
|
||||
const portProxyCalls = {
|
||||
stop: async () => {
|
||||
@ -23,4 +25,4 @@ const portProxyCalls = {
|
||||
export type TPortProxyCalls = typeof portProxyCalls;
|
||||
expose(portProxyCalls);
|
||||
|
||||
console.log('PortProxy Initialized');
|
||||
console.log('PortProxy Initialized');
|
||||
|
Reference in New Issue
Block a user