From 7a0e972ca4ef878eb80a3fd772249b2cbc500487 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Thu, 19 Mar 2020 21:19:20 -0700 Subject: [PATCH] refactor getRandomPoolLength out of markRandomNodeUnreachable --- js/modules/loki_rpc.js | 10 ++++------ js/modules/loki_snode_api.js | 6 +++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/js/modules/loki_rpc.js b/js/modules/loki_rpc.js index b27bca1a0..cb49b975b 100644 --- a/js/modules/loki_rpc.js +++ b/js/modules/loki_rpc.js @@ -73,9 +73,8 @@ const sendToProxy = async (options = {}, targetNode, retryNumber = 0) => { // remove // but which the proxy or the target... // we got a ton of randomPool nodes, let's just not worry about this one - const randomPoolRemainingCount = lokiSnodeAPI.markRandomNodeUnreachable( - randSnode - ); + lokiSnodeAPI.markRandomNodeUnreachable(randSnode); + const randomPoolRemainingCount = lokiSnodeAPI.getRandomPoolLength(); log.warn( `lokiRpc sendToProxy`, `snode ${randSnode.ip}:${randSnode.port} to ${targetNode.ip}:${ @@ -99,9 +98,8 @@ const sendToProxy = async (options = {}, targetNode, retryNumber = 0) => { // but the target node // we got a ton of randomPool nodes, let's just not worry about this one - const randomPoolRemainingCount = lokiSnodeAPI.markRandomNodeUnreachable( - randSnode - ); + lokiSnodeAPI.markRandomNodeUnreachable(randSnode); + const randomPoolRemainingCount = lokiSnodeAPI.getRandomPoolLength(); log.warn( `lokiRpc sendToProxy`, `snode ${randSnode.ip}:${randSnode.port} to ${targetNode.ip}:${ diff --git a/js/modules/loki_snode_api.js b/js/modules/loki_snode_api.js index 061ecf2de..46b18b9ee 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -185,6 +185,9 @@ class LokiSnodeAPI { this.randomSnodePool, _.find(this.randomSnodePool, { ip: snode.ip, port: snode.port }) ); + } + + getRandomPoolLength() { return this.randomSnodePool.length; } @@ -281,7 +284,8 @@ class LokiSnodeAPI { const snodes = result.snodes.filter(tSnode => tSnode.ip !== '0.0.0.0'); return snodes; } catch (e) { - const randomPoolRemainingCount = this.markRandomNodeUnreachable(snode); + this.markRandomNodeUnreachable(snode); + const randomPoolRemainingCount = this.getRandomPoolLength(); log.error( 'loki_snodes:::getSnodesForPubkey - error', e.code,