From ee260f7de075b04e5a3d1d2469101db02e917ac3 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Fri, 28 Jun 2019 10:46:41 +1000 Subject: [PATCH 1/2] Fix silly filtering bug, add filtering for swarm nodes and lint --- js/modules/loki_message_api.js | 6 ++++-- js/modules/loki_snode_api.js | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index 7dfc99d35..a53ead433 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -283,7 +283,7 @@ class LokiMessageAPI { options ); return result.messages || []; - }; + } async startLongPolling(numConnections, callback) { this.ourSwarmNodes = {}; @@ -293,7 +293,9 @@ class LokiMessageAPI { nodes = await lokiSnodeAPI.getSwarmNodesForPubKey(this.ourKey); } for (let i = 0; i < nodes.length; i += 1) { - const lastHash = await window.Signal.Data.getLastHashBySnode(nodes[i].address); + const lastHash = await window.Signal.Data.getLastHashBySnode( + nodes[i].address + ); this.ourSwarmNodes[nodes[i].address] = { lastHash, ip: nodes[i].ip, diff --git a/js/modules/loki_snode_api.js b/js/modules/loki_snode_api.js index a82ee326a..ba50946ac 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -92,7 +92,7 @@ class LokiSnodeAPI { ); // Filter 0.0.0.0 nodes which haven't submitted uptime proofs const snodes = result.result.service_node_states.filter( - snode => snode.address !== '0.0.0.0' + snode => snode.public_ip !== '0.0.0.0' ); this.randomSnodePool = snodes.map(snode => ({ address: snode.public_ip, @@ -172,7 +172,8 @@ class LokiSnodeAPI { pubKey, } ); - return result.snodes; + const snodes = result.snodes.filter(snode => snode.ip !== '0.0.0.0'); + return snodes; } catch (e) { this.randomSnodePool = _.without( this.randomSnodePool, From eb1fa97c9c592cfe189d81fc703fbf3957a918e3 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Fri, 28 Jun 2019 11:13:50 +1000 Subject: [PATCH 2/2] Make use of ip consistent for random snode pool and swarm list --- js/modules/loki_snode_api.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/js/modules/loki_snode_api.js b/js/modules/loki_snode_api.js index ba50946ac..65d7a7e8c 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -95,7 +95,7 @@ class LokiSnodeAPI { snode => snode.public_ip !== '0.0.0.0' ); this.randomSnodePool = snodes.map(snode => ({ - address: snode.public_ip, + ip: snode.public_ip, port: snode.storage_port, })); } catch (e) { @@ -162,22 +162,17 @@ class LokiSnodeAPI { async getSwarmNodes(pubKey) { // TODO: Hit multiple random nodes and merge lists? - const { address, port } = await this.getRandomSnodeAddress(); + const { ip, port } = await this.getRandomSnodeAddress(); try { - const result = await rpc( - `https://${address}`, - port, - 'get_snodes_for_pubkey', - { - pubKey, - } - ); + const result = await rpc(`https://${ip}`, port, 'get_snodes_for_pubkey', { + pubKey, + }); const snodes = result.snodes.filter(snode => snode.ip !== '0.0.0.0'); return snodes; } catch (e) { this.randomSnodePool = _.without( this.randomSnodePool, - _.find(this.randomSnodePool, { address }) + _.find(this.randomSnodePool, { ip }) ); return this.getSwarmNodes(pubKey); }