Fixed some bugs removing nodes after the first failure instead of waiting for the failure count and also reduced the number of errors logged and made some warnings

pull/203/head
Beaudan 7 years ago
parent b00a0cb699
commit 25ded46e2c

@ -143,6 +143,7 @@ class LokiMessageAPI {
nodeComplete(nodeUrl);
successfulRequests += 1;
} catch (e) {
log.warn('Send message error:', e);
if (e instanceof NotFoundError) {
canResolve = false;
} else if (e instanceof HTTPError) {
@ -155,8 +156,12 @@ class LokiMessageAPI {
// We mark the node as complete as we could still reach it
nodeComplete(nodeUrl);
} else {
log.error('Loki SendMessages:', e);
if (lokiSnodeAPI.unreachableNode(pubKey, nodeUrl)) {
const removeNode = await lokiSnodeAPI.unreachableNode(
pubKey,
nodeUrl
);
if (removeNode) {
log.error('Loki SendMessages:', e);
nodeComplete(nodeUrl);
failedNodes.push(nodeUrl);
}
@ -242,6 +247,7 @@ class LokiMessageAPI {
}
successfulRequests += 1;
} catch (e) {
log.warn('Retrieve message error:', e);
if (e instanceof NotFoundError) {
canResolve = false;
} else if (e instanceof HTTPError) {
@ -254,8 +260,12 @@ class LokiMessageAPI {
// We mark the node as complete as we could still reach it
nodeComplete(nodeUrl);
} else {
log.error('Loki RetrieveMessages:', e);
if (lokiSnodeAPI.unreachableNode(ourKey, nodeUrl)) {
const removeNode = await lokiSnodeAPI.unreachableNode(
ourKey,
nodeUrl
);
if (removeNode) {
log.error('Loki RetrieveMessages:', e);
nodeComplete(nodeUrl);
}
}

@ -68,10 +68,11 @@ class LokiSnodeAPI {
} else {
this.ourSwarmNodes[nodeUrl].failureCount += 1;
}
if (this.ourSwarmNodes[nodeUrl].failureCount >= FAILURE_THRESHOLD) {
delete this.ourSwarmNodes[nodeUrl];
if (this.ourSwarmNodes[nodeUrl].failureCount < FAILURE_THRESHOLD) {
return false;
}
return false;
delete this.ourSwarmNodes[nodeUrl];
return true;
}
if (!this.contactSwarmNodes[nodeUrl]) {
this.contactSwarmNodes[nodeUrl] = {
@ -85,7 +86,7 @@ class LokiSnodeAPI {
}
const conversation = ConversationController.get(pubKey);
const swarmNodes = [...conversation.get('swarmNodes')];
if (nodeUrl in swarmNodes) {
if (swarmNodes.includes(nodeUrl)) {
const filteredNodes = swarmNodes.filter(node => node !== nodeUrl);
await conversation.updateSwarmNodes(filteredNodes);
delete this.contactSwarmNodes[nodeUrl];
@ -161,7 +162,7 @@ class LokiSnodeAPI {
newSwarmNodes = await this.getSwarmNodes(pubKey);
} catch (e) {
// TODO: Handle these errors sensibly
log.error('Failed to get new swarm nodes');
log.error(e);
newSwarmNodes = [];
}
resolve(newSwarmNodes);
@ -205,12 +206,6 @@ class LokiSnodeAPI {
try {
response = await fetch(options.url, fetchOptions);
} catch (e) {
log.error(
options.type,
options.url,
0,
`Error getting swarm nodes for ${pubKey}`
);
throw HTTPError('getSwarmNodes fetch error', 0, e.toString());
}
@ -229,12 +224,6 @@ class LokiSnodeAPI {
if (response.status >= 0 && response.status < 400) {
return result.nodes;
}
log.error(
options.type,
options.url,
response.status,
`Error getting swarm nodes for ${pubKey}`
);
throw HTTPError('getSwarmNodes: error response', response.status, result);
}
}

Loading…
Cancel
Save