diff --git a/app/index.html b/app/index.html
index 4594f53..954ad3e 100644
--- a/app/index.html
+++ b/app/index.html
@@ -8064,6 +8064,8 @@ Bitcoin.Util = {
processRequestFromUser(gid, uid, data);
else if (data.message)
processDataFromUser(gid, uid, data);
+ else if (data.mark)
+ processMarkFromUser(gid, uid, data);
else if (data.delete)
processDeleteFromUser(gid, uid, data);
else
@@ -8134,7 +8136,8 @@ Bitcoin.Util = {
sign: data.sign,
application: data.application,
type: data.type,
- comment: data.comment
+ comment: data.comment,
+ marked: false
}
compactIDB.addData(value.application in floGlobals.appList ? value.application :
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) {
if (!floCrypto.validateAddr(data.requestorID))
throw Error("Invalid requestorID")
@@ -8153,12 +8192,13 @@ Bitcoin.Util = {
if (!floGlobals.serveList.includes(closeNode))
throw Error("Incorrect Supernode")
if (data.requestorID !== floCrypto.getFloID(data.pubKey))
- throw Error("Invalid senderID/pubKey")
+ throw Error("Invalid pubKey")
let hashcontent = ["time", "application", "delete"]
.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;
- const deleteData = v => new Promise((res, rej) => {
+ const deleteData = vc => new Promise((res, rej) => {
compactIDB.readData(disk, vc, `SN_${closeNode}`).then(result => {
if (result.receiverID === data.requestorID)
compactIDB.removeData(disk, vc, `SN_${closeNode}`)
@@ -8168,13 +8208,12 @@ Bitcoin.Util = {
}).catch(e => rej(vc))
})
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
.filter(r => r.status === 'fulfilled')
.map(r => r.value)
sendBackupDelete(data.application, vectorClocks, closeNode);
})
-
}