getSwarmNodesForPubKey make fetching hashes optional and off by default, get version summary when all downloaded, _getVersion retry bug fix, other notes

pull/1061/head
Ryan Tharp 5 years ago
parent 40ebc508fc
commit f6233b91a9

@ -59,6 +59,7 @@ async function tryGetSnodeListFromLokidSeednode(
); );
// throw before clearing the lock, so the retries can kick in // throw before clearing the lock, so the retries can kick in
if (snodes.length === 0) { if (snodes.length === 0) {
// does this error message need to be exactly this?
throw new window.textsecure.SeedNodeError('Failed to contact seed node'); throw new window.textsecure.SeedNodeError('Failed to contact seed node');
} }
return snodes; return snodes;
@ -423,7 +424,7 @@ class LokiSnodeAPI {
} }
// WARNING: this leaks our IP to all snodes but with no other identifying information // WARNING: this leaks our IP to all snodes but with no other identifying information
// except that a client started up or ran out of random pool snodes // except "that a client started up" or "ran out of random pool snodes"
// and the order of the list is randomized, so a snode can't tell if it just started or not // and the order of the list is randomized, so a snode can't tell if it just started or not
async _getVersion(node, options = {}) { async _getVersion(node, options = {}) {
const retries = options.retries || 0; const retries = options.retries || 0;
@ -443,7 +444,7 @@ class LokiSnodeAPI {
this.randomSnodePool[foundNodeIdx].version = data.version; this.randomSnodePool[foundNodeIdx].version = data.version;
} else { } else {
// maybe already marked bad... // maybe already marked bad...
log.warn( log.debug(
`loki_snode:::_getVersion - can't find ${node.ip}:${ `loki_snode:::_getVersion - can't find ${node.ip}:${
node.port node.port
} in randomSnodePool` } in randomSnodePool`
@ -475,7 +476,7 @@ class LokiSnodeAPI {
`on ${node.ip}:${node.port} retrying in 1s` `on ${node.ip}:${node.port} retrying in 1s`
); );
await primitives.sleepFor(1000); await primitives.sleepFor(1000);
await this._getVersion(node, { ...options, retries: retries + 1 }); return this._getVersion(node, { ...options, retries: retries + 1 });
} else { } else {
this.markRandomNodeUnreachable(node); this.markRandomNodeUnreachable(node);
const randomNodesLeft = this.getRandomPoolLength(); const randomNodesLeft = this.getRandomPoolLength();
@ -520,7 +521,7 @@ class LokiSnodeAPI {
*/ */
} catch (e) { } catch (e) {
log.error( log.error(
'loki_snode:::_getAllVerionsForRandomSnodePool - error', `loki_snode:::_getAllVerionsForRandomSnodePool - error`,
e.code, e.code,
e.message e.message
); );
@ -532,7 +533,19 @@ class LokiSnodeAPI {
this.stopGetAllVersionPromiseControl = loop.stop; this.stopGetAllVersionPromiseControl = loop.stop;
await loop.start(true); await loop.start(true);
this.stopGetAllVersionPromiseControl = false; // clear lock this.stopGetAllVersionPromiseControl = false; // clear lock
log.debug('Versions retrieved from network!'); // an array of objects
const versions = this.randomSnodePool.reduce((curVal, node) => {
if (curVal.indexOf(node.version) === -1) {
curVal.push(node.version);
}
return curVal;
}, []);
log.debug(
`loki_snode:::_getAllVerionsForRandomSnodePool - ${
versions.length
} versions retrieved from network!:`,
versions.join(',')
);
} }
async refreshRandomPool(seedNodes = [...window.seedNodeList]) { async refreshRandomPool(seedNodes = [...window.seedNodeList]) {
@ -630,12 +643,14 @@ class LokiSnodeAPI {
} }
// called by loki_message:::sendMessage & loki_message:::startLongPolling // called by loki_message:::sendMessage & loki_message:::startLongPolling
async getSwarmNodesForPubKey(pubKey) { async getSwarmNodesForPubKey(pubKey, options = {}) {
const { fetchHashes } = options;
try { try {
const conversation = ConversationController.get(pubKey); const conversation = ConversationController.get(pubKey);
const swarmNodes = [...conversation.get('swarmNodes')]; const swarmNodes = [...conversation.get('swarmNodes')];
// always? include lashHash // always? include lashHash
if (fetchHashes) {
await Promise.all( await Promise.all(
Object.keys(swarmNodes).map(async j => { Object.keys(swarmNodes).map(async j => {
const node = swarmNodes[j]; const node = swarmNodes[j];
@ -646,7 +661,7 @@ class LokiSnodeAPI {
log.debug( log.debug(
`loki_snode:::getSwarmNodesForPubKey - ${j} ${node.ip}:${ `loki_snode:::getSwarmNodesForPubKey - ${j} ${node.ip}:${
node.port node.port
} hash ${lastHash} for ${node.address}` }`
); );
swarmNodes[j] = { swarmNodes[j] = {
...node, ...node,
@ -654,6 +669,7 @@ class LokiSnodeAPI {
}; };
}) })
); );
}
return swarmNodes; return swarmNodes;
} catch (e) { } catch (e) {

Loading…
Cancel
Save