Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
ca73849541 | |||
b64523b0b2 | |||
963ad6efa4 | |||
d271029302 | |||
018fcbf71e | |||
fa04732241 | |||
da19fab8d8 | |||
8d318dca28 | |||
d03bfcc793 | |||
4ba2686977 | |||
d24c4d4b7a | |||
e1d4d6cf38 | |||
11344ac0df | |||
85fcfc3c36 |
8
package-lock.json
generated
8
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "2.0.8",
|
||||
"version": "2.0.15",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -11438,9 +11438,9 @@
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"ws": {
|
||||
"version": "7.4.2",
|
||||
"resolved": "https://verdaccio.lossless.one/ws/-/ws-7.4.2.tgz",
|
||||
"integrity": "sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA=="
|
||||
"version": "7.4.3",
|
||||
"resolved": "https://verdaccio.lossless.one/ws/-/ws-7.4.3.tgz",
|
||||
"integrity": "sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA=="
|
||||
},
|
||||
"xml-js": {
|
||||
"version": "1.6.11",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "2.0.8",
|
||||
"version": "2.0.15",
|
||||
"private": false,
|
||||
"description": "a proxy for handling high workloads of proxying",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -30,7 +30,7 @@
|
||||
"@pushrocks/smartsystem": "^2.0.9",
|
||||
"@tsclass/tsclass": "^3.0.29",
|
||||
"@types/ws": "^7.4.0",
|
||||
"ws": "^7.4.2"
|
||||
"ws": "^7.4.3"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
@ -8,6 +8,11 @@ export class ProxyWorker {
|
||||
public port = 8001;
|
||||
public router = new SmartproxyRouter();
|
||||
public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
|
||||
public defaultHeaders: { [key: string]: string } = {};
|
||||
|
||||
public alreadyAddedReverseConfigs: {
|
||||
[hostName: string]: plugins.tsclass.network.IReverseProxyConfig;
|
||||
} = {};
|
||||
|
||||
/**
|
||||
* starts the proxyInstance
|
||||
@ -161,6 +166,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
{
|
||||
method: req.method,
|
||||
headers: req.headers,
|
||||
keepAlive: true,
|
||||
},
|
||||
true, // lets make this streaming
|
||||
(request) => {
|
||||
@ -174,6 +180,9 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
);
|
||||
res.statusCode = response.statusCode;
|
||||
console.log(response.statusCode);
|
||||
for (const defaultHeader of Object.keys(this.defaultHeaders)) {
|
||||
res.setHeader(defaultHeader, this.defaultHeaders[defaultHeader]);
|
||||
}
|
||||
for (const header of Object.keys(response.headers)) {
|
||||
res.setHeader(header, response.headers[header]);
|
||||
}
|
||||
@ -210,20 +219,44 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
});
|
||||
|
||||
// handle closing
|
||||
ws.on('close', (message) => {
|
||||
const cleanUp = () => {
|
||||
ws.removeAllListeners();
|
||||
ws.close();
|
||||
ws.terminate();
|
||||
wsc.removeAllListeners();
|
||||
wsc.close();
|
||||
wsc.terminate();
|
||||
};
|
||||
|
||||
ws.on('close', (message) => {
|
||||
cleanUp();
|
||||
});
|
||||
wsc.on('close', (message) => {
|
||||
ws.close();
|
||||
cleanUp();
|
||||
});
|
||||
});
|
||||
this.httpsServer.keepAliveTimeout = 61000;
|
||||
this.httpsServer.headersTimeout = 65000;
|
||||
|
||||
this.httpsServer.on('connection', (connection) => {
|
||||
this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
|
||||
connection.setTimeout(120000);
|
||||
this.socketMap.add(connection);
|
||||
connection.on('close', () => {
|
||||
const cleanupConnection = () => {
|
||||
this.socketMap.remove(connection);
|
||||
connection.removeAllListeners();
|
||||
connection.destroy();
|
||||
};
|
||||
connection.on('close', () => {
|
||||
cleanupConnection();
|
||||
});
|
||||
connection.on('error', () => {
|
||||
cleanupConnection();
|
||||
});
|
||||
connection.on('end', () => {
|
||||
cleanupConnection();
|
||||
});
|
||||
connection.on('timeout', () => {
|
||||
cleanupConnection();
|
||||
});
|
||||
});
|
||||
|
||||
@ -236,10 +269,27 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
this.router.setNewProxyConfigs(proxyConfigsArg);
|
||||
for (const hostCandidate of this.proxyConfigs) {
|
||||
// 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, {
|
||||
cert: hostCandidate.publicKey,
|
||||
key: hostCandidate.privateKey,
|
||||
});
|
||||
this.httpsServer;
|
||||
}
|
||||
/* this.httpsServer.close();
|
||||
this.httpsServer.listen(this.port); */
|
||||
@ -270,6 +320,12 @@ const proxyWorkerCalls = {
|
||||
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;
|
||||
|
@ -45,6 +45,10 @@ export class SmartProxy {
|
||||
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);
|
||||
|
Reference in New Issue
Block a user