fix up handling of clock out of sync

This commit is contained in:
Audric Ackermann 2021-06-29 14:55:59 +10:00
parent e85f69a144
commit 504a9afc0a
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4
4 changed files with 15 additions and 9 deletions

View File

@ -846,7 +846,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
const chatParams = {
identifier: this.id,
body,
timestamp: this.get('sent_at') || Date.now(),
timestamp: Date.now(), // force a new timestamp to handle user fixed his clock
expireTimer: this.get('expireTimer'),
attachments,
preview,

View File

@ -70,11 +70,11 @@ export async function sendMessage(
);
throw e;
}
if (!snode) {
if (!usedNodes || usedNodes.length === 0) {
throw new window.textsecure.EmptySwarmError(pubKey, 'Ran out of swarm nodes to query');
} else {
window?.log?.info(
`loki_message:::sendMessage - Successfully stored message to ${pubKey} via ${snode.ip}:${snode.port}`
);
}
window?.log?.info(
`loki_message:::sendMessage - Successfully stored message to ${pubKey} via ${snode.ip}:${snode.port}`
);
}

View File

@ -496,8 +496,8 @@ export async function storeOnNode(targetNode: Snode, params: SendParams): Promis
e,
`destination ${targetNode.ip}:${targetNode.port}`
);
throw e;
}
return false;
}
/** */

View File

@ -38,6 +38,9 @@ export interface SnodeResponse {
export const NEXT_NODE_NOT_FOUND_PREFIX = 'Next node not found: ';
export const CLOCK_OUT_OF_SYNC_MESSAGE_ERROR =
'You clock is out of sync with the network. Check your clock';
// Returns the actual ciphertext, symmetric key that will be used
// for decryption, and an ephemeral_key to send to the next hop
async function encryptForPubKey(pubKeyX25519hex: string, reqObj: any): Promise<DestinationContext> {
@ -196,9 +199,8 @@ async function buildOnionGuardNodePayload(
function process406Error(statusCode: number) {
if (statusCode === 406) {
// clock out of sync
console.warn('clock out of sync todo');
// this will make the pRetry stop
throw new pRetry.AbortError('You clock is out of sync with the network. Check your clock.');
throw new pRetry.AbortError(CLOCK_OUT_OF_SYNC_MESSAGE_ERROR);
}
}
@ -881,6 +883,10 @@ export async function lokiOnionFetch(
// better handle the no connection state
throw new Error(ERROR_CODE_NO_CONNECT);
}
if (e?.message === CLOCK_OUT_OF_SYNC_MESSAGE_ERROR) {
window?.log?.warn('Its an clock out of sync error ');
throw new pRetry.AbortError(CLOCK_OUT_OF_SYNC_MESSAGE_ERROR);
}
throw e;
}
}