markRandomNodeUnreachable() refactor, notes/logging

pull/787/head
Ryan Tharp 5 years ago
parent 156c11d30f
commit 3bba0571a0

@ -9,8 +9,8 @@ class LokiSnodeAPI {
if (!is.string(serverUrl)) { if (!is.string(serverUrl)) {
throw new Error('WebAPI.initialize: Invalid server url'); throw new Error('WebAPI.initialize: Invalid server url');
} }
this.serverUrl = serverUrl; this.serverUrl = serverUrl; // random.snode
this.localUrl = localUrl; this.localUrl = localUrl; // localhost.loki
this.randomSnodePool = []; this.randomSnodePool = [];
this.swarmsPendingReplenish = {}; this.swarmsPendingReplenish = {};
} }
@ -63,7 +63,7 @@ class LokiSnodeAPI {
pubkey_ed25519: snode.pubkey_ed25519, pubkey_ed25519: snode.pubkey_ed25519,
})); }));
} catch (e) { } catch (e) {
log.warn('initialiseRandomPool error', JSON.stringify(e)); log.warn('initialiseRandomPool error', e.code, e.message);
if (seedNodes.length === 0) { if (seedNodes.length === 0) {
throw new window.textsecure.SeedNodeError( throw new window.textsecure.SeedNodeError(
'Failed to contact seed node' 'Failed to contact seed node'
@ -73,6 +73,7 @@ class LokiSnodeAPI {
} }
} }
// nodeUrl is like 9hrje1bymy7hu6nmtjme9idyu3rm8gr3mkstakjyuw1997t7w4ny.snode
async unreachableNode(pubKey, nodeUrl) { async unreachableNode(pubKey, nodeUrl) {
const conversation = ConversationController.get(pubKey); const conversation = ConversationController.get(pubKey);
const swarmNodes = [...conversation.get('swarmNodes')]; const swarmNodes = [...conversation.get('swarmNodes')];
@ -82,6 +83,13 @@ class LokiSnodeAPI {
await conversation.updateSwarmNodes(filteredNodes); await conversation.updateSwarmNodes(filteredNodes);
} }
markRandomNodeUnreachable(snode) {
this.randomSnodePool = _.without(
this.randomSnodePool,
_.find(this.randomSnodePool, { ip: snode.ip, port: snode.port })
);
}
async updateLastHash(snode, hash, expiresAt) { async updateLastHash(snode, hash, expiresAt) {
await window.Signal.Data.updateLastHash({ snode, hash, expiresAt }); await window.Signal.Data.updateLastHash({ snode, hash, expiresAt });
} }
@ -152,11 +160,7 @@ class LokiSnodeAPI {
return snodes; return snodes;
} catch (e) { } catch (e) {
log.error('getSwarmNodes error', e.code, e.message); log.error('getSwarmNodes error', e.code, e.message);
// this.markRandomNodeUnreachable(snode);
this.randomSnodePool = _.without(
this.randomSnodePool,
_.find(this.randomSnodePool, { ip: snode.ip })
);
return this.getSwarmNodes(pubKey); return this.getSwarmNodes(pubKey);
} }
} }

Loading…
Cancel
Save