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"));
|
||||
else {
|
||||
let process;
|
||||
if (request in data) //Request
|
||||
if ('request' in data) //Request
|
||||
process = processRequestFromUser(data.request);
|
||||
else if (message in data) //Store data
|
||||
else if ('message' in data) //Store data
|
||||
process = processDataFromUser(data);
|
||||
else if (tag in data) //Tag data
|
||||
else if ('tag' in data) //Tag data
|
||||
process = processTagFromUser(data);
|
||||
else if (note in data)
|
||||
else if ('note' in data)
|
||||
process = processNoteFromUser(data);
|
||||
/*
|
||||
else if (data.edit)
|
||||
@ -63,18 +63,21 @@ function processDataFromUser(data) {
|
||||
return reject(INVALID("Invalid signature"));
|
||||
|
||||
DB.addData(closeNode, {
|
||||
vectorClock: `${Date.now()}_${data.senderID}`,
|
||||
senderID: data.senderID,
|
||||
receiverID: data.receiverID,
|
||||
time: data.time,
|
||||
application: data.application,
|
||||
type: data.type,
|
||||
message: data.message,
|
||||
comment: data.comment,
|
||||
sign: data.sign,
|
||||
pubKey: data.pubKey
|
||||
}).then(result => resolve([result, 'DATA']))
|
||||
.catch(error => reject(error));
|
||||
vectorClock: `${Date.now()}_${data.senderID}`,
|
||||
senderID: data.senderID,
|
||||
receiverID: data.receiverID,
|
||||
time: data.time,
|
||||
application: data.application,
|
||||
type: data.type,
|
||||
message: data.message,
|
||||
comment: data.comment,
|
||||
sign: data.sign,
|
||||
pubKey: data.pubKey
|
||||
}).then(rb => {
|
||||
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))
|
||||
return reject(INVALID("Incorrect Supernode"));
|
||||
DB.getData(closeNode, data.vectorClock).then(result => {
|
||||
if (!result.length)
|
||||
return reject(INVALID("Invalid vectorClock"));
|
||||
result = result[0];
|
||||
if (!(result.application in floGlobals.appList))
|
||||
return reject(INVALID("Application not authorised"));
|
||||
if (!floCrypto.validateAddr(data.requestorID) ||
|
||||
@ -110,9 +116,11 @@ function processTagFromUser(data) {
|
||||
if (!floCrypto.verifySign(hashcontent, data.sign, data.pubKey))
|
||||
return reject(INVALID("Invalid signature"));
|
||||
let tag = ([null, undefined, ""].includes(data.tag) ? null : data.tag.toString());
|
||||
DB.tagData(closeNode, data.vectorClock, tag, data.time, data.pubKey, data.sign)
|
||||
.then(result => resolve([result, 'TAG']))
|
||||
.catch(error => reject(error));
|
||||
DB.tagData(closeNode, data.vectorClock, tag, data.time, data.pubKey, data.sign).then(rb => {
|
||||
DB.getData(closeNode, data.vectorClock)
|
||||
.then(result => resolve([result[0], 'TAG', rb]))
|
||||
.catch(error => reject(error))
|
||||
}).catch(error => reject(error))
|
||||
}).catch(error => reject(error))
|
||||
});
|
||||
};
|
||||
@ -125,6 +133,9 @@ function processNoteFromUser(data) {
|
||||
if (!_list.serving.includes(closeNode))
|
||||
return reject(INVALID("Incorrect Supernode"));
|
||||
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 (!floGlobals.appSubAdmins[result.application].includes(data.requestorID) && result.receiverID !== data.requestorID)
|
||||
return reject(INVALID("Invalid requestorID"));
|
||||
@ -136,9 +147,11 @@ function processNoteFromUser(data) {
|
||||
if (!floCrypto.verifySign(hashcontent, data.sign, data.pubKey))
|
||||
return reject(INVALID("Invalid signature"));
|
||||
let note = ([null, undefined, ""].includes(data.note) ? null : data.note.toString());
|
||||
DB.noteData(closeNode, data.vectorClock, note, data.time, data.pubKey, data.sign)
|
||||
.then(result => resolve([result, 'NOTE']))
|
||||
.catch(error => reject(error));
|
||||
DB.noteData(closeNode, data.vectorClock, note, data.time, data.pubKey, data.sign).then(rb => {
|
||||
DB.getData(closeNode, data.vectorClock)
|
||||
.then(result => resolve([result[0], 'NOTE', rb]))
|
||||
.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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let statement = "SELECT * FROM _" + snID +
|
||||
"WHERE " + H_struct.VECTOR_CLOCK + "=?";
|
||||
" WHERE " + H_struct.VECTOR_CLOCK + "=?";
|
||||
db.query(statement, [vectorClock])
|
||||
.then(result => resolve(result))
|
||||
.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 * FROM _" + snID +
|
||||
" 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)
|
||||
.then(result => resolve(result))
|
||||
.catch(error => reject(error));
|
||||
|
||||
@ -40,7 +40,7 @@ module.exports = function Server(port, client, intra) {
|
||||
refresher.countdown;
|
||||
if (['DATA', 'TAG', 'NOTE'].includes(result[1]))
|
||||
sendToLiveRequests(result[0]);
|
||||
intra.forwardToNextNode(result[1], result[0]);
|
||||
intra.forwardToNextNode(result[2], result[0]);
|
||||
};
|
||||
}).catch(error => {
|
||||
if (error instanceof INVALID)
|
||||
@ -87,7 +87,7 @@ module.exports = function Server(port, client, intra) {
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
//console.error(error);
|
||||
if (floGlobals.sn_config.errorFeedback)
|
||||
ws.send(`${INVALID_E_CODE}: Request not in JSON format`);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user