fixed and improved fireNodeGoodByeEvent event

This commit is contained in:
Abhishek Sinha 2019-07-03 20:17:00 +05:30
parent df12a39b43
commit 98b4d34350

View File

@ -14401,8 +14401,7 @@
async resolve_current_crypto_price_in_fiat(crypto_code, currency_code) { async resolve_current_crypto_price_in_fiat(crypto_code, currency_code) {
let today = + new Date(); let today = + new Date();
const RM_TRADE = new localbitcoinplusplus.trade; const RM_TRADE = new localbitcoinplusplus.trade;
let last_update_of_fiat_price_obj = RM_TRADE.get_current_crypto_price_in_fiat(crypto_code, let last_update_of_fiat_price_obj = RM_TRADE.get_current_crypto_price_in_fiat(crypto_code, currency_code);
currency_code);
if (typeof last_update_of_fiat_price_obj !== "object" || if (typeof last_update_of_fiat_price_obj !== "object" ||
(today - last_update_of_fiat_price_obj.timestamp > 3600000)) { (today - last_update_of_fiat_price_obj.timestamp > 3600000)) {
last_update_of_fiat_price_obj = await RM_TRADE.set_current_crypto_price_in_fiat(crypto_code, currency_code); last_update_of_fiat_price_obj = await RM_TRADE.set_current_crypto_price_in_fiat(crypto_code, currency_code);
@ -18493,7 +18492,7 @@
if (localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS == su_db_data.trader_flo_address) return; if (localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS == su_db_data.trader_flo_address) return;
const mcslist = MCS.map(m=>m.data.id); const mcslist = MCS.map(m=>m.data.id);
95
if(mcslist.indexOf(su_db_data.trader_flo_address) < mcslist.indexOf(localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS)) { if(mcslist.indexOf(su_db_data.trader_flo_address) < mcslist.indexOf(localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS)) {
if (websocket.readyState === WebSocket.OPEN) { if (websocket.readyState === WebSocket.OPEN) {
websocket.close(); websocket.close();
@ -21630,26 +21629,39 @@
.includes(op[0].flo_public_key)) { .includes(op[0].flo_public_key)) {
// Update Node availability status to true/false // Update Node availability status to true/false
readDBbyIndex('myClosestSupernodes', 'trader_flo_address', getFLOId) const cs = await readDBbyIndex('myClosestSupernodes', 'trader_flo_address', getFLOId);
.then(cs=>{
if(cs.length<1) { if(cs.length<1) {
console.log(temp_ip, getFLOId); console.log(temp_ip, getFLOId);
console.error(`WARNING: Failed to update Supernodes status.`); console.error(`WARNING: Failed to update Supernodes status.`);
return; return;
} }
const switchMyWS = new backupSupernodesWebSocketObject(); const switchMyWS = new backupSupernodesWebSocketObject();
switchMyWS.updateSupernodeAvailabilityStatus(`ws://${cs[0].ip}:${cs[0].port}`, false); await switchMyWS.updateSupernodeAvailabilityStatus(`ws://${cs[0].ip}:${cs[0].port}`, false);
});
// Find out if you are the next eligible backup supernode, // Wait for 10 seconds if the 'dead' supernode only refreshed the page
await localbitcoinplusplus.actions.delay(10000);
// Get the current status now
const getStatusOfDeadSuAgain = await readDBbyIndex('myClosestSupernodes', 'trader_flo_address', getFLOId);
// If its still dead find out if you are the next eligible backup supernode
// If true, take charge of ded supernode's operations
if (getStatusOfDeadSuAgain[0].is_live==false) {
const mcs = await readAllDB('myClosestSupernodes'); const mcs = await readAllDB('myClosestSupernodes');
const myClosestSupList = mcs.filter((k,i)=>i<=localbitcoinplusplus.master_configurations.MaxBackups);
const index = mcs.findIndex(f=>f.trader_flo_address==getFLOId); const index = mcs.findIndex(f=>f.trader_flo_address==getFLOId);
tail = mcs.splice(0, index); tail = mcs.splice(0, index);
const newClosestSupernodeMasterList = mcs.concat(tail); const newClosestSupernodeMasterList = mcs.concat(tail).filter((k,i)=>i<=localbitcoinplusplus.master_configurations.MaxBackups);
const RM_RPC = new localbitcoinplusplus.rpc;
for(i=0; i<=newClosestSupernodeMasterList.length; i++) { for(i=0; i<=newClosestSupernodeMasterList.length; i++) {
if(newClosestSupernodeMasterList[i].is_live==true) break;
if(newClosestSupernodeMasterList[i].is_live==true
&& newClosestSupernodeMasterList[i].trader_flo_address !==
localbitcoinplusplus.wallets.my_local_flo_address) break;
if(newClosestSupernodeMasterList[i].trader_flo_address== if(newClosestSupernodeMasterList[i].trader_flo_address==
localbitcoinplusplus.wallets.my_local_flo_address) { localbitcoinplusplus.wallets.my_local_flo_address) {
@ -21677,8 +21689,8 @@
// which are not dead supernode's backup supernodes to sync // which are not dead supernode's backup supernodes to sync
// data from you // data from you
const nonBackUpSusForDeadSu = newClosestSupernodeMasterList const nonBackUpSusForDeadSu = myClosestSupList
.filter(function(obj) { return mcs.indexOf(obj) == -1; }); .filter(obj=>newClosestSupernodeMasterList.indexOf(obj) == -1);
console.log(nonBackUpSusForDeadSu); console.log(nonBackUpSusForDeadSu);
@ -21697,6 +21709,8 @@
} }
} }
}
msg = `INFO: Supernode ${getFLOId} left.`; msg = `INFO: Supernode ${getFLOId} left.`;
} else { } else {
msg = `INFO: User node ${getFLOId} left.`; msg = `INFO: User node ${getFLOId} left.`;