Restart sendMessage logic if PoW changed an dfix NaN bug

pull/294/head
Beaudan 6 years ago
parent f01d8088b7
commit 7141847dfb

@ -124,7 +124,17 @@ class LokiMessageAPI {
promises.push(this.openSendConnection(params));
}
const results = await Promise.all(promises);
let results;
try {
results = await Promise.all(promises);
} catch (e) {
if (e instanceof textsecure.WrongDifficultyError) {
// Force nonce recalculation
this.sendMessage(pubKey, data, messageTimeStamp, ttl, options);
return;
}
throw e;
}
delete this.sendingSwarmNodes[timestamp];
if (results.every(value => value === false)) {
throw new window.textsecure.EmptySwarmError(
@ -155,15 +165,17 @@ class LokiMessageAPI {
while (successiveFailures < 3) {
await sleepFor(successiveFailures * 500);
try {
const result = await rpc(`http://${url}`, this.snodeServerPort, 'store', params);
const result = await rpc(
`http://${url}`,
this.snodeServerPort,
'store',
params
);
// Make sure we aren't doing too much PoW
const currentDifficulty = window.storage.get('PoWDifficulty', null);
const newDifficulty = result.difficulty;
if (
!Number.isNaN(newDifficulty) &&
newDifficulty !== currentDifficulty
) {
if (newDifficulty != null && newDifficulty !== currentDifficulty) {
window.storage.put('PoWDifficulty', newDifficulty);
}
return true;
@ -179,6 +191,7 @@ class LokiMessageAPI {
if (!Number.isNaN(newDifficulty)) {
window.storage.put('PoWDifficulty', newDifficulty);
}
throw e;
} else if (e instanceof textsecure.NotFoundError) {
// TODO: Handle resolution error
successiveFailures += 1;

Loading…
Cancel
Save