This commit is contained in:
sairajzero 2021-07-29 16:40:55 +05:30
parent 3d3d2be6df
commit 9001b21b07
3 changed files with 30 additions and 19 deletions

View File

@ -290,7 +290,7 @@ function Database(user, password, dbname, host = 'localhost') {
db.getData = function(snID, logtime) { db.getData = function(snID, logtime) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let statement = "SELECT * FROM _" + snID + let statement = "SELECT * FROM _" + snID +
" WHERE " + L_struct.LOG_TIME + ">=" + logtime + " WHERE " + L_struct.LOG_TIME + ">" + logtime +
" ORDER BY " + L_struct.LOG_TIME; " ORDER BY " + L_struct.LOG_TIME;
db.query(statement) db.query(statement)
.then(result => resolve(result)) .then(result => resolve(result))

View File

@ -136,6 +136,7 @@ packet_.constuct = function(message) {
}; };
packet_.s = d => [JSON.stringify(d.message), d.time].join("|"); packet_.s = d => [JSON.stringify(d.message), d.time].join("|");
packet_.parse = function(str) { packet_.parse = function(str) {
try {
let packet = JSON.parse(str.substring(SUPERNODE_INDICATOR.length)); let packet = JSON.parse(str.substring(SUPERNODE_INDICATOR.length));
let curTime = Date.now(); let curTime = Date.now();
if (packet.time > curTime - floGlobals.sn_config.delayDelta && if (packet.time > curTime - floGlobals.sn_config.delayDelta &&
@ -145,6 +146,10 @@ packet_.parse = function(str) {
packet.message = [packet.message]; packet.message = [packet.message];
return packet; return packet;
}; };
} catch (error) {
console.error(str, error);
return false;
};
}; };
//-----NODE CONNECTORS (WEBSOCKET)----- //-----NODE CONNECTORS (WEBSOCKET)-----
@ -416,7 +421,7 @@ function handshakeEnd() {
//Reconnect to next available node //Reconnect to next available node
function reconnectNextNode() { function reconnectNextNode() {
if (_nextNode.ws) if (_nextNode.id)
_nextNode.close(); _nextNode.close();
connectToNextNode() connectToNextNode()
.then(result => console.log(result)) .then(result => console.log(result))

View File

@ -51,6 +51,7 @@ module.exports = function Server(port, client, intra) {
intra.processTaskFromSupernode(message, ws); intra.processTaskFromSupernode(message, ws);
else { else {
console.debug("WS: ", message); console.debug("WS: ", message);
try {
var request = JSON.parse(message); var request = JSON.parse(message);
client.processRequestFromUser(request) client.processRequestFromUser(request)
.then(result => { .then(result => {
@ -60,6 +61,11 @@ module.exports = function Server(port, client, intra) {
if (floGlobals.sn_config.errorFeedback) if (floGlobals.sn_config.errorFeedback)
ws.send(error.toString()); ws.send(error.toString());
}); });
} catch (error) {
console.error(error);
if (floGlobals.sn_config.errorFeedback)
ws.send("Request not in JSON format");
};
}; };
}; };
}); });