Compare commits

...

10 Commits

Author SHA1 Message Date
ca73849541 2.0.15 2021-02-03 19:42:27 +00:00
b64523b0b2 fix(core): update 2021-02-03 19:42:27 +00:00
963ad6efa4 2.0.14 2021-02-03 15:11:55 +00:00
d271029302 fix(core): update 2021-02-03 15:11:55 +00:00
018fcbf71e 2.0.13 2021-02-03 11:19:57 +00:00
fa04732241 fix(core): update 2021-02-03 11:19:56 +00:00
da19fab8d8 2.0.12 2021-02-03 11:02:26 +00:00
8d318dca28 fix(core): update 2021-02-03 11:02:26 +00:00
d03bfcc793 2.0.11 2021-02-03 01:14:10 +00:00
4ba2686977 fix(core): update 2021-02-03 01:14:09 +00:00
3 changed files with 64 additions and 13 deletions

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "2.0.10", "version": "2.0.15",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -11438,9 +11438,9 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}, },
"ws": { "ws": {
"version": "7.4.2", "version": "7.4.3",
"resolved": "https://verdaccio.lossless.one/ws/-/ws-7.4.2.tgz", "resolved": "https://verdaccio.lossless.one/ws/-/ws-7.4.3.tgz",
"integrity": "sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==" "integrity": "sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA=="
}, },
"xml-js": { "xml-js": {
"version": "1.6.11", "version": "1.6.11",

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "2.0.10", "version": "2.0.15",
"private": false, "private": false,
"description": "a proxy for handling high workloads of proxying", "description": "a proxy for handling high workloads of proxying",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -30,7 +30,7 @@
"@pushrocks/smartsystem": "^2.0.9", "@pushrocks/smartsystem": "^2.0.9",
"@tsclass/tsclass": "^3.0.29", "@tsclass/tsclass": "^3.0.29",
"@types/ws": "^7.4.0", "@types/ws": "^7.4.0",
"ws": "^7.4.2" "ws": "^7.4.3"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

View File

@ -10,6 +10,10 @@ export class ProxyWorker {
public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>(); public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
public defaultHeaders: { [key: string]: string } = {}; public defaultHeaders: { [key: string]: string } = {};
public alreadyAddedReverseConfigs: {
[hostName: string]: plugins.tsclass.network.IReverseProxyConfig;
} = {};
/** /**
* starts the proxyInstance * starts the proxyInstance
*/ */
@ -162,6 +166,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
{ {
method: req.method, method: req.method,
headers: req.headers, headers: req.headers,
keepAlive: true,
}, },
true, // lets make this streaming true, // lets make this streaming
(request) => { (request) => {
@ -214,20 +219,44 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
}); });
// handle closing // handle closing
ws.on('close', (message) => { const cleanUp = () => {
ws.removeAllListeners();
ws.close();
ws.terminate();
wsc.removeAllListeners();
wsc.close(); wsc.close();
wsc.terminate();
};
ws.on('close', (message) => {
cleanUp();
}); });
wsc.on('close', (message) => { wsc.on('close', (message) => {
ws.close(); cleanUp();
}); });
}); });
this.httpsServer.keepAliveTimeout = 61000; this.httpsServer.keepAliveTimeout = 61000;
this.httpsServer.headersTimeout = 65000; this.httpsServer.headersTimeout = 65000;
this.httpsServer.on('connection', (connection) => { this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
connection.setTimeout(120000);
this.socketMap.add(connection); this.socketMap.add(connection);
connection.on('close', () => { const cleanupConnection = () => {
this.socketMap.remove(connection); this.socketMap.remove(connection);
connection.removeAllListeners();
connection.destroy();
};
connection.on('close', () => {
cleanupConnection();
});
connection.on('error', () => {
cleanupConnection();
});
connection.on('end', () => {
cleanupConnection();
});
connection.on('timeout', () => {
cleanupConnection();
}); });
}); });
@ -240,10 +269,27 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
this.router.setNewProxyConfigs(proxyConfigsArg); this.router.setNewProxyConfigs(proxyConfigsArg);
for (const hostCandidate of this.proxyConfigs) { for (const hostCandidate of this.proxyConfigs) {
// console.log(hostCandidate); // console.log(hostCandidate);
const existingHostNameConfig = this.alreadyAddedReverseConfigs[hostCandidate.hostName];
if (!existingHostNameConfig) {
this.alreadyAddedReverseConfigs[hostCandidate.hostName] = hostCandidate;
} else {
if (
existingHostNameConfig.publicKey === hostCandidate.publicKey &&
existingHostNameConfig.privateKey === hostCandidate.privateKey
) {
continue;
} else {
this.alreadyAddedReverseConfigs[hostCandidate.hostName] = hostCandidate;
}
}
this.httpsServer.addContext(hostCandidate.hostName, { this.httpsServer.addContext(hostCandidate.hostName, {
cert: hostCandidate.publicKey, cert: hostCandidate.publicKey,
key: hostCandidate.privateKey, key: hostCandidate.privateKey,
}); });
this.httpsServer;
} }
/* this.httpsServer.close(); /* this.httpsServer.close();
this.httpsServer.listen(this.port); */ this.httpsServer.listen(this.port); */
@ -274,7 +320,12 @@ const proxyWorkerCalls = {
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => { updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
await proxyWorkerInstance.updateProxyConfigs(configArray); await proxyWorkerInstance.updateProxyConfigs(configArray);
}, },
addDefaultHeaders: async (headers: {[key: string]: string}) => {} addDefaultHeaders: async (headersArg: { [key: string]: string }) => {
proxyWorkerInstance.defaultHeaders = {
...proxyWorkerInstance.defaultHeaders,
...headersArg,
};
},
}; };
export type TProxyWorkerCalls = typeof proxyWorkerCalls; export type TProxyWorkerCalls = typeof proxyWorkerCalls;