added code to prevent myClosestSupernode is_live value update when status is already eq to is_live field

This commit is contained in:
Abhishek Sinha 2019-07-19 20:04:15 +05:30
parent ca4681f09f
commit 815360f0ad

View File

@ -15728,9 +15728,18 @@
showMessage(`WARNING: Failed to update status of "${ws_url}" to ${status}.`); showMessage(`WARNING: Failed to update status of "${ws_url}" to ${status}.`);
return; return;
} }
// Code to prevent update if status is already eq to is_live value
let floId_index;
if (typeof wsUri == "object") {
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((myClosestSupernodesStatusRes)=>{ updateinDB('myClosestSupernodes', get_disconnected_su_details).then((myClosestSupernodesStatusRes)=>{
wsUri[floId_index].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}.`);
}); });
@ -21842,20 +21851,9 @@
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);
if(localbitcoinplusplus.master_configurations.supernodesPubKeys
.includes(evt.flo_public_key)) {
// ReadyState was 3 when this node disconnected. Re-initiate the // ReadyState was 3 when this node disconnected. Re-initiate the
// WS connection to be able to send/receive messages // WS connection to be able to send/receive messages
if (typeof localbitcoinplusplus.backupWS[getFLOId]=="object" reactor.dispatchEvent('resolve_backup_ws_connections');
&& localbitcoinplusplus.backupWS[getFLOId].ws_connection.readyState !== 1) {
const back_ws_url = localbitcoinplusplus.backupWS[getFLOId].ws_url;
localbitcoinplusplus.backupWS[getFLOId] = null;
localbitcoinplusplus.backupWS[getFLOId] = new backupSupernodesWebSocketObject(back_ws_url);
localbitcoinplusplus.backupWS[getFLOId].connectWS();
}
msg = `INFO: Supernode ${getFLOId} joined.`;
const switchMyWS = new backupSupernodesWebSocketObject(); const switchMyWS = new backupSupernodesWebSocketObject();
switchMyWS.updateSupernodeAvailabilityStatus(getFLOId, true); switchMyWS.updateSupernodeAvailabilityStatus(getFLOId, true);
@ -21867,10 +21865,6 @@
} }
} }
} else {
msg = `INFO: User node ${getFLOId} joined.`;
}
showMessage(msg);
}); });
reactor.addEventListener('new_supernode_connected', async function(evt) { reactor.addEventListener('new_supernode_connected', async function(evt) {
@ -21910,8 +21904,7 @@
// Update Node availability status to true/false // Update Node availability status to true/false
const cs = await readDBbyIndex('myClosestSupernodes', 'trader_flo_address', getFLOId); const cs = await readDBbyIndex('myClosestSupernodes', 'trader_flo_address', getFLOId);
if(cs.length<1) { if(cs.length<1) {
console.log(temp_ip, getFLOId); console.error(`WARNING: Failed to update Supernodes ${getFLOId} status.`);
console.error(`WARNING: Failed to update Supernodes status.`);
return; return;
} }
const switchMyWS = new backupSupernodesWebSocketObject(); const switchMyWS = new backupSupernodesWebSocketObject();
@ -21924,9 +21917,12 @@
const getStatusOfDeadSuAgain = await readDBbyIndex('myClosestSupernodes', 'trader_flo_address', getFLOId); const getStatusOfDeadSuAgain = await readDBbyIndex('myClosestSupernodes', 'trader_flo_address', getFLOId);
// If its still dead find out if you are the next eligible backup supernode // If its still dead find out if you are the next eligible backup supernode
// If true, take charge of ded supernode's operations // If true, take charge of dead supernode's operations
if (getStatusOfDeadSuAgain[0].is_live==false) { if (getStatusOfDeadSuAgain[0].is_live==false) {
// Initiate connections with next live supernodes
reactor.dispatchEvent('resolve_backup_ws_connections');
const mcs = await readAllDB('myClosestSupernodes'); const mcs = await readAllDB('myClosestSupernodes');
const myClosestSupList = mcs.filter((k,i)=>i<=localbitcoinplusplus.master_configurations.MaxBackups); 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);
@ -22169,6 +22165,7 @@
const backup_conns = localbitcoinplusplus.backupWS[backup_id]; const backup_conns = localbitcoinplusplus.backupWS[backup_id];
if(typeof backup_conns.ws_connection == "object") { if(typeof backup_conns.ws_connection == "object") {
if(backup_conns.ws_connection.readyState !== 1) { if(backup_conns.ws_connection.readyState !== 1) {
localbitcoinplusplus.backupWS[backup_id].ws_connection.close();
delete localbitcoinplusplus.backupWS[backup_id]; delete localbitcoinplusplus.backupWS[backup_id];
} }
} }