* Use key name for configured archiver name (e.g. "zip")
* Start WIP on mesasge import/toss via schedule * Defaults for message network name
This commit is contained in:
parent
1a6af18801
commit
662d3f232e
|
@ -75,7 +75,7 @@ module.exports = class ArchiveUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// return first match
|
// return first match
|
||||||
const detected = _.find(this.archivers, arch => {
|
const detected = _.findKey(this.archivers, arch => {
|
||||||
const lenNeeded = arch.offset + arch.sig.length;
|
const lenNeeded = arch.offset + arch.sig.length;
|
||||||
|
|
||||||
if(buf.length < lenNeeded) {
|
if(buf.length < lenNeeded) {
|
||||||
|
|
|
@ -211,7 +211,6 @@ function getDefaultConfig() {
|
||||||
|
|
||||||
archivers : {
|
archivers : {
|
||||||
zip : {
|
zip : {
|
||||||
name : "PKZip", // :TODO: Use key for this
|
|
||||||
sig : "504b0304",
|
sig : "504b0304",
|
||||||
offset : 0,
|
offset : 0,
|
||||||
compressCmd : "7z",
|
compressCmd : "7z",
|
||||||
|
|
|
@ -69,8 +69,7 @@ function loadModulesForCategory(category, iterator, complete) {
|
||||||
|
|
||||||
fs.readdir(Config.paths[category], (err, files) => {
|
fs.readdir(Config.paths[category], (err, files) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
iterator(err);
|
return iterator(err);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsModules = files.filter(file => {
|
const jsModules = files.filter(file => {
|
||||||
|
|
|
@ -55,8 +55,20 @@ function FTNMessageScanTossModule() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getDefaultNetworkName = function() {
|
||||||
|
if(this.moduleConfig.defaultNetwork) {
|
||||||
|
return this.moduleConfig.defaultNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
|
const networkNames = Object.keys(Config.messageNetworks.ftn.networks);
|
||||||
|
if(1 === networkNames.length) {
|
||||||
|
return networkNames[0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.isDefaultDomainZone = function(networkName, address) {
|
this.isDefaultDomainZone = function(networkName, address) {
|
||||||
return(networkName === this.moduleConfig.defaultNetwork && address.zone === this.moduleConfig.defaultZone);
|
const defaultNetworkName = this.getDefaultNetworkName();
|
||||||
|
return(networkName === defaultNetworkName && address.zone === this.moduleConfig.defaultZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getOutgoingPacketDir = function(networkName, destAddress) {
|
this.getOutgoingPacketDir = function(networkName, destAddress) {
|
||||||
|
@ -288,6 +300,8 @@ function FTNMessageScanTossModule() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// :TODO: need to check more!
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -318,9 +332,6 @@ function FTNMessageScanTossModule() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.performImport = function() {
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getAreaLastScanId = function(areaTag, cb) {
|
this.getAreaLastScanId = function(areaTag, cb) {
|
||||||
const sql =
|
const sql =
|
||||||
`SELECT area_tag, message_id
|
`SELECT area_tag, message_id
|
||||||
|
@ -576,6 +587,43 @@ function FTNMessageScanTossModule() {
|
||||||
);
|
);
|
||||||
}, cb); // complete
|
}, cb); // complete
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.importMessagesFromDirectory = function(importDir, cb) {
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
function getPossibleFiles(callback) {
|
||||||
|
fs.readdir(importDir, (err, files) => {
|
||||||
|
callback(err, files);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function identify(files, callback) {
|
||||||
|
async.map(files, (f, transform) => {
|
||||||
|
let entry = { file : f };
|
||||||
|
|
||||||
|
if('.pkt' === paths.extname(f)) {
|
||||||
|
entry.type = 'packet';
|
||||||
|
transform(null, entry);
|
||||||
|
} else {
|
||||||
|
const fullPath = paths.join(importDir, f);
|
||||||
|
self.archUtil.detectType(fullPath, (err, archName) => {
|
||||||
|
entry.type = archName;
|
||||||
|
transform(null, entry);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, (err, identifiedFiles) => {
|
||||||
|
callback(err, identifiedFiles);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function importPacketFiles(identifiedFiles, callback) {
|
||||||
|
|
||||||
|
}
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require('util').inherits(FTNMessageScanTossModule, MessageScanTossModule);
|
require('util').inherits(FTNMessageScanTossModule, MessageScanTossModule);
|
||||||
|
@ -592,7 +640,7 @@ FTNMessageScanTossModule.prototype.startup = function(cb) {
|
||||||
if(!exporting) {
|
if(!exporting) {
|
||||||
exporting = true;
|
exporting = true;
|
||||||
|
|
||||||
Log.info( { module : exports.moduleInfo.name }, 'Performing scheduled message export...');
|
Log.info( { module : exports.moduleInfo.name }, 'Performing scheduled message scan/export...');
|
||||||
|
|
||||||
this.performExport(err => {
|
this.performExport(err => {
|
||||||
exporting = false;
|
exporting = false;
|
||||||
|
@ -605,6 +653,24 @@ FTNMessageScanTossModule.prototype.startup = function(cb) {
|
||||||
// :TODO: monitor file for changes/existance with gaze
|
// :TODO: monitor file for changes/existance with gaze
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const importSchedule = this.parseScheduleString(this.moduleConfig.schedule.import);
|
||||||
|
if(importSchedule) {
|
||||||
|
if(importSchedule.sched) {
|
||||||
|
let importing = false;
|
||||||
|
this.importTimer = later.setInterval( () => {
|
||||||
|
if(!importing) {
|
||||||
|
importing = true;
|
||||||
|
|
||||||
|
Log.info( { module : exports.moduleInfo.name }, 'Performing scheduled message import/toss...');
|
||||||
|
|
||||||
|
this.performImport(err => {
|
||||||
|
importing = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, importSchedule.sched);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FTNMessageScanTossModule.super_.prototype.startup.call(this, cb);
|
FTNMessageScanTossModule.super_.prototype.startup.call(this, cb);
|
||||||
|
@ -620,13 +686,28 @@ FTNMessageScanTossModule.prototype.shutdown = function(cb) {
|
||||||
FTNMessageScanTossModule.super_.prototype.shutdown.call(this, cb);
|
FTNMessageScanTossModule.super_.prototype.shutdown.call(this, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FTNMessageScanTossModule.prototype.performImport = function(cb) {
|
||||||
|
if(!this.hasValidConfiguration()) {
|
||||||
|
return cb(new Error('Missing or invalid configuration'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
async.each( [ 'inbound', 'secInbound' ], (importDir, nextDir) => {
|
||||||
|
self.importMessagesFromDirectory(self.moduleConfig.paths[importDir], err => {
|
||||||
|
|
||||||
|
nextDir();
|
||||||
|
});
|
||||||
|
}, cb);
|
||||||
|
};
|
||||||
|
|
||||||
FTNMessageScanTossModule.prototype.performExport = function(cb) {
|
FTNMessageScanTossModule.prototype.performExport = function(cb) {
|
||||||
//
|
//
|
||||||
// We're only concerned with areas related to FTN. For each area, loop though
|
// We're only concerned with areas related to FTN. For each area, loop though
|
||||||
// and let's find out what messages need exported.
|
// and let's find out what messages need exported.
|
||||||
//
|
//
|
||||||
if(!this.hasValidConfiguration()) {
|
if(!this.hasValidConfiguration()) {
|
||||||
return cb(new Error('No valid configurations for export'));
|
return cb(new Error('Missing or invalid configuration'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const getNewUuidsSql =
|
const getNewUuidsSql =
|
||||||
|
@ -668,9 +749,15 @@ FTNMessageScanTossModule.prototype.performExport = function(cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function exportToConfiguredUplinks(msgRows, callback) {
|
function exportToConfiguredUplinks(msgRows, callback) {
|
||||||
const uuidsOnly = msgRows.map(r => r.message_uuid); // conver to array of UUIDs only
|
const uuidsOnly = msgRows.map(r => r.message_uuid); // convert to array of UUIDs only
|
||||||
self.exportMessagesToUplinks(uuidsOnly, areaConfig, err => {
|
self.exportMessagesToUplinks(uuidsOnly, areaConfig, err => {
|
||||||
callback(err, msgRows[msgRows.length - 1].message_id);
|
const newLastScanId = msgRows[msgRows.length - 1].message_id;
|
||||||
|
|
||||||
|
Log.info(
|
||||||
|
{ messagesExported : msgRows.length, newLastScanId : newLastScanId },
|
||||||
|
'Export complete');
|
||||||
|
|
||||||
|
callback(err, newLastScanId);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function updateLastScanId(newLastScanId, callback) {
|
function updateLastScanId(newLastScanId, callback) {
|
||||||
|
|
Loading…
Reference in New Issue