Child Node Framework Update : clean up
parent
ffbfd57f27
commit
a907887f8c
|
|
@ -11,6 +11,7 @@ module.exports = function(s,config,lang,app,io){
|
|||
config.childNodes.mode === 'master'
|
||||
){
|
||||
const {
|
||||
getIpAddress,
|
||||
initiateDataConnection,
|
||||
initiateVideoTransferConnection,
|
||||
onWebSocketDataFromChildNode,
|
||||
|
|
@ -51,14 +52,15 @@ module.exports = function(s,config,lang,app,io){
|
|||
//child Node Websocket
|
||||
childNodeWebsocket.on('connection', function (client, req) {
|
||||
//functions for dispersing work to child servers;
|
||||
console.log('Connection to ws 8288')
|
||||
const ipAddress = getIpAddress(req)
|
||||
const connectionId = s.gid(10);
|
||||
s.debugLog('Child Node Connection!',new Date(),ipAddress)
|
||||
client.id = connectionId;
|
||||
function onAuthenticate(d){
|
||||
const data = JSON.parse(d);
|
||||
const childNodeKeyAccepted = config.childNodes.key.indexOf(data.socketKey) > -1;
|
||||
if(!client.shinobiChildAlreadyRegistered && data.f === 'init' && childNodeKeyAccepted){
|
||||
const connectionAddress = initiateDataConnection(client,req,data,connectionId);
|
||||
initiateDataConnection(client,req,data,connectionId);
|
||||
childNodesConnectionIndex[connectionId] = client;
|
||||
client.removeListener('message',onAuthenticate)
|
||||
client.on('message',(d) => {
|
||||
|
|
@ -66,6 +68,7 @@ module.exports = function(s,config,lang,app,io){
|
|||
onWebSocketDataFromChildNode(client,data)
|
||||
})
|
||||
}else{
|
||||
s.debugLog('Child Node Force Disconnected!',new Date(),ipAddress)
|
||||
client.destroy()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,20 +7,21 @@ module.exports = function(s,config,lang,app,io){
|
|||
req.connection.remoteAddress).replace('::ffff:','');
|
||||
}
|
||||
function initiateDataConnection(client,req,options,connectionId){
|
||||
const ipAddress = getIpAddress(req) + ':' + options.port
|
||||
client.ip = ipAddress;
|
||||
const ipAddress = getIpAddress(req)
|
||||
const webAddress = ipAddress + ':' + options.port
|
||||
client.ip = webAddress;
|
||||
client.shinobiChildAlreadyRegistered = true;
|
||||
client.sendJson = (data) => {
|
||||
client.send(JSON.stringify(data))
|
||||
}
|
||||
if(!s.childNodes[ipAddress]){
|
||||
s.childNodes[ipAddress] = {}
|
||||
if(!s.childNodes[webAddress]){
|
||||
s.childNodes[webAddress] = {}
|
||||
};
|
||||
const activeNode = s.childNodes[ipAddress];
|
||||
const activeNode = s.childNodes[webAddress];
|
||||
activeNode.dead = false
|
||||
activeNode.cnid = client.id
|
||||
activeNode.cpu = 0
|
||||
activeNode.ip = ipAddress
|
||||
activeNode.ip = webAddress
|
||||
activeNode.activeCameras = {}
|
||||
options.availableHWAccels.forEach(function(accel){
|
||||
if(config.availableHWAccels.indexOf(accel) === -1)config.availableHWAccels.push(accel)
|
||||
|
|
@ -31,15 +32,15 @@ module.exports = function(s,config,lang,app,io){
|
|||
connectionId: connectionId,
|
||||
})
|
||||
activeNode.coreCount = options.coreCount
|
||||
console.log('Initiated Child Node : ', ipAddress)
|
||||
return ipAddress
|
||||
s.debugLog('Authenticated Child Node!',new Date(),webAddress)
|
||||
return webAddress
|
||||
}
|
||||
function onWebSocketDataFromChildNode(client,data){
|
||||
const activeMonitor = data.ke && data.mid && s.group[data.ke] ? s.group[data.ke].activeMonitors[data.mid] : null;
|
||||
const ipAddress = client.ip;
|
||||
const webAddress = client.ip;
|
||||
switch(data.f){
|
||||
case'cpu':
|
||||
s.childNodes[ipAddress].cpu = data.cpu;
|
||||
s.childNodes[webAddress].cpu = data.cpu;
|
||||
break;
|
||||
case'sql':
|
||||
s.sqlQuery(data.query,data.values,function(err,rows){
|
||||
|
|
@ -52,7 +53,7 @@ module.exports = function(s,config,lang,app,io){
|
|||
});
|
||||
break;
|
||||
case'clearCameraFromActiveList':
|
||||
if(s.childNodes[ipAddress])delete(s.childNodes[ipAddress].activeCameras[data.ke + data.id])
|
||||
if(s.childNodes[webAddress])delete(s.childNodes[webAddress].activeCameras[data.ke + data.id])
|
||||
break;
|
||||
case'camera':
|
||||
s.camera(data.mode,data.data)
|
||||
|
|
@ -67,10 +68,10 @@ module.exports = function(s,config,lang,app,io){
|
|||
}
|
||||
}
|
||||
function onDataConnectionDisconnect(client, req){
|
||||
const ipAddress = client.ip;
|
||||
console.log('childNodeWebsocket.disconnect',ipAddress)
|
||||
if(s.childNodes[ipAddress]){
|
||||
var monitors = Object.values(s.childNodes[ipAddress].activeCameras)
|
||||
const webAddress = client.ip;
|
||||
console.log('childNodeWebsocket.disconnect',webAddress)
|
||||
if(s.childNodes[webAddress]){
|
||||
var monitors = Object.values(s.childNodes[webAddress].activeCameras)
|
||||
if(monitors && monitors[0]){
|
||||
var loadCompleted = 0
|
||||
var loadMonitor = function(monitor){
|
||||
|
|
@ -91,8 +92,8 @@ module.exports = function(s,config,lang,app,io){
|
|||
}
|
||||
loadMonitor(monitors[loadCompleted])
|
||||
}
|
||||
s.childNodes[ipAddress].activeCameras = {}
|
||||
s.childNodes[ipAddress].dead = true
|
||||
s.childNodes[webAddress].activeCameras = {}
|
||||
s.childNodes[webAddress].dead = true
|
||||
}
|
||||
}
|
||||
function initiateFileWriteFromChildNode(client,data,connectionId,onFinish){
|
||||
|
|
@ -208,6 +209,7 @@ module.exports = function(s,config,lang,app,io){
|
|||
})
|
||||
}
|
||||
return {
|
||||
getIpAddress,
|
||||
initiateDataConnection,
|
||||
onWebSocketDataFromChildNode,
|
||||
onDataConnectionDisconnect,
|
||||
|
|
|
|||
Loading…
Reference in New Issue