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