Added support for compressed MeshCore.js

This commit is contained in:
Ylian Saint-Hilaire 2020-07-17 11:14:24 -07:00
parent fddf83ae0a
commit 1edb8f9662
30 changed files with 12 additions and 4 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -175,9 +175,11 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
parent.agentStats.clearingCoreCount++;
parent.parent.debug('agent', "Clearing core");
} else {
// Update new core
//obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0) + meshcorehash + parent.parent.defaultMeshCores[corename]); // MeshCommand_CoreModule, start core update
//parent.parent.debug('agent', 'Updating code ' + corename);
// Setup task limiter options, this system limits how many tasks can run at the same time to spread the server load.
var taskLimiterOptions = { hash: meshcorehash, core: parent.parent.defaultMeshCores[corename], name: corename };
// If the agent supports compression, sent the core compressed.
if ((obj.agentInfo.capabilities & 0x80) && (parent.parent.defaultMeshCoresDeflate[corename])) { args.core = parent.parent.defaultMeshCoresDeflate[corename]; }
// Update new core with task limiting so not to flood the server. This is a high priority task.
obj.agentCoreUpdatePending = true;
@ -193,7 +195,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
// This agent is probably disconnected, nothing to do.
parent.parent.taskLimiter.completed(taskid);
}
}, { hash: meshcorehash, core: parent.parent.defaultMeshCores[corename], name: corename }, 0);
}, taskLimiterOptions, 0);
}
obj.agentCoreCheck++;
}

View File

@ -55,6 +55,7 @@ function CreateMeshCentralServer(config, args) {
obj.certificateOperations = null;
obj.defaultMeshCmd = null;
obj.defaultMeshCores = {};
obj.defaultMeshCoresDeflate = {};
obj.defaultMeshCoresHash = {};
obj.meshAgentBinaries = {}; // Mesh Agent Binaries, Architecture type --> { hash:(sha384 hash), size:(binary size), path:(binary path) }
obj.meshAgentInstallScripts = {}; // Mesh Install Scripts, Script ID -- { hash:(sha384 hash), size:(binary size), path:(binary path) }
@ -1992,6 +1993,11 @@ function CreateMeshCentralServer(config, args) {
obj.debug('main', 'Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes.');
//console.log('Core module ' + i + ' is ' + obj.defaultMeshCores[i].length + ' bytes.'); // DEBUG, Print the core size
//obj.fs.writeFile("C:\\temp\\" + i + ".js", obj.defaultMeshCores[i].substring(4)); // DEBUG, Write the core to file
// Compress the mesh cores with DEFLATE
var callback = function MeshCoreDeflateCb(err, buffer) { if (err == null) { obj.defaultMeshCoresDeflate[MeshCoreDeflateCb.i] = buffer; } }
callback.i = i;
require('zlib').deflate(obj.defaultMeshCores[i], { level: require('zlib').Z_BEST_COMPRESSION }, callback);
}
}