From 9edaad678f682220c6d8d71f580f1ab474675e76 Mon Sep 17 00:00:00 2001 From: Abhishek Sinha Date: Sun, 25 Aug 2019 13:21:55 +0530 Subject: [PATCH] fixed more bugs in backup ws and fixed readyState unchanged on onclose event error --- supernode/index.html | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/supernode/index.html b/supernode/index.html index 467df06..85683dd 100644 --- a/supernode/index.html +++ b/supernode/index.html @@ -11307,13 +11307,26 @@ // ws conn already present if (supsObj.trader_flo_address===currenctBackupWsList[z-1]) continue; - if (myClosestSupsFloList.indexOf(supsObj.trader_flo_address) - <= myClosestSupsFloList.indexOf(currenctBackupWsList[z-1])) { + // Get the highest index of connected supernodes + const highestIndexOfConnectedSupernode = Object.keys(localbitcoinplusplus.backupWS) + .reduce((acc, val) => + (acc === undefined || myClosestSupsFloList.indexOf(val) > myClosestSupsFloList.indexOf(acc)) + ? myClosestSupsFloList.indexOf(val) : myClosestSupsFloList.indexOf(acc)); + + if (myClosestSupsFloList.indexOf(supsObj.trader_flo_address) < highestIndexOfConnectedSupernode) { /* Break the loop as soon as this line runs as any further ws conn releated event will be taken care in shift_ws_connection event itself. */ reactor.dispatchEvent('shift_ws_connection', supsObj); break; + } else { + if (currenctBackupWsList.length + < localbitcoinplusplus.master_configurations.MaxBackups) { + + reactor.dispatchEvent('shift_ws_connection', supsObj); + break; + } + break; } } else { reactor.dispatchEvent('shift_ws_connection', supsObj);