added code for myClosestSupernodes object, recording all incoming temp ip of Supernodes

This commit is contained in:
Abhishek Sinha 2019-10-01 21:07:09 +05:30
parent 295f7a21d1
commit 2949db59be

View File

@ -12520,9 +12520,10 @@
}, },
exportUserDataFromOneSupernodeToAnother: async function( exportUserDataFromOneSupernodeToAnother: async function(
myFloId= "",
userFloId = "", userFloId = "",
receipient_su = "" receipient_su = ""
) { ) {
let immigrantsList = []; let immigrantsList = [];
const tableArray = [ const tableArray = [
"deposit", "deposit",
@ -12557,6 +12558,13 @@
.then(server_sync_response => doSend(server_sync_response)); .then(server_sync_response => doSend(server_sync_response));
} }
} else { } else {
// const oldSupernodeKbucket = await localbitcoinplusplus.kademlia.restoreKbucket(
// myFloId,
// "FLO_TEST",
// KBucket
// );
const allUsersData = await readAllDB("userPublicData"); const allUsersData = await readAllDB("userPublicData");
const supernodesFloList = localbitcoinplusplus.master_configurations.supernodesPubKeys const supernodesFloList = localbitcoinplusplus.master_configurations.supernodesPubKeys
@ -12590,6 +12598,9 @@
} }
} }
} }
localbitcoinplusplus.kademlia.updateClosestSupernodeSeeds(myFloId);
} }
} }
}; };
@ -13192,7 +13203,8 @@
reactor.registerEvent("switchToBackupWSForSuperNodesOperations"); reactor.registerEvent("switchToBackupWSForSuperNodesOperations");
reactor.registerEvent("user_flo_keys_active"); reactor.registerEvent("user_flo_keys_active");
reactor.registerEvent("remove_extra_backup_connections"); reactor.registerEvent("remove_extra_backup_connections");
reactor.registerEvent("createClosestSupernodesObject");
reactor.addEventListener("fireNodeWelcomeBackEvent", function(evt) { reactor.addEventListener("fireNodeWelcomeBackEvent", function(evt) {
let getFLOId = bitjs.FLO_TEST.pubkey2address(evt.flo_public_key); let getFLOId = bitjs.FLO_TEST.pubkey2address(evt.flo_public_key);
@ -13317,6 +13329,9 @@
false false
); );
// Delete entry from iptable
removeByIndex("ipTable", "temporary_ip", temp_ip);
if ( if (
localbitcoinplusplus.master_configurations.supernodesPubKeys.includes( localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
op[0].flo_public_key op[0].flo_public_key
@ -13449,6 +13464,9 @@
if ( if (
params.receiver_flo_address !== params.receiver_flo_address !==
localbitcoinplusplus.wallets.my_local_flo_address localbitcoinplusplus.wallets.my_local_flo_address
||
localbitcoinplusplus.myClosestSupernodes[params.trader_flo_address].is_live
=== true
) )
return; return;
@ -13922,7 +13940,7 @@
); );
}); });
reactor.addEventListener("backup_supernode_up", async function(url='') { reactor.addEventListener("backup_supernode_up", async function(url='') {
showMessage( showMessage(
`Connected to backup Supernode sever: ${url}.` `Connected to backup Supernode sever: ${url}.`
); );
@ -13996,6 +14014,56 @@
} }
}); });
reactor.addEventListener('createClosestSupernodesObject', async function(getClosestSuList=[]) {
if (typeof localbitcoinplusplus.myClosestSupernodes === "object"
&& localbitcoinplusplus.myClosestSupernodes.length ===
localbitcoinplusplus.master_configurations.supernodesPubKeys.length)
return;
const idbData = await readDB("localbitcoinUser", "00-01");
if (getClosestSuList.length < 1) {
getClosestSuList = await readAllDB('myClosestSupernodes');
}
Object.defineProperty(localbitcoinplusplus, 'myClosestSupernodes', {
value: {},
writable: false,
enumerable: true,
configurable: false
});
for (const m of getClosestSuList) {
for (let k in m) {
if (typeof localbitcoinplusplus.myClosestSupernodes[m.trader_flo_address] !== "object") {
Object.defineProperty(localbitcoinplusplus.myClosestSupernodes, [m.trader_flo_address], {
value: {},
writable: false,
enumerable: true,
configurable: false
});
}
if (k === 'is_live') {
Object.defineProperty(localbitcoinplusplus.myClosestSupernodes[m.trader_flo_address], k, {
value: m[k],
writable: true,
enumerable: true,
configurable: false
});
} else {
Object.defineProperty(localbitcoinplusplus.myClosestSupernodes[m.trader_flo_address], k, {
value: m[k],
writable: false,
enumerable: true,
configurable: false
});
}
}
}
return localbitcoinplusplus.myClosestSupernodes;
});
</script> </script>
<!-- Misc functions --> <!-- Misc functions -->
@ -20166,12 +20234,15 @@
idbData.myLocalFLOAddress idbData.myLocalFLOAddress
); );
const getClosestSuList = await readAllDB("myClosestSupernodes");
reactor.dispatchEvent("createClosestSupernodesObject", getClosestSuList);
if ( if (
localbitcoinplusplus.master_configurations.supernodesPubKeys.includes( localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
idbData.myLocalFLOPublicKey idbData.myLocalFLOPublicKey
) )
) { ) {
const getClosestSuList = await readAllDB("myClosestSupernodes");
if ( if (
wsUri[0].trader_flo_address !== idbData.myLocalFLOAddress || wsUri[0].trader_flo_address !== idbData.myLocalFLOAddress ||
getClosestSuList.length < getClosestSuList.length <
@ -20180,6 +20251,10 @@
showMessage( showMessage(
`INFO: Invalid connection. Refreshing the closest supernode list in DB.` `INFO: Invalid connection. Refreshing the closest supernode list in DB.`
); );
// Possible entry of new Supernode. Export data of users
//localbitcoinplusplus.actions.exportUserDataFromOneSupernodeToAnother(idbData.myLocalFLOAddress);
wsUri = await localbitcoinplusplus.kademlia.updateClosestSupernodeSeeds( wsUri = await localbitcoinplusplus.kademlia.updateClosestSupernodeSeeds(
idbData.myLocalFLOAddress idbData.myLocalFLOAddress
); );
@ -20269,9 +20344,9 @@
connectWS() { connectWS() {
this.ws_connection = new WebSocket(this.ws_url); this.ws_connection = new WebSocket(this.ws_url);
const switchMyWS = new backupSupernodesWebSocketObject(); const switchMyWS = new backupSupernodesWebSocketObject();
this.ws_connection.onopen = function(evt) { this.ws_connection.onopen = async function(evt) {
reactor.dispatchEvent("backup_supernode_up", evt.srcElement.url); await reactor.dispatchEvent("backup_supernode_up", evt.srcElement.url);
reactor.dispatchEvent("remove_extra_backup_connections"); await reactor.dispatchEvent("remove_extra_backup_connections");
}.bind(this); }.bind(this);
this.ws_connection.onclose = function(evt) { this.ws_connection.onclose = function(evt) {
reactor.dispatchEvent("backup_supernode_down", evt); reactor.dispatchEvent("backup_supernode_down", evt);
@ -20393,8 +20468,7 @@
"trader_flo_address", "trader_flo_address",
disconnected_su_flo_id disconnected_su_flo_id
); );
const get_disconnected_su_details = const get_disconnected_su_details = get_disconnected_su_details_list[0];
get_disconnected_su_details_list[0];
if (typeof get_disconnected_su_details !== "object") { if (typeof get_disconnected_su_details !== "object") {
showMessage( showMessage(
`WARNING: Failed to update status of "${ws_url}" to ${status}.` `WARNING: Failed to update status of "${ws_url}" to ${status}.`
@ -20402,25 +20476,15 @@
return; return;
} }
// Code to prevent update if status is already eq to is_live value // Code to prevent update if status is already eq to is_live value
let floId_index; if (typeof localbitcoinplusplus.myClosestSupernodes[disconnected_su_flo_id] == "object") {
if (typeof wsUri == "object") { if (localbitcoinplusplus.myClosestSupernodes[disconnected_su_flo_id].is_live === status) return;
floId_index = wsUri.findIndex(
e => e.trader_flo_address == disconnected_su_flo_id,
disconnected_su_flo_id
);
if (
typeof floId_index == "number" &&
typeof wsUri[floId_index] == "object"
) {
if (wsUri[floId_index].is_live === status) return;
}
} }
get_disconnected_su_details.is_live = status; get_disconnected_su_details.is_live = status;
get_disconnected_su_details.timestamp = +new Date(); get_disconnected_su_details.timestamp = +new Date();
updateinDB("myClosestSupernodes", get_disconnected_su_details).then( updateinDB("myClosestSupernodes", get_disconnected_su_details).then(
myClosestSupernodesStatusRes => { myClosestSupernodesStatusRes => {
wsUri[floId_index].is_live = status; localbitcoinplusplus.myClosestSupernodes[disconnected_su_flo_id].is_live = status;
let su_status = status === true ? "connected" : "disconnected"; let su_status = (status === true) ? "connected" : "disconnected";
showMessage(`INFO: Supernode ${ws_url} is now ${su_status}.`); showMessage(`INFO: Supernode ${ws_url} is now ${su_status}.`);
} }
); );
@ -20530,7 +20594,8 @@
}); });
} }
function onOpen(evt) { async function onOpen(evt) {
await reactor.dispatchEvent("createClosestSupernodesObject");
reactor.dispatchEvent("new_supernode_connected", evt); reactor.dispatchEvent("new_supernode_connected", evt);
readDB("localbitcoinUser", "00-01").then(res => { readDB("localbitcoinUser", "00-01").then(res => {
if (typeof res == "object" && res.myLocalFLOAddress == "string") { if (typeof res == "object" && res.myLocalFLOAddress == "string") {
@ -26939,7 +27004,7 @@
var db; var db;
const DBName = "localbitcoinDB"; const DBName = "localbitcoinDB";
const request = window.indexedDB.open(DBName, 1); const request = window.indexedDB.open(DBName, 2);
request.onerror = function(event) { request.onerror = function(event) {
//https://stackoverflow.com/questions/13972385/invalidstateerror-while-opening-indexeddb-in-firefox //https://stackoverflow.com/questions/13972385/invalidstateerror-while-opening-indexeddb-in-firefox