Initializing backup feature requirements
Restructuring IDB to provide more reliable storage for upcoming backup features
This commit is contained in:
parent
5e6d47a042
commit
95a3c9a127
125
index.html
125
index.html
@ -32,7 +32,10 @@
|
||||
//Required for Supernode operations
|
||||
supernodes: {}, //each supnernode must be stored as floID : {uri:<uri>,pubKey:<publicKey>}
|
||||
storageList : ["General"],
|
||||
defaultStorage : "General"
|
||||
defaultStorage : "General",
|
||||
serveList : [],
|
||||
backupStoredList : [],
|
||||
supernodeConfig : {}
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -5401,16 +5404,20 @@
|
||||
request = request.split(" ");
|
||||
requestor = request[0];
|
||||
request = JSON.parse(request[1]);
|
||||
var filterOptions = {
|
||||
lowerKey: request.lowerVectorClock,
|
||||
upperKey: request.upperVectorClock,
|
||||
lastOnly: request.mostRecent,
|
||||
atKey: request.atVectorClock,
|
||||
patternEval: (k, v) => { return (v.application == request.application && (!request.receiverID || v.receiverID == request.receiverID) && (!request.comment || v.comment == request.comment) && (!request.type || v.type == request.type) && (!request.senderIDs || request.senderIDs.includes(v.senderID))) }
|
||||
}
|
||||
compactIDB.searchData( floGlobals.storageList.includes(request.application) ? request.application : floGlobals.defaultStorage, filterOptions)
|
||||
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
|
||||
.catch(error => console.log(error))
|
||||
floSupernode.kBucket.determineClosestSupernode(data.receiverID).then(result => {
|
||||
if(floGlobals.serveList.includes(result[0].floID)){
|
||||
var filterOptions = {
|
||||
lowerKey: request.lowerVectorClock,
|
||||
upperKey: request.upperVectorClock,
|
||||
lastOnly: request.mostRecent,
|
||||
atKey: request.atVectorClock,
|
||||
patternEval: (k, v) => { return (v.application == request.application && (!request.receiverID || v.receiverID == request.receiverID) && (!request.comment || v.comment == request.comment) && (!request.type || v.type == request.type) && (!request.senderIDs || request.senderIDs.includes(v.senderID))) }
|
||||
}
|
||||
compactIDB.searchData( floGlobals.storageList.includes(request.application) ? request.application : floGlobals.defaultStorage, filterOptions, `SN_${result[0].floID}`)
|
||||
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
|
||||
.catch(error => console.log(error))
|
||||
}
|
||||
}).catch(error => console.log(error))
|
||||
} catch (error) {
|
||||
console.log(error.message)
|
||||
}
|
||||
@ -5422,26 +5429,29 @@
|
||||
console.log('Data :', data);
|
||||
try {
|
||||
data = JSON.parse(data)
|
||||
floSupernode.kBucket.determineClosestSupernode(data.receiverID).then(result => {
|
||||
if (result[0].floID == myFloID
|
||||
&& data.senderID == floCrypto.getFloIDfromPubkeyHex(data.pubKey)
|
||||
&& floCrypto.verifySign(JSON.stringify(data.message), data.sign, data.pubKey)){
|
||||
if (floGlobals.storageList.includes(data.application))
|
||||
var table = data.application;
|
||||
else
|
||||
var table = floGlobals.defaultStorage;
|
||||
compactIDB.addData(table, {
|
||||
senderID: data.senderID,
|
||||
receiverID: data.receiverID,
|
||||
pubKey: data.pubKey,
|
||||
message: data.message,
|
||||
sign: data.sign,
|
||||
application: data.application,
|
||||
type: data.type,
|
||||
comment: data.comment
|
||||
})
|
||||
}
|
||||
})
|
||||
if(!data.backup){ //Serving Users
|
||||
floSupernode.kBucket.determineClosestSupernode(data.receiverID).then(result => {
|
||||
if (floGlobals.serveList.includes(result[0].floID)
|
||||
&& data.senderID == floCrypto.getFloIDfromPubkeyHex(data.pubKey)
|
||||
&& floCrypto.verifySign(JSON.stringify(data.message), data.sign, data.pubKey)){
|
||||
if (floGlobals.storageList.includes(data.application))
|
||||
var table = data.application;
|
||||
else
|
||||
var table = floGlobals.defaultStorage;
|
||||
var key = `${Date.now()}_${data.senderID}`
|
||||
compactIDB.addData(table, {
|
||||
senderID: data.senderID,
|
||||
receiverID: data.receiverID,
|
||||
pubKey: data.pubKey,
|
||||
message: data.message,
|
||||
sign: data.sign,
|
||||
application: data.application,
|
||||
type: data.type,
|
||||
comment: data.comment
|
||||
},key,`SN_${result[0].floID}`)
|
||||
}
|
||||
}).catch(error => console.log(error))
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
@ -5465,7 +5475,7 @@
|
||||
|
||||
initDB: function (dbName, objectStores = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.dbName = this.dbName || dbName;
|
||||
//this.dbName = this.dbName || dbName;
|
||||
var idb = indexedDB.open(dbName);
|
||||
idb.onerror = (event) => {
|
||||
reject("Error in opening IndexedDB!");
|
||||
@ -6021,45 +6031,57 @@
|
||||
myPubKey = floCrypto.getPubKeyHex(myPrivKey)
|
||||
myFloID = floCrypto.getFloIDfromPubkeyHex(myPubKey)
|
||||
|
||||
initIndexedDBforSupernode().then(result => {
|
||||
initIndexedDBforSupernodeConfig().then(result => {
|
||||
console.log(result)
|
||||
readSupernodeListFromAPI().then(result => {
|
||||
console.log(result)
|
||||
floSupernode.kBucket.launch().then(result => {
|
||||
console.log(result)
|
||||
if (myFloID in floGlobals.supernodes) {
|
||||
serverPwd = prompt("Enter Server Pass!")
|
||||
setInterval(refreshBlockchainData, 3600000);
|
||||
floSupernode.initSupernode(serverPwd, myFloID)
|
||||
.then(result => console.log(result))
|
||||
.catch(error => console.log(error))
|
||||
initIndexedDBforSupernodeDataStorage(myFloID).then(result => {
|
||||
console.log(result)
|
||||
serverPwd = prompt("Enter Server Pass!")
|
||||
setInterval(refreshBlockchainData, 3600000);
|
||||
floSupernode.initSupernode(serverPwd, myFloID)
|
||||
.then(result => console.log(result))
|
||||
.catch(error => console.log(error))
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}).catch(error => console.log(error))
|
||||
}
|
||||
|
||||
function initIndexedDBforSupernode(){
|
||||
function initIndexedDBforSupernodeConfig(){
|
||||
return new Promise((resolve, reject) => {
|
||||
var IndexesList = ["senderID","receiverID","pubKey","message","sign","application","type","comment"];
|
||||
var primaryKey = "vectorClock";
|
||||
var storageList = floGlobals.storageList;
|
||||
var obj = {
|
||||
var snObj = {
|
||||
lastTx:{},
|
||||
config:{},
|
||||
supernodes:{
|
||||
indexes:{ uri:null, pubKey:null }
|
||||
}
|
||||
}
|
||||
compactIDB.setDefaultDB("SupernodeConfig")
|
||||
compactIDB.initDB("SupernodeConfig", snObj)
|
||||
.then(result => resolve("Initiated supernode configuration IDB"))
|
||||
.catch(error => reject(error));
|
||||
})
|
||||
}
|
||||
|
||||
function initIndexedDBforSupernodeDataStorage(floID){
|
||||
return new Promise((resolve, reject) => {
|
||||
var indexesList = ["senderID","receiverID","pubKey","message","sign","application","type","comment"];
|
||||
var idbObj = {}
|
||||
for(var i=0;i<storageList.length;i++){
|
||||
obj[storageList[i]] = {
|
||||
options:{keyPath:primaryKey,autoIncrement:true},
|
||||
idbObj[storageList[i]] = {
|
||||
indexes:{}
|
||||
}
|
||||
for(var j=0;j<IndexesList.length;j++)
|
||||
obj[storageList[i]].indexes[IndexesList[j]] = null;
|
||||
for(var j=0;j<indexesList.length;j++)
|
||||
idbObj[storageList[i]].indexes[indexesList[j]] = null;
|
||||
}
|
||||
compactIDB.initDB("SupernodeStorage",obj)
|
||||
.then(result => resolve("Initiated supernode storage"))
|
||||
compactIDB.initDB(`SN_${floID}`, idbObj)
|
||||
.then(result => resolve("Initiated supernode storage IDB for "+floID))
|
||||
.catch(error => reject(error));
|
||||
})
|
||||
}
|
||||
@ -6083,11 +6105,16 @@
|
||||
compactIDB.removeData("supernodes",sn);
|
||||
for(sn in content.addNodes)
|
||||
compactIDB.writeData("supernodes",content.addNodes[sn],sn);
|
||||
for(c in content.config)
|
||||
compactIDB.writeData("config",content.config[c],c)
|
||||
}
|
||||
compactIDB.writeData("lastTx",result.totalTxs,floGlobals.adminID);
|
||||
compactIDB.readAllData("supernodes").then(result => {
|
||||
floGlobals.supernodes = result
|
||||
resolve("Read supernode from blockchain");
|
||||
compactIDB.readAllData("config").then(result => {
|
||||
floGlobals.config = result
|
||||
resolve("Read supernode from blockchain");
|
||||
})
|
||||
})
|
||||
})
|
||||
}).catch(error => reject(error))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user