Bug Fixes
- Fixed: processIncomingData throwing error when using POST request - Fixed: tag/note data not working properly (getData returns an array, thus need to use result[0]) - Adding data, tag, note will return the entire data (ie, all columns) to user - Fixed: a minor syntax bug in DB.getData - Fixed: mostRecent option not giving the last record correctly
This commit is contained in:
parent
a12bd9e2a2
commit
060d3b618d
@ -19,13 +19,13 @@ function processIncomingData(data) {
|
|||||||
return reject(INVALID("Invalid Time"));
|
return reject(INVALID("Invalid Time"));
|
||||||
else {
|
else {
|
||||||
let process;
|
let process;
|
||||||
if (request in data) //Request
|
if ('request' in data) //Request
|
||||||
process = processRequestFromUser(data.request);
|
process = processRequestFromUser(data.request);
|
||||||
else if (message in data) //Store data
|
else if ('message' in data) //Store data
|
||||||
process = processDataFromUser(data);
|
process = processDataFromUser(data);
|
||||||
else if (tag in data) //Tag data
|
else if ('tag' in data) //Tag data
|
||||||
process = processTagFromUser(data);
|
process = processTagFromUser(data);
|
||||||
else if (note in data)
|
else if ('note' in data)
|
||||||
process = processNoteFromUser(data);
|
process = processNoteFromUser(data);
|
||||||
/*
|
/*
|
||||||
else if (data.edit)
|
else if (data.edit)
|
||||||
@ -63,18 +63,21 @@ function processDataFromUser(data) {
|
|||||||
return reject(INVALID("Invalid signature"));
|
return reject(INVALID("Invalid signature"));
|
||||||
|
|
||||||
DB.addData(closeNode, {
|
DB.addData(closeNode, {
|
||||||
vectorClock: `${Date.now()}_${data.senderID}`,
|
vectorClock: `${Date.now()}_${data.senderID}`,
|
||||||
senderID: data.senderID,
|
senderID: data.senderID,
|
||||||
receiverID: data.receiverID,
|
receiverID: data.receiverID,
|
||||||
time: data.time,
|
time: data.time,
|
||||||
application: data.application,
|
application: data.application,
|
||||||
type: data.type,
|
type: data.type,
|
||||||
message: data.message,
|
message: data.message,
|
||||||
comment: data.comment,
|
comment: data.comment,
|
||||||
sign: data.sign,
|
sign: data.sign,
|
||||||
pubKey: data.pubKey
|
pubKey: data.pubKey
|
||||||
}).then(result => resolve([result, 'DATA']))
|
}).then(rb => {
|
||||||
.catch(error => reject(error));
|
DB.getData(closeNode, rb.vectorClock)
|
||||||
|
.then(result => resolve([result[0], 'DATA', rb]))
|
||||||
|
.catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,6 +102,9 @@ function processTagFromUser(data) {
|
|||||||
if (!_list.serving.includes(closeNode))
|
if (!_list.serving.includes(closeNode))
|
||||||
return reject(INVALID("Incorrect Supernode"));
|
return reject(INVALID("Incorrect Supernode"));
|
||||||
DB.getData(closeNode, data.vectorClock).then(result => {
|
DB.getData(closeNode, data.vectorClock).then(result => {
|
||||||
|
if (!result.length)
|
||||||
|
return reject(INVALID("Invalid vectorClock"));
|
||||||
|
result = result[0];
|
||||||
if (!(result.application in floGlobals.appList))
|
if (!(result.application in floGlobals.appList))
|
||||||
return reject(INVALID("Application not authorised"));
|
return reject(INVALID("Application not authorised"));
|
||||||
if (!floCrypto.validateAddr(data.requestorID) ||
|
if (!floCrypto.validateAddr(data.requestorID) ||
|
||||||
@ -110,9 +116,11 @@ function processTagFromUser(data) {
|
|||||||
if (!floCrypto.verifySign(hashcontent, data.sign, data.pubKey))
|
if (!floCrypto.verifySign(hashcontent, data.sign, data.pubKey))
|
||||||
return reject(INVALID("Invalid signature"));
|
return reject(INVALID("Invalid signature"));
|
||||||
let tag = ([null, undefined, ""].includes(data.tag) ? null : data.tag.toString());
|
let tag = ([null, undefined, ""].includes(data.tag) ? null : data.tag.toString());
|
||||||
DB.tagData(closeNode, data.vectorClock, tag, data.time, data.pubKey, data.sign)
|
DB.tagData(closeNode, data.vectorClock, tag, data.time, data.pubKey, data.sign).then(rb => {
|
||||||
.then(result => resolve([result, 'TAG']))
|
DB.getData(closeNode, data.vectorClock)
|
||||||
.catch(error => reject(error));
|
.then(result => resolve([result[0], 'TAG', rb]))
|
||||||
|
.catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -125,6 +133,9 @@ function processNoteFromUser(data) {
|
|||||||
if (!_list.serving.includes(closeNode))
|
if (!_list.serving.includes(closeNode))
|
||||||
return reject(INVALID("Incorrect Supernode"));
|
return reject(INVALID("Incorrect Supernode"));
|
||||||
DB.getData(closeNode, data.vectorClock).then(result => {
|
DB.getData(closeNode, data.vectorClock).then(result => {
|
||||||
|
if (!result.length)
|
||||||
|
return reject(INVALID("Invalid vectorClock"));
|
||||||
|
result = result[0];
|
||||||
if (result.application in floGlobals.appList && floGlobals.appList[result.application] === result.receiverID) {
|
if (result.application in floGlobals.appList && floGlobals.appList[result.application] === result.receiverID) {
|
||||||
if (!floGlobals.appSubAdmins[result.application].includes(data.requestorID) && result.receiverID !== data.requestorID)
|
if (!floGlobals.appSubAdmins[result.application].includes(data.requestorID) && result.receiverID !== data.requestorID)
|
||||||
return reject(INVALID("Invalid requestorID"));
|
return reject(INVALID("Invalid requestorID"));
|
||||||
@ -136,9 +147,11 @@ function processNoteFromUser(data) {
|
|||||||
if (!floCrypto.verifySign(hashcontent, data.sign, data.pubKey))
|
if (!floCrypto.verifySign(hashcontent, data.sign, data.pubKey))
|
||||||
return reject(INVALID("Invalid signature"));
|
return reject(INVALID("Invalid signature"));
|
||||||
let note = ([null, undefined, ""].includes(data.note) ? null : data.note.toString());
|
let note = ([null, undefined, ""].includes(data.note) ? null : data.note.toString());
|
||||||
DB.noteData(closeNode, data.vectorClock, note, data.time, data.pubKey, data.sign)
|
DB.noteData(closeNode, data.vectorClock, note, data.time, data.pubKey, data.sign).then(rb => {
|
||||||
.then(result => resolve([result, 'NOTE']))
|
DB.getData(closeNode, data.vectorClock)
|
||||||
.catch(error => reject(error));
|
.then(result => resolve([result[0], 'NOTE', rb]))
|
||||||
|
.catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -227,7 +227,7 @@ function Database(user, password, dbname, host = 'localhost') {
|
|||||||
db.getData = function(snID, vectorClock) {
|
db.getData = function(snID, vectorClock) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let statement = "SELECT * FROM _" + snID +
|
let statement = "SELECT * FROM _" + snID +
|
||||||
"WHERE " + H_struct.VECTOR_CLOCK + "=?";
|
" WHERE " + H_struct.VECTOR_CLOCK + "=?";
|
||||||
db.query(statement, [vectorClock])
|
db.query(statement, [vectorClock])
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
@ -308,7 +308,8 @@ function Database(user, password, dbname, host = 'localhost') {
|
|||||||
//let statement = "SELECT " + attr.join(", ") + " FROM _" + snID +
|
//let statement = "SELECT " + attr.join(", ") + " FROM _" + snID +
|
||||||
let statement = "SELECT * FROM _" + snID +
|
let statement = "SELECT * FROM _" + snID +
|
||||||
" WHERE " + conditionArr.join(" AND ") +
|
" WHERE " + conditionArr.join(" AND ") +
|
||||||
(request.mostRecent ? " LIMIT 1" : (" ORDER BY " + H_struct.VECTOR_CLOCK));
|
" ORDER BY " + (request.afterTime ? L_struct.LOG_TIME : H_struct.VECTOR_CLOCK) +
|
||||||
|
(request.mostRecent ? " DESC LIMIT 1" : "");
|
||||||
db.query(statement)
|
db.query(statement)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
|
|||||||
@ -40,7 +40,7 @@ module.exports = function Server(port, client, intra) {
|
|||||||
refresher.countdown;
|
refresher.countdown;
|
||||||
if (['DATA', 'TAG', 'NOTE'].includes(result[1]))
|
if (['DATA', 'TAG', 'NOTE'].includes(result[1]))
|
||||||
sendToLiveRequests(result[0]);
|
sendToLiveRequests(result[0]);
|
||||||
intra.forwardToNextNode(result[1], result[0]);
|
intra.forwardToNextNode(result[2], result[0]);
|
||||||
};
|
};
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
if (error instanceof INVALID)
|
if (error instanceof INVALID)
|
||||||
@ -87,7 +87,7 @@ module.exports = function Server(port, client, intra) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
//console.error(error);
|
||||||
if (floGlobals.sn_config.errorFeedback)
|
if (floGlobals.sn_config.errorFeedback)
|
||||||
ws.send(`${INVALID_E_CODE}: Request not in JSON format`);
|
ws.send(`${INVALID_E_CODE}: Request not in JSON format`);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user