Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
209e5644c0 | |||
128c9f9751 | |||
0dfb763b17 | |||
2883d2b926 | |||
4113bf551e | |||
2896c92c04 | |||
f9e81ba7cd | |||
8fcada6d4e | |||
f43151916d | |||
d416355ea1 | |||
13c84f7146 | |||
3ddb4c4c75 |
@ -1,5 +1,7 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
variables:
|
||||
GIT_STRATEGY: clone
|
||||
|
||||
cache:
|
||||
paths:
|
||||
|
20
package-lock.json
generated
20
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.23",
|
||||
"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",
|
||||
|
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.23",
|
||||
"private": false,
|
||||
"description": "a proxy for handling high workloads of proxying",
|
||||
"main": "dist/index.js",
|
||||
@ -9,7 +9,7 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"build": "(tsbuild --web)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -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"
|
||||
},
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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!');
|
@ -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');
|
||||
|
@ -1,25 +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');
|
||||
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.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!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,32 +1,23 @@
|
||||
// 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';
|
||||
|
||||
export {
|
||||
tsclass
|
||||
};
|
||||
export { tsclass };
|
||||
|
||||
// pushrocks scope
|
||||
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
|
||||
};
|
||||
export { smartrequest, smartpromise, smartspawn, smartsystem };
|
||||
|
||||
// third party scope
|
||||
import ws from 'ws';
|
||||
import * as ws from 'ws';
|
||||
|
||||
export {
|
||||
ws
|
||||
};
|
||||
export { ws };
|
||||
|
28
ts/smartproxy.portproxy.ts
Normal file
28
ts/smartproxy.portproxy.ts
Normal 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');
|
Reference in New Issue
Block a user