fixed backup ws connection loop issue

This commit is contained in:
Abhishek Sinha 2019-09-12 21:19:15 +05:30
parent 9fa26d20db
commit d13cceeb33

View File

@ -13225,10 +13225,9 @@ Event information log
reactor.registerEvent("shift_ws_connection"); reactor.registerEvent("shift_ws_connection");
reactor.registerEvent("switchToBackupWSForSuperNodesOperations"); reactor.registerEvent("switchToBackupWSForSuperNodesOperations");
reactor.registerEvent("user_flo_keys_active"); reactor.registerEvent("user_flo_keys_active");
reactor.registerEvent("backup_supernode_down");
reactor.registerEvent("remove_extra_backup_connections"); reactor.registerEvent("remove_extra_backup_connections");
reactor.registerEvent(
"request_to_modify_user_balance_on_successfull_fiat_deposit"
);
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);
@ -13738,21 +13737,23 @@ Event information log
localbitcoinplusplus.backupWS[getFLOId].ws_connection localbitcoinplusplus.backupWS[getFLOId].ws_connection
.readyState >= 2 .readyState >= 2
) { ) {
localbitcoinplusplus.backupWS[getFLOId] = null; if (getFLOId !== localbitcoinplusplus.wallets.my_local_flo_address) {
localbitcoinplusplus.backupWS[ localbitcoinplusplus.backupWS[getFLOId] = null;
getFLOId localbitcoinplusplus.backupWS[
] = new backupSupernodesWebSocketObject(back_ws_url); getFLOId
localbitcoinplusplus.backupWS[getFLOId].connectWS(); ] = new backupSupernodesWebSocketObject(back_ws_url);
/* Now in connectWS if connection fails call switchToBackupWSForSuperNodesOperations() in onClose() localbitcoinplusplus.backupWS[getFLOId].connectWS();
/* Now in connectWS if connection fails call switchToBackupWSForSuperNodesOperations() in onClose()
for next su node, if its success check for max baxkup connection conditon, if required for next su node, if its success check for max baxkup connection conditon, if required
execute 'resolve_backup_ws_connections' in onOpen() or exit */ execute 'resolve_backup_ws_connections' in onOpen() or exit */
}
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
reactor.dispatchEvent( // reactor.dispatchEvent(
"switchToBackupWSForSuperNodesOperations", // "switchToBackupWSForSuperNodesOperations",
back_ws_url // back_ws_url
); // );
} }
} }
}); });
@ -13809,15 +13810,15 @@ Event information log
continue; continue;
// Get the highest index of connected supernodes // Get the highest index of connected supernodes
const highestIndexOfConnectedSupernode = Object.keys( let highestIndexOfConnectedSupernode = -1;
localbitcoinplusplus.backupWS
).reduce((acc, val) => for(let i=0; i<=currenctBackupWsList.length; i++) {
acc === undefined || if(myClosestSupsFloList.indexOf(currenctBackupWsList[i])
myClosestSupsFloList.indexOf(val) > >highestIndexOfConnectedSupernode) {
myClosestSupsFloList.indexOf(acc) highestIndexOfConnectedSupernode
? myClosestSupsFloList.indexOf(val) = myClosestSupsFloList.indexOf(currenctBackupWsList[i]);
: myClosestSupsFloList.indexOf(acc) }
); }
if ( if (
myClosestSupsFloList.indexOf(supsObj.trader_flo_address) < myClosestSupsFloList.indexOf(supsObj.trader_flo_address) <
@ -13882,9 +13883,11 @@ Event information log
); );
if ( if (
typeof nextClosestSupernodeElem == "object" && typeof nextClosestSupernodeElem == "object"
nextClosestSupernodeElem[0].trader_flo_address !== && nextClosestSupernodeElem !== null
user_data.myLocalFLOAddress && nextClosestSupernodeElem !== undefined
&& nextClosestSupernodeElem[0].trader_flo_address
!== user_data.myLocalFLOAddress
) { ) {
reactor.dispatchEvent( reactor.dispatchEvent(
"shift_ws_connection", "shift_ws_connection",
@ -13956,20 +13959,23 @@ Event information log
} }
}); });
/*This function is used to verify a tx denoting token transfer by trusted guy to the supernode /* This function runs when a backup ws is down */
and to increase balance of the respective user node.*/ reactor.addEventListener("backup_supernode_down", async function(evt) {
showMessage(
`Disconnected to backup Supernode sever: ${evt.srcElement.url}.`
);
const switchMyWS = new backupSupernodesWebSocketObject();
switchMyWS.updateSupernodeAvailabilityStatus(
evt.srcElement.url,
false
);
// Request next backup server to connect
await reactor.dispatchEvent(
"switchToBackupWSForSuperNodesOperations",
evt.srcElement.url
);
});
reactor.addEventListener(
"request_to_modify_user_balance_on_successfull_fiat_deposit",
function(token_transfer_resp) {
/*
token_transfer_resp = {
tx: ec289d40069bb4db8b633133560269004a35f834c4a146560887ac87f7789d35,
user_action: 'deposit'
}
*/
}
);
</script> </script>
<!-- Misc functions --> <!-- Misc functions -->
@ -20295,21 +20301,7 @@ Event information log
reactor.dispatchEvent("backup_supernode_up"); reactor.dispatchEvent("backup_supernode_up");
}.bind(this); }.bind(this);
this.ws_connection.onclose = function(evt) { this.ws_connection.onclose = function(evt) {
reactor.addEventListener("backup_supernode_down", async function() { reactor.dispatchEvent("backup_supernode_down", evt);
showMessage(
`Disconnected to backup Supernode sever: ${evt.srcElement.url}.`
);
switchMyWS.updateSupernodeAvailabilityStatus(
evt.srcElement.url,
false
);
// Request next backup server to connect
await reactor.dispatchEvent(
"switchToBackupWSForSuperNodesOperations",
evt.srcElement.url
);
});
reactor.dispatchEvent("backup_supernode_down");
}.bind(this); }.bind(this);
this.ws_connection.onmessage = function(evt) { this.ws_connection.onmessage = function(evt) {
let response = evt.data; let response = evt.data;