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