Change to websocket compression.

Ylian Saint-Hilaire committed Jul 10, 2020 at 00:38 UTC ab3ac1f137ad36ebc476039ed7fe1e3dcd425744
1 file changed +8 -4
webserver.js
+8 -4
@@ -4300,10 +4300,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4300
4301 // Starts the HTTPS server, this should be called after the user/mesh tables are loaded
4302 function serverStart() {
4303 + // Setup websocket options if needed.
4304 + var webSocketOptions;
4305 + if (args.wscompression === true) { webSocketOptions = { wsOptions: { perMessageDeflate: true } } }
4306 +
4307 // Start the server, only after users and meshes are loaded from the database.
4308 if (obj.args.notls || obj.args.tlsoffload) {
4309 // Setup the HTTP server without TLS
4306 - obj.expressWs = require('express-ws')(obj.app, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4310 + obj.expressWs = require('express-ws')(obj.app, webSocketOptions);
4311 } else {
4312 // Setup the HTTP server with TLS, use only TLS 1.2 and higher with perfect forward secrecy (PFS).
4313 //const tlsOptions = { cert: obj.certificates.web.cert, key: obj.certificates.web.key, ca: obj.certificates.web.ca, rejectUnauthorized: true, ciphers: "HIGH:!aNULL:!eNULL:!EXPORT:!RSA:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA", secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_COMPRESSION | constants.SSL_OP_CIPHER_SERVER_PREFERENCE | constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1 }; // This does not work with TLS 1.3
@@ -4315,7 +4319,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4319 //obj.tlsServer.on('tlsClientError', function (err) { console.log('tlsClientError', err); });
4320 obj.tlsServer.on('newSession', function (id, data, cb) { if (tlsSessionStoreCount > 1000) { tlsSessionStoreCount = 0; tlsSessionStore = {}; } tlsSessionStore[id.toString('hex')] = data; tlsSessionStoreCount++; cb(); });
4321 obj.tlsServer.on('resumeSession', function (id, cb) { cb(null, tlsSessionStore[id.toString('hex')] || null); });
4318 - obj.expressWs = require('express-ws')(obj.app, obj.tlsServer, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4322 + obj.expressWs = require('express-ws')(obj.app, obj.tlsServer, webSocketOptions);
4323 }
4324
4325 // Start a second agent-only server if needed
@@ -4328,7 +4332,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4332
4333 if (agentPortTls == false) {
4334 // Setup the HTTP server without TLS
4331 - obj.expressWsAlt = require('express-ws')(obj.agentapp, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4335 + obj.expressWsAlt = require('express-ws')(obj.agentapp, webSocketOptions);
4336 } else {
4337 // Setup the agent HTTP server with TLS, use only TLS 1.2 and higher with perfect forward secrecy (PFS).
4338 // If TLS is used on the agent port, we always use the default TLS certificate.
@@ -4339,7 +4343,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4343 //obj.tlsAltServer.on('tlsClientError', function (err) { console.log('tlsClientError', err); });
4344 obj.tlsAltServer.on('newSession', function (id, data, cb) { if (tlsSessionStoreCount > 1000) { tlsSessionStoreCount = 0; tlsSessionStore = {}; } tlsSessionStore[id.toString('hex')] = data; tlsSessionStoreCount++; cb(); });
4345 obj.tlsAltServer.on('resumeSession', function (id, cb) { cb(null, tlsSessionStore[id.toString('hex')] || null); });
4342 - obj.expressWsAlt = require('express-ws')(obj.agentapp, obj.tlsAltServer, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4346 + obj.expressWsAlt = require('express-ws')(obj.agentapp, obj.tlsAltServer, webSocketOptions);
4347 }
4348 }
4349