fix(core): update

This commit is contained in:
Philipp Kunz 2022-07-29 00:49:46 +02:00
parent ca73849541
commit 101470dcd4
12 changed files with 11832 additions and 8967 deletions

20550
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,32 +5,29 @@
"description": "a proxy for handling high workloads of proxying",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web)",
"build": "(tsbuild --web --allowimplicitany)",
"format": "(gitzone format)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.10",
"@types/node": "^14.14.22",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tstest": "^1.0.72",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.6.2"
},
"dependencies": {
"@pushrocks/lik": "^4.0.20",
"@pushrocks/smartnetwork": "^1.1.22",
"@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrequest": "^1.1.51",
"@pushrocks/smartspawn": "^2.0.9",
"@pushrocks/smartstring": "^3.0.24",
"@pushrocks/smartsystem": "^2.0.9",
"@tsclass/tsclass": "^3.0.29",
"@types/ws": "^7.4.0",
"ws": "^7.4.3"
"@pushrocks/lik": "^6.0.0",
"@pushrocks/smartnetwork": "^3.0.0",
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrequest": "^1.1.56",
"@pushrocks/smartstring": "^4.0.2",
"@tsclass/tsclass": "^4.0.17",
"@types/ws": "^8.5.3",
"ws": "^8.8.1"
},
"files": [
"ts/**/*",

View File

@ -1,10 +1,13 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartproxy from '../ts/index';
import * as smartproxy from '../ts/index.js';
let testProxy: smartproxy.SmartProxy;
let testProxy: smartproxy.NetworkProxy;
tap.test('first test', async () => {
testProxy = new smartproxy.SmartProxy({});
testProxy = new smartproxy.NetworkProxy({
port: 3001
});
expect(testProxy).toBeInstanceOf(smartproxy.NetworkProxy);
});
tap.test('should start the testproxy', async () => {
@ -12,9 +15,9 @@ tap.test('should start the testproxy', async () => {
});
tap.test('should supply reverse proxy config', async () => {
testProxy.updateReverseConfigs([
testProxy.updateProxyConfigs([
{
destinationIp: 'localhost',
destinationIp: '127.0.0.1',
destinationPort: '3000',
hostName: 'push.rocks',
privateKey: `-----BEGIN PRIVATE KEY-----

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartproxy',
version: '2.0.16',
description: 'a proxy for handling high workloads of proxying'
}

View File

@ -1 +1,2 @@
export * from './smartproxy.classes.smartproxy';
export * from './smartproxy.classes.networkproxy.js'
export * from './smartproxy.portproxy.js';

View File

@ -1,12 +1,17 @@
import { expose } from '@pushrocks/smartspawn';
import * as plugins from './smartproxy.plugins';
import { SmartproxyRouter } from './smartproxy.classes.router';
import * as plugins from './smartproxy.plugins.js';
import { ProxyRouter } from './smartproxy.classes.router.js';
export class ProxyWorker {
export interface INetworkProxyOptions {
port: number;
}
export class NetworkProxy {
// INSTANCE
public options: INetworkProxyOptions;
public proxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
public httpsServer: plugins.https.Server; // | plugins.http.Server;
public port = 8001;
public router = new SmartproxyRouter();
public httpsServer: plugins.https.Server;
public router = new ProxyRouter();
public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
public defaultHeaders: { [key: string]: string } = {};
@ -14,6 +19,10 @@ export class ProxyWorker {
[hostName: string]: plugins.tsclass.network.IReverseProxyConfig;
} = {};
constructor(optionsArg: INetworkProxyOptions) {
this.options = optionsArg;
}
/**
* starts the proxyInstance
*/
@ -196,7 +205,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
);
// Enable websockets
const wss = new plugins.ws.Server({ server: this.httpsServer });
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
wss.on('connection', (ws: plugins.wsDefault) => {
console.log('got connection for wsc');
const wscConnected = plugins.smartpromise.defer();
@ -242,9 +251,12 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
connection.setTimeout(120000);
this.socketMap.add(connection);
const cleanupConnection = () => {
this.socketMap.remove(connection);
connection.removeAllListeners();
connection.destroy();
if (this.socketMap.checkForObject(connection)) {
this.socketMap.remove(connection);
connection.end();
connection.removeAllListeners();
connection.destroy();
}
};
connection.on('close', () => {
cleanupConnection();
@ -260,8 +272,8 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
});
});
this.httpsServer.listen(this.port);
console.log(`ProxyWorker -> OK: now listening for new connections on port ${this.port}`);
this.httpsServer.listen(this.options.port);
console.log(`ProxyWorker -> OK: now listening for new connections on port ${this.options.port}`);
}
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
@ -306,28 +318,3 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
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[]) => {
await proxyWorkerInstance.updateProxyConfigs(configArray);
},
addDefaultHeaders: async (headersArg: { [key: string]: string }) => {
proxyWorkerInstance.defaultHeaders = {
...proxyWorkerInstance.defaultHeaders,
...headersArg,
};
},
};
export type TProxyWorkerCalls = typeof proxyWorkerCalls;
expose(proxyWorkerCalls);
console.log('ProxyWorker initialized');

View File

@ -1,6 +1,6 @@
import * as plugins from './smartproxy.plugins';
import * as plugins from './smartproxy.plugins.js';
export class SmartproxyRouter {
export class ProxyRouter {
public reverseProxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
/**

View File

@ -1,61 +0,0 @@
import * as plugins from './smartproxy.plugins';
import { TProxyWorkerCalls } from './smartproxy.classes.proxyworker';
import { TPortProxyCalls } from './smartproxy.portproxy';
export interface ISmartProxyOptions {
port?: number;
}
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 options: ISmartProxyOptions;
constructor(optionsArg: ISmartProxyOptions = {}) {
this.options = optionsArg;
}
public async updateReverseConfigs(
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
) {
// TODO search for old hostCandidates with that target
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.proxyWorkerFunctions.updateReverseConfigs(this.reverseConfigs);
this.portProxyFunctions = await plugins.smartspawn.spawn<TPortProxyCalls>(
new plugins.smartspawn.Worker('./smartproxy.portproxy')
);
await this.portProxyFunctions.start(this.options.port);
await this.proxyWorkerFunctions.start();
console.log('successfully spawned portproxy and proxyworkers!');
}
public async updateDefaultHeaders(defaultHeadersArg: {[key: string]: string}) {
await this.proxyWorkerFunctions.addDefaultHeaders(defaultHeadersArg);
}
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

@ -15,11 +15,9 @@ export { tsclass };
import * as lik from '@pushrocks/lik';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartspawn from '@pushrocks/smartspawn';
import * as smartstring from '@pushrocks/smartstring';
import * as smartsystem from '@pushrocks/smartsystem';
export { lik, smartrequest, smartpromise, smartspawn, smartstring, smartsystem };
export { lik, smartrequest, smartpromise, smartstring };
// third party scope
import * as ws from 'ws';

View File

@ -1,11 +1,18 @@
import * as plugins from './smartproxy.plugins';
import { expose } from '@pushrocks/smartspawn';
import * as plugins from './smartproxy.plugins.js';
import * as net from 'net';
let netServer: plugins.net.Server;
let httpServer: plugins.http.Server;
const portProxyCalls = {
start: async (portArg = 8000) => {
export class PortProxy {
fromPort: number;
toPort: number;
constructor(fromPortArg: number, toPortArg: number) {
this.fromPort = fromPortArg;
this.toPort = toPortArg
}
public async start () {
httpServer = plugins.http.createServer((request, response) => {
const requestUrl = new URL(request.url, `http://${request.headers.host}`);
const completeUrlWithoutProtocol = `${requestUrl.host}${requestUrl.pathname}${requestUrl.search}`;
@ -17,7 +24,7 @@ const portProxyCalls = {
});
response.end();
});
httpServer.listen(7999);
httpServer.listen(this.fromPort);
const cleanUpSockets = (from: plugins.net.Socket, to: plugins.net.Socket) => {
from.end();
to.end();
@ -32,7 +39,7 @@ const portProxyCalls = {
.createServer((from) => {
const to = net.createConnection({
host: 'localhost',
port: 8001,
port: this.toPort,
});
from.setTimeout(120000);
from.pipe(to);
@ -62,10 +69,11 @@ const portProxyCalls = {
cleanUpSockets(from, to);
})
})
.listen(portArg);
console.log(`PortProxy -> OK: Now listening on port ${portArg}`);
},
stop: async () => {
.listen(this.fromPort);
console.log(`PortProxy -> OK: Now listening on port ${this.fromPort}`);
}
public async stop() {
const done = plugins.smartpromise.defer();
httpServer.close(() => {
netServer.close(() => {
@ -73,10 +81,5 @@ const portProxyCalls = {
});
});
await done.promise;
},
}
};
export type TPortProxyCalls = typeof portProxyCalls;
expose(portProxyCalls);
console.log('PortProxy Initialized');

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}