Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
bd1f1a4c1c | |||
d3bdd56660 | |||
c38a7c4c32 | |||
858628196a | |||
4910679058 | |||
97db2012ca | |||
0ee13b4e06 | |||
21f5882fa3 | |||
48b43f9f0d | |||
d3d476fd53 | |||
b80b8a0a20 | |||
384943f697 | |||
e9239ed978 | |||
baf1844866 | |||
0b3d7f8a06 | |||
c38a2745e9 | |||
a0f39d1c5b | |||
c67ac868a5 | |||
90e1a0453e | |||
d7765fb5dc | |||
0fdd17b430 | |||
0562de6aa1 | |||
7b550a35aa | |||
fb66aac6e7 | |||
208790cfcf | |||
5978bbaf66 | |||
1c47eafe5f | |||
69e3a71354 | |||
21e92bf0c1 | |||
d732e6e7aa | |||
5fdfcdb407 | |||
49e2e90bda | |||
b8e53e7b42 | |||
1136841b3d | |||
42cbc51d22 | |||
2d16403ad1 | |||
afe847499a | |||
f980bb70b4 | |||
f192a8f041 | |||
64bf3aef6d | |||
a5e3cbd05b | |||
2f0fad999a | |||
5e6477720d | |||
bad8bf0688 | |||
4f1db106fb | |||
d47829a8b2 |
19
package-lock.json
generated
19
package-lock.json
generated
@ -1,17 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "3.0.7",
|
"version": "3.0.30",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "3.0.7",
|
"version": "3.0.30",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^6.0.0",
|
"@pushrocks/lik": "^6.0.0",
|
||||||
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartrequest": "^2.0.0",
|
"@pushrocks/smartrequest": "^2.0.6",
|
||||||
"@pushrocks/smartstring": "^4.0.2",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
"@tsclass/tsclass": "^4.0.17",
|
"@tsclass/tsclass": "^4.0.17",
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
@ -1554,9 +1555,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@pushrocks/smartrequest": {
|
"node_modules/@pushrocks/smartrequest": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.6",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-2.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-2.0.6.tgz",
|
||||||
"integrity": "sha512-Xmi+2xYvy67aOMg+XO08RaIZ2QjZZonvz7lEFx5esFzu4LIbwYOzN3GEmZ6/gz9yqdGCBknUxTSLfKCO/hZgTg==",
|
"integrity": "sha512-rfE7vSr3ZrXLddCiyddU0vpL1ok0PbwL6bpd2gPNzwpCx4+q+4khQFADMKprzykRtQ4jYdKdhplJzwJGxBMI+g==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
@ -9973,9 +9974,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/smartrequest": {
|
"@pushrocks/smartrequest": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.6",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-2.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-2.0.6.tgz",
|
||||||
"integrity": "sha512-Xmi+2xYvy67aOMg+XO08RaIZ2QjZZonvz7lEFx5esFzu4LIbwYOzN3GEmZ6/gz9yqdGCBknUxTSLfKCO/hZgTg==",
|
"integrity": "sha512-rfE7vSr3ZrXLddCiyddU0vpL1ok0PbwL6bpd2gPNzwpCx4+q+4khQFADMKprzykRtQ4jYdKdhplJzwJGxBMI+g==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smarturl": "^3.0.2",
|
"@pushrocks/smarturl": "^3.0.2",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "3.0.7",
|
"version": "3.0.30",
|
||||||
"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",
|
||||||
@ -22,8 +22,9 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^6.0.0",
|
"@pushrocks/lik": "^6.0.0",
|
||||||
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartrequest": "^2.0.0",
|
"@pushrocks/smartrequest": "^2.0.6",
|
||||||
"@pushrocks/smartstring": "^4.0.2",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
"@tsclass/tsclass": "^4.0.17",
|
"@tsclass/tsclass": "^4.0.17",
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartproxy',
|
name: '@pushrocks/smartproxy',
|
||||||
version: '3.0.7',
|
version: '3.0.30',
|
||||||
description: 'a proxy for handling high workloads of proxying'
|
description: 'a proxy for handling high workloads of proxying'
|
||||||
}
|
}
|
||||||
|
@ -117,9 +117,6 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
console.log('got request');
|
|
||||||
const destinationConfig = this.router.routeReq(req);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* endRequest function
|
* endRequest function
|
||||||
* can be used to prematurely end a request
|
* can be used to prematurely end a request
|
||||||
@ -133,6 +130,15 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
res.end(messageArg);
|
res.end(messageArg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(`got request: ${req.headers.host}${plugins.url.parse(req.url).path}`);
|
||||||
|
const destinationConfig = this.router.routeReq(req);
|
||||||
|
|
||||||
|
if (!destinationConfig) {
|
||||||
|
console.log(`${req.headers.host} can't be routed properly. Terminating request.`);
|
||||||
|
endRequest();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// authentication
|
// authentication
|
||||||
if (destinationConfig.authentication) {
|
if (destinationConfig.authentication) {
|
||||||
const authInfo = destinationConfig.authentication;
|
const authInfo = destinationConfig.authentication;
|
||||||
@ -187,6 +193,15 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
req.on('end', (data) => {
|
req.on('end', (data) => {
|
||||||
request.end();
|
request.end();
|
||||||
});
|
});
|
||||||
|
req.on('error', () => {
|
||||||
|
request.end();
|
||||||
|
});
|
||||||
|
req.on('close', () => {
|
||||||
|
request.end();
|
||||||
|
});
|
||||||
|
req.on('timeout', () => {
|
||||||
|
request.end();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
res.statusCode = response.statusCode;
|
res.statusCode = response.statusCode;
|
||||||
@ -203,6 +218,16 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
response.on('end', () => {
|
response.on('end', () => {
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
|
response.on('error', () => {
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
response.on('close', () => {
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
response.on('timeout', () => {
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -210,53 +235,52 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
||||||
wss.on('connection', (ws: plugins.wsDefault) => {
|
wss.on('connection', (ws: plugins.wsDefault) => {
|
||||||
console.log('got connection for wsc');
|
console.log('got connection for wsc');
|
||||||
const wscConnected = plugins.smartpromise.defer();
|
let wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
|
||||||
|
|
||||||
const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
|
|
||||||
headers: {
|
|
||||||
Host: ws.url,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
wsc.on('open', () => {
|
|
||||||
wscConnected.resolve();
|
|
||||||
});
|
|
||||||
|
|
||||||
ws.on('message', async (message) => {
|
ws.on('message', async (message) => {
|
||||||
await wscConnected.promise;
|
if (!wscConnectedDeferred) {
|
||||||
|
wscConnectedDeferred = plugins.smartpromise.defer();
|
||||||
|
const wsc = new plugins.wsDefault(this.router.routeWs(ws), {
|
||||||
|
headers: {
|
||||||
|
Host: ws.url,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
wsc.on('open', () => {
|
||||||
|
wscConnectedDeferred.resolve(wsc);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const wsc = await wscConnectedDeferred.promise;
|
||||||
wsc.emit('message', message);
|
wsc.emit('message', message);
|
||||||
});
|
wsc.on('message', (message) => {
|
||||||
wsc.on('message', (message) => {
|
ws.emit('message', message);
|
||||||
ws.emit('message', message);
|
});
|
||||||
});
|
|
||||||
|
// handle closing
|
||||||
|
const cleanUp = () => {
|
||||||
|
ws.close();
|
||||||
|
wsc.close();
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.on('close', (message) => {
|
||||||
|
cleanUp();
|
||||||
|
});
|
||||||
|
|
||||||
// handle closing
|
wsc.on('close', (message) => {
|
||||||
const cleanUp = () => {
|
cleanUp();
|
||||||
ws.removeAllListeners();
|
});
|
||||||
ws.close();
|
|
||||||
ws.terminate();
|
|
||||||
wsc.removeAllListeners();
|
|
||||||
wsc.close();
|
|
||||||
wsc.terminate();
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.on('close', (message) => {
|
|
||||||
cleanUp();
|
|
||||||
});
|
|
||||||
wsc.on('close', (message) => {
|
|
||||||
cleanUp();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.httpsServer.keepAliveTimeout = 61000;
|
this.httpsServer.keepAliveTimeout = 61000;
|
||||||
this.httpsServer.headersTimeout = 65000;
|
this.httpsServer.headersTimeout = 65000;
|
||||||
|
|
||||||
this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
|
this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
|
||||||
connection.setTimeout(120000);
|
|
||||||
this.socketMap.add(connection);
|
this.socketMap.add(connection);
|
||||||
|
console.log(`added connection. now ${this.socketMap.getArray().length} sockets connected.`);
|
||||||
const cleanupConnection = () => {
|
const cleanupConnection = () => {
|
||||||
if (this.socketMap.checkForObject(connection)) {
|
if (this.socketMap.checkForObject(connection)) {
|
||||||
this.socketMap.remove(connection);
|
this.socketMap.remove(connection);
|
||||||
connection.end();
|
console.log(`removed connection. ${this.socketMap.getArray().length} sockets remaining.`);
|
||||||
connection.removeAllListeners();
|
|
||||||
connection.destroy();
|
connection.destroy();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -271,7 +295,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
});
|
});
|
||||||
connection.on('timeout', () => {
|
connection.on('timeout', () => {
|
||||||
cleanupConnection();
|
cleanupConnection();
|
||||||
});
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
this.httpsServer.listen(this.options.port);
|
this.httpsServer.listen(this.options.port);
|
||||||
@ -281,6 +305,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
|
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
|
||||||
|
console.log(`got new proxy configs`);
|
||||||
this.proxyConfigs = proxyConfigsArg;
|
this.proxyConfigs = proxyConfigsArg;
|
||||||
this.router.setNewProxyConfigs(proxyConfigsArg);
|
this.router.setNewProxyConfigs(proxyConfigsArg);
|
||||||
for (const hostCandidate of this.proxyConfigs) {
|
for (const hostCandidate of this.proxyConfigs) {
|
||||||
|
@ -13,11 +13,12 @@ export { tsclass };
|
|||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
import * as smartstring from '@pushrocks/smartstring';
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
|
|
||||||
export { lik, smartrequest, smartpromise, smartstring };
|
export { lik, smartdelay, smartrequest, smartpromise, smartstring };
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import * as ws from 'ws';
|
import * as ws from 'ws';
|
||||||
|
Reference in New Issue
Block a user