Fix bug with swarm node reference, now we should only refresh swarm nodes when they fail

pull/187/head
Beaudan 6 years ago
parent 5d823de6f9
commit 2311bd1328

@ -199,9 +199,10 @@
return conversation;
};
conversation.initialPromise = create().then(async () => {
window.lokiSnodeAPI.refreshSwarmNodesForPubKey(id);
conversation.updateProfileAvatar();
conversation.initialPromise = create();
conversation.initialPromise.then(async () => {
await window.lokiSnodeAPI.refreshSwarmNodesForPubKey(id);
await conversation.updateProfileAvatar();
});
return conversation;

@ -111,7 +111,6 @@ module.exports = {
removeAllSessions,
getSwarmNodesByPubkey,
saveSwarmNodesForPubKey,
getConversationCount,
saveConversation,
@ -676,14 +675,6 @@ async function getSwarmNodesByPubkey(pubkey) {
return channels.getSwarmNodesByPubkey(pubkey);
}
async function saveSwarmNodesForPubKey(pubKey, swarmNodes, { Conversation }) {
const conversation = await getConversationById(pubKey, { Conversation });
conversation.set({ swarmNodes });
await updateConversation(conversation.id, conversation.attributes, {
Conversation,
});
}
async function getConversationCount() {
return channels.getConversationCount();
}

@ -106,6 +106,7 @@ class LokiMessageAPI {
throw err;
}
const completedNodes = [];
const failedNodes = [];
let successfulRequests = 0;
let canResolve = true;
@ -150,6 +151,7 @@ class LokiMessageAPI {
log.error('Loki SendMessages:', e);
if (lokiSnodeAPI.unreachableNode(pubKey, nodeUrl)) {
nodeComplete(nodeUrl);
failedNodes.push(nodeUrl);
}
}
}
@ -161,6 +163,8 @@ class LokiMessageAPI {
}
if (swarmNodes.length === 0) {
const freshNodes = await lokiSnodeAPI.getFreshSwarmNodes(pubKey);
const goodNodes = _.difference(freshNodes, failedNodes);
await lokiSnodeAPI.updateSwarmNodes(pubKey, goodNodes);
swarmNodes = _.difference(freshNodes, completedNodes);
if (swarmNodes.length === 0) {
if (successfulRequests !== 0) {
@ -172,7 +176,6 @@ class LokiMessageAPI {
new Error('Ran out of swarm nodes to query')
);
}
lokiSnodeAPI.updateSwarmNodes(pubKey, swarmNodes);
}
const remainingRequests =

@ -59,9 +59,10 @@ class LokiSnodeAPI {
return false;
}
const conversation = ConversationController.get(pubKey);
const swarmNodes = conversation.get('swarmNodes');
if (swarmNodes.delete(nodeUrl)) {
await conversation.updateSwarmNodes(swarmNodes);
const swarmNodes = [...conversation.get('swarmNodes')];
if (nodeUrl in swarmNodes) {
const filteredNodes = swarmNodes.filter(node => node !== nodeUrl);
await conversation.updateSwarmNodes(filteredNodes);
delete this.contactSwarmNodes[nodeUrl];
}
return true;
@ -82,7 +83,7 @@ class LokiSnodeAPI {
let swarmNodes;
try {
conversation = ConversationController.get(pubKey);
swarmNodes = conversation.get('swarmNodes');
swarmNodes = [...conversation.get('swarmNodes')];
} catch (e) {
throw new window.textsecure.ReplayableError({
message: 'Could not get conversation',
@ -143,6 +144,7 @@ class LokiSnodeAPI {
newSwarmNodes = await this.getSwarmNodes(pubKey);
} catch (e) {
// TODO: Handle these errors sensibly
log.error('Failed to get new swarm nodes');
newSwarmNodes = [];
}
resolve(newSwarmNodes);

Loading…
Cancel
Save