bug fix
This commit is contained in:
parent
a91df8a2b2
commit
685a383c8e
@ -18,7 +18,7 @@ function processIncomingData(data) {
|
||||
else if (data.message) //Store data
|
||||
process = processDataFromUser(data);
|
||||
else if (data) //Tag data
|
||||
process = processTagFromUser(gid, uid, data);
|
||||
process = processTagFromUser(data);
|
||||
/*
|
||||
else if (data.edit)
|
||||
return processEditFromUser(gid, uid, data);
|
||||
@ -27,8 +27,13 @@ function processIncomingData(data) {
|
||||
*/
|
||||
else
|
||||
return reject("Invalid Data-format");
|
||||
process.then(result => resolve(result))
|
||||
.catch(error => reject(error));
|
||||
process.then(result => {
|
||||
console.log(result);
|
||||
resolve(result);
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@ -57,6 +57,7 @@ const T_struct = {
|
||||
function Database(user, password, dbname, host = 'localhost') {
|
||||
const db = {};
|
||||
db.query = (s, v) => new Promise((res, rej) => {
|
||||
//console.log("\nSQL:",s, v);
|
||||
const fn = ((e, r) => e ? rej(e) : res(r));
|
||||
v ? db.conn.query(s, v, fn) : db.conn.query(s, fn);
|
||||
});
|
||||
@ -172,14 +173,14 @@ function Database(user, password, dbname, host = 'localhost') {
|
||||
H_struct.APPLICATION + " TINYTEXT NOT NULL, " +
|
||||
H_struct.TYPE + " TINYTEXT, " +
|
||||
B_struct.MESSAGE + " TEXT NOT NULL, " +
|
||||
B_struct.TIME + " INT NOT NULL, " +
|
||||
H_struct.TIME + " BIGINT NOT NULL, " +
|
||||
B_struct.SIGNATURE + " VARCHAR(160) NOT NULL, " +
|
||||
B_struct.PUB_KEY + " CHAR(66) NOT NULL, " +
|
||||
H_struct.PUB_KEY + " CHAR(66) NOT NULL, " +
|
||||
B_struct.COMMENT + " TINYTEXT, " +
|
||||
L_struct.STATUS + " INT NOT NULL, " +
|
||||
L_struct.LOG_TIME + " INT NOT NULL, " +
|
||||
L_struct.LOG_TIME + " BIGINT NOT NULL, " +
|
||||
T_struct.TAG + " TINYTEXT, " +
|
||||
T_struct.TAG_TIME + " INT, " +
|
||||
T_struct.TAG_TIME + " BIGINT, " +
|
||||
T_struct.TAG_KEY + " CHAR(66), " +
|
||||
T_struct.TAG_SIGN + " VARCHAR(160), " +
|
||||
"PRIMARY KEY (" + H_struct.VECTOR_CLOCK + ")" +
|
||||
@ -201,7 +202,7 @@ function Database(user, password, dbname, host = 'localhost') {
|
||||
|
||||
db.addData = function(snID, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let attr = Object.keys(H_struct).map(a => H_struct[a]);
|
||||
let attr = Object.keys(H_struct).map(a => H_struct[a]).concat(Object.keys(B_struct).map(a => B_struct[a]));
|
||||
let values = attr.map(a => data[a]);
|
||||
let statement = "INSERT INTO _" + snID +
|
||||
" (" + attr.join(", ") + ", " + L_struct.STATUS + ", " + L_struct.LOG_TIME + ") " +
|
||||
@ -260,11 +261,11 @@ function Database(user, password, dbname, host = 'localhost') {
|
||||
conditionArr.push(`${H_struct.SENDER_ID} = '${request.senderID}'`);
|
||||
};
|
||||
//console.log(conditionArr);
|
||||
let attr = Object.keys(H_struct).concat(Object.keys(B_struct));
|
||||
let statement = "SELECT (" + attr.join(", ") + ")" +
|
||||
let attr = Object.keys(H_struct).map(a => H_struct[a]).concat(Object.keys(B_struct).map(a => B_struct[a]));
|
||||
let statement = "SELECT " + attr.join(", ") +
|
||||
" FROM _" + snID +
|
||||
" WHERE " + conditionArr.join(" AND ") +
|
||||
request.mostRecent ? "LIMIT 1" : (" ORDER BY " + H_struct.VECTOR_CLOCK);
|
||||
(request.mostRecent ? " LIMIT 1" : (" ORDER BY " + H_struct.VECTOR_CLOCK));
|
||||
db.query(statement)
|
||||
.then(result => resolve(result))
|
||||
.catch(error => reject(error));
|
||||
|
||||
@ -180,7 +180,7 @@ function connectToActiveNode(snID, reverse = false) {
|
||||
//Connect to next available node
|
||||
function connectToNextNode() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let nextNodeID = kBucket.nextNode(nodeID);
|
||||
let nextNodeID = kBucket.nextNode(myFloID);
|
||||
connectToActiveNode(nextNodeID).then(ws => {
|
||||
_nextNode.set(nextNodeID, ws);
|
||||
_nextNode.send(packet_.constuct({
|
||||
@ -410,12 +410,13 @@ function handshakeEnd() {
|
||||
|
||||
//Reconnect to next available node
|
||||
function reconnectNextNode() {
|
||||
_nextNode.close();
|
||||
if(_nextNode.ws)
|
||||
_nextNode.close();
|
||||
connectToNextNode()
|
||||
.then(result => console.log(result))
|
||||
.catch(error => {
|
||||
//Case: No other node is online
|
||||
console.error(error);
|
||||
console.info("No other node online");
|
||||
//Serve all nodes
|
||||
for (let sn in floGlobals.supernodes)
|
||||
DB.createTable(sn)
|
||||
|
||||
@ -12,7 +12,7 @@ module.exports = function Server(port, client, intra) {
|
||||
let u = url.parse(req.url, true);
|
||||
if (!u.search)
|
||||
return res.end("");
|
||||
console.log(u.search);
|
||||
console.log("GET:", u.search);
|
||||
client.processRequestFromUser(u.query)
|
||||
.then(result => res.end(JSON.stringify(result[0])))
|
||||
.catch(error => res.end(error.toString()));
|
||||
@ -21,7 +21,7 @@ module.exports = function Server(port, client, intra) {
|
||||
let data = '';
|
||||
req.on('data', chunk => data += chunk);
|
||||
req.on('end', () => {
|
||||
console.log(data);
|
||||
console.log("POST:", data);
|
||||
//process the data storing
|
||||
client.processIncomingData(data).then(result => {
|
||||
res.end(JSON.stringify(result[0]));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user