Mark feature
Changes required for mark feature
This commit is contained in:
parent
0398de34fd
commit
f6c9e95dce
117
app/index.html
117
app/index.html
@ -8064,6 +8064,8 @@ Bitcoin.Util = {
|
|||||||
processRequestFromUser(gid, uid, data);
|
processRequestFromUser(gid, uid, data);
|
||||||
else if (data.message)
|
else if (data.message)
|
||||||
processDataFromUser(gid, uid, data);
|
processDataFromUser(gid, uid, data);
|
||||||
|
else if (data.mark)
|
||||||
|
processMarkFromUser(gid, uid, data);
|
||||||
else if (data.delete)
|
else if (data.delete)
|
||||||
processDeleteFromUser(gid, uid, data);
|
processDeleteFromUser(gid, uid, data);
|
||||||
else
|
else
|
||||||
@ -8134,7 +8136,8 @@ Bitcoin.Util = {
|
|||||||
sign: data.sign,
|
sign: data.sign,
|
||||||
application: data.application,
|
application: data.application,
|
||||||
type: data.type,
|
type: data.type,
|
||||||
comment: data.comment
|
comment: data.comment,
|
||||||
|
marked: false
|
||||||
}
|
}
|
||||||
compactIDB.addData(value.application in floGlobals.appList ? value.application :
|
compactIDB.addData(value.application in floGlobals.appList ? value.application :
|
||||||
floGlobals.defaultDisk, value, key, `SN_${closeNode}`).then(result => {
|
floGlobals.defaultDisk, value, key, `SN_${closeNode}`).then(result => {
|
||||||
@ -8146,6 +8149,42 @@ Bitcoin.Util = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processMarkFromUser(gid, uid, data) {
|
||||||
|
if (!floCrypto.validateAddr(data.receiverID))
|
||||||
|
throw Error("Invalid requestorID")
|
||||||
|
if (!(data.application in floGlobals.appList))
|
||||||
|
throw Error("Invalid application")
|
||||||
|
if (!floCrypto.validateAddr(data.requestorID) ||
|
||||||
|
!floGlobals.appSubAdmins.includes(data.requestorID))
|
||||||
|
throw Error("Invalid requestorID")
|
||||||
|
let closeNode = floSupernode.kBucket.closestNode(data.receiverID)
|
||||||
|
if (!floGlobals.serveList.includes(closeNode))
|
||||||
|
throw Error("Incorrect Supernode")
|
||||||
|
if (data.requestorID !== floCrypto.getFloID(data.pubKey))
|
||||||
|
throw Error("Invalid pubKey")
|
||||||
|
let hashcontent = ["time", "application"]
|
||||||
|
.map(d => data[d]).join("|") + JSON.stringify(data.mark)
|
||||||
|
if (!floCrypto.verifySign(hashcontent, data.sign, data.pubKey))
|
||||||
|
throw Error("Invalid signature")
|
||||||
|
let disk = data.application
|
||||||
|
const markData = (vc, m) => new Promise((res, rej) => {
|
||||||
|
compactIDB.readData(disk, vc, `SN_${closeNode}`).then(d => {
|
||||||
|
d.marked = m;
|
||||||
|
compactIDB.writeData(disk, d, vc, `SN_${closeNode}`)
|
||||||
|
.then(r => res(vc))
|
||||||
|
.catch(e => rej(vc))
|
||||||
|
}).catch(e => rej(vc))
|
||||||
|
})
|
||||||
|
Promise.allSettled(Object.keys(data.mark).map(vc => markData(vc, data.mark[vc])))
|
||||||
|
.then(results => {
|
||||||
|
floSupernode.supernodeClientWS.send(`@${uid}#${gid}:${JSON.stringify(results)}`)
|
||||||
|
let mark = {}
|
||||||
|
results.filter(r => r.status === 'fulfilled')
|
||||||
|
.forEach(r => mark[r.value] = data.mark[r.value])
|
||||||
|
sendBackupMark(data.application, mark, closeNode);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function processDeleteFromUser(gid, uid, data) {
|
function processDeleteFromUser(gid, uid, data) {
|
||||||
if (!floCrypto.validateAddr(data.requestorID))
|
if (!floCrypto.validateAddr(data.requestorID))
|
||||||
throw Error("Invalid requestorID")
|
throw Error("Invalid requestorID")
|
||||||
@ -8153,12 +8192,13 @@ Bitcoin.Util = {
|
|||||||
if (!floGlobals.serveList.includes(closeNode))
|
if (!floGlobals.serveList.includes(closeNode))
|
||||||
throw Error("Incorrect Supernode")
|
throw Error("Incorrect Supernode")
|
||||||
if (data.requestorID !== floCrypto.getFloID(data.pubKey))
|
if (data.requestorID !== floCrypto.getFloID(data.pubKey))
|
||||||
throw Error("Invalid senderID/pubKey")
|
throw Error("Invalid pubKey")
|
||||||
let hashcontent = ["time", "application", "delete"]
|
let hashcontent = ["time", "application", "delete"]
|
||||||
.map(d => data[d]).join("|")
|
.map(d => data[d]).join("|")
|
||||||
throw Error("Invalid signature")
|
if (!floCrypto.verifySign(hashcontent, data.sign, data.pubKey))
|
||||||
|
throw Error("Invalid signature")
|
||||||
let disk = data.application in floGlobals.appList ? data.application : floGlobals.defaultDisk;
|
let disk = data.application in floGlobals.appList ? data.application : floGlobals.defaultDisk;
|
||||||
const deleteData = v => new Promise((res, rej) => {
|
const deleteData = vc => new Promise((res, rej) => {
|
||||||
compactIDB.readData(disk, vc, `SN_${closeNode}`).then(result => {
|
compactIDB.readData(disk, vc, `SN_${closeNode}`).then(result => {
|
||||||
if (result.receiverID === data.requestorID)
|
if (result.receiverID === data.requestorID)
|
||||||
compactIDB.removeData(disk, vc, `SN_${closeNode}`)
|
compactIDB.removeData(disk, vc, `SN_${closeNode}`)
|
||||||
@ -8168,13 +8208,12 @@ Bitcoin.Util = {
|
|||||||
}).catch(e => rej(vc))
|
}).catch(e => rej(vc))
|
||||||
})
|
})
|
||||||
Promise.allSettled(data.delete.map(vc => deleteData(vc))).then(results => {
|
Promise.allSettled(data.delete.map(vc => deleteData(vc))).then(results => {
|
||||||
floSupernode.supernodeClientWS.send(`@${uid}#${gid}:${JSON.stringify(result)}`)
|
floSupernode.supernodeClientWS.send(`@${uid}#${gid}:${JSON.stringify(results)}`)
|
||||||
let vectorClocks = results
|
let vectorClocks = results
|
||||||
.filter(r => r.status === 'fulfilled')
|
.filter(r => r.status === 'fulfilled')
|
||||||
.map(r => r.value)
|
.map(r => r.value)
|
||||||
sendBackupDelete(data.application, vectorClocks, closeNode);
|
sendBackupDelete(data.application, vectorClocks, closeNode);
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script id="compactIDB">
|
<script id="compactIDB">
|
||||||
@ -8571,7 +8610,7 @@ Bitcoin.Util = {
|
|||||||
var indexesList = [
|
var indexesList = [
|
||||||
"senderID", "receiverID", "application",
|
"senderID", "receiverID", "application",
|
||||||
"type", "message", "time", "comment",
|
"type", "message", "time", "comment",
|
||||||
"pubKey", "sign"
|
"pubKey", "sign", "marked"
|
||||||
];
|
];
|
||||||
let obsList = Object.keys(floGlobals.appList).concat(floGlobals.defaultDisk)
|
let obsList = Object.keys(floGlobals.appList).concat(floGlobals.defaultDisk)
|
||||||
var idbObj = {}
|
var idbObj = {}
|
||||||
@ -8614,9 +8653,9 @@ Bitcoin.Util = {
|
|||||||
var promises = []
|
var promises = []
|
||||||
//For authorised-apps data
|
//For authorised-apps data
|
||||||
for (let app in floGlobals.appList) {
|
for (let app in floGlobals.appList) {
|
||||||
const patternEval = (k, v) => (floGlobals.appList[app] != v.receiverID ||
|
const patternEval = (k, v) => (!v.marked && (floGlobals.appList[app] != v.receiverID ||
|
||||||
(!floGlobals.appSubAdmins[app].includes(v.senderID) &&
|
(!floGlobals.appSubAdmins[app].includes(v.senderID) &&
|
||||||
floGlobals.appList[app] != v.senderID))
|
floGlobals.appList[app] != v.senderID)))
|
||||||
for (let sn of floGlobals.storedList)
|
for (let sn of floGlobals.storedList)
|
||||||
promises.push(filterDelete(app, `SN_${sn}`, {
|
promises.push(filterDelete(app, `SN_${sn}`, {
|
||||||
upperKey,
|
upperKey,
|
||||||
@ -8941,6 +8980,9 @@ Bitcoin.Util = {
|
|||||||
case "backupDelete":
|
case "backupDelete":
|
||||||
deleteBackupData(data.sn_msg)
|
deleteBackupData(data.sn_msg)
|
||||||
break;
|
break;
|
||||||
|
case "backupMark":
|
||||||
|
markBackupData(data.sn_msg)
|
||||||
|
break;
|
||||||
case "supernodeUp":
|
case "supernodeUp":
|
||||||
nodeBackOnline(data.from)
|
nodeBackOnline(data.from)
|
||||||
break;
|
break;
|
||||||
@ -8960,7 +9002,7 @@ Bitcoin.Util = {
|
|||||||
initiateRefresh()
|
initiateRefresh()
|
||||||
break;
|
break;
|
||||||
case "dataRequest":
|
case "dataRequest":
|
||||||
sendStoredData(data.sn_msg.snID, data.from, data.sn_msg.lowerKey)
|
sendStoredData(data.sn_msg.snID, data.from)
|
||||||
break;
|
break;
|
||||||
case "dataSync":
|
case "dataSync":
|
||||||
dataSyncIndication(data.sn_msg.snID, data.sn_msg.mode, data.from)
|
dataSyncIndication(data.sn_msg.snID, data.sn_msg.mode, data.from)
|
||||||
@ -9034,12 +9076,20 @@ Bitcoin.Util = {
|
|||||||
sendToBackupNodes(sn_msg);
|
sendToBackupNodes(sn_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendStoredData(snID, receiver, lowerKey) {
|
function sendBackupMark(application, mark, snID) {
|
||||||
if (typeof lowerKey != "object") lowerKey = {};
|
var sn_msg = {
|
||||||
|
type: "backupMark",
|
||||||
|
snID: snID,
|
||||||
|
time: Date.now(),
|
||||||
|
application: application,
|
||||||
|
mark: mark
|
||||||
|
}
|
||||||
|
sendToBackupNodes(sn_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendStoredData(snID, receiver) {
|
||||||
const sendObs = (obs, node) => new Promise((res, rej) => {
|
const sendObs = (obs, node) => new Promise((res, rej) => {
|
||||||
compactIDB.searchData(obs, {
|
compactIDB.readAllData(obs, `SN_${snID}`).then(result => {
|
||||||
lowerKey: lowerKey[obs]
|
|
||||||
}, `SN_${snID}`).then(result => {
|
|
||||||
for (let k in result) {
|
for (let k in result) {
|
||||||
var data = {
|
var data = {
|
||||||
from: myFloID,
|
from: myFloID,
|
||||||
@ -9090,22 +9140,15 @@ Bitcoin.Util = {
|
|||||||
function requestBackupData(from, snID) {
|
function requestBackupData(from, snID) {
|
||||||
var promises = []
|
var promises = []
|
||||||
let obsList = Object.keys(floGlobals.appList).concat(floGlobals.defaultDisk)
|
let obsList = Object.keys(floGlobals.appList).concat(floGlobals.defaultDisk)
|
||||||
for (let i in obsList)
|
Promise.all(obsList.map(o => compactIDB.clearData(o, `SN_${snID}`)))
|
||||||
promises[i] = compactIDB.searchData(obsList[i], {
|
.then(result => {
|
||||||
lastOnly: true
|
var sn_msg = {
|
||||||
}, `SN_${snID}`)
|
type: "dataRequest",
|
||||||
Promise.all(promises).then(results => {
|
snID: snID,
|
||||||
var lowerKey = {}
|
time: Date.now()
|
||||||
for (let i in results)
|
}
|
||||||
lowerKey[obsList[i]] = Object.keys(results[i]).sort().pop() + 1
|
sendToSupernode(from, sn_msg, true)
|
||||||
var sn_msg = {
|
})
|
||||||
type: "dataRequest",
|
|
||||||
snID: snID,
|
|
||||||
lowerKey: lowerKey,
|
|
||||||
time: Date.now()
|
|
||||||
}
|
|
||||||
sendToSupernode(from, sn_msg, true)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeBackupData(data) {
|
function storeBackupData(data) {
|
||||||
@ -9136,6 +9179,18 @@ Bitcoin.Util = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function markBackupData(data) {
|
||||||
|
if (floGlobals.storedList.includes(data.snID)) {
|
||||||
|
const markData = (vc, m) =>
|
||||||
|
compactIDB.readData(data.application, vc, `SN_${data.snID}`)
|
||||||
|
.then(d => {
|
||||||
|
d.marked = m;
|
||||||
|
compactIDB.writeData(data.application, d, vc, `SN_${data.snID}`)
|
||||||
|
})
|
||||||
|
Object.keys(data.mark).forEach(vc => markData(vc, data.mark[vc]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function indicateSupernodeUp() {
|
function indicateSupernodeUp() {
|
||||||
console.log("Indicating supernode is up")
|
console.log("Indicating supernode is up")
|
||||||
if (floGlobals.backupNodes.length) {
|
if (floGlobals.backupNodes.length) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user