You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Fix a few e2e backup bits
* Don't _maybeSendKeyBackup() as soon as we enable them: we shouldn't have anything to send anyway until we mark all sessions for backup, which we do just afterwards, so leave that to trigger the upload (otherwise the uploading triggered by backupAll just returns straight away because a backup is already in progress). * Pass delay & retry params to _maybeSendKeyBackup(): we want the all-key upload to happen straight away so pass in delay=0, and we also don't want to retry on a timer if the the user is waiting. * If we fail due to an HTTP 400 or similar, don't swallow the error. * Use the right indexeddb store
This commit is contained in:
@@ -839,8 +839,6 @@ MatrixClient.prototype.enableKeyBackup = function(info) {
|
|||||||
this._crypto.backupKey.set_recipient_key(info.auth_data.public_key);
|
this._crypto.backupKey.set_recipient_key(info.auth_data.public_key);
|
||||||
|
|
||||||
this.emit('keyBackupStatus', true);
|
this.emit('keyBackupStatus', true);
|
||||||
|
|
||||||
this._crypto._maybeSendKeyBackup();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -970,16 +970,21 @@ Crypto.prototype.importRoomKeys = function(keys) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Crypto.prototype._maybeSendKeyBackup = async function() {
|
Crypto.prototype._maybeSendKeyBackup = async function(delay, retry) {
|
||||||
|
if (retry === undefined) retry = true;
|
||||||
|
|
||||||
if (!this._sendingBackups) {
|
if (!this._sendingBackups) {
|
||||||
this._sendingBackups = true;
|
this._sendingBackups = true;
|
||||||
try {
|
try {
|
||||||
// wait between 0 and 10 seconds, to avoid backup requests from
|
if (delay === undefined) {
|
||||||
// different clients hitting the server all at the same time when a
|
// by default, wait between 0 and 10 seconds, to avoid backup
|
||||||
// new key is sent
|
// requests from different clients hitting the server all at
|
||||||
await new Promise((resolve, reject) => {
|
// the same time when a new key is sent
|
||||||
setTimeout(resolve, Math.random() * 10000);
|
delay = Math.random() * 10000;
|
||||||
});
|
}
|
||||||
|
if (delay > 0) {
|
||||||
|
await Promise.delay(delay);
|
||||||
|
}
|
||||||
let numFailures = 0; // number of consecutive failures
|
let numFailures = 0; // number of consecutive failures
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!this.backupKey) {
|
if (!this.backupKey) {
|
||||||
@@ -1034,10 +1039,11 @@ Crypto.prototype._maybeSendKeyBackup = async function() {
|
|||||||
console.log("send failed", err);
|
console.log("send failed", err);
|
||||||
if (err.httpStatus === 400
|
if (err.httpStatus === 400
|
||||||
|| err.httpStatus === 403
|
|| err.httpStatus === 403
|
||||||
|| err.httpStatus === 401) {
|
|| err.httpStatus === 401
|
||||||
|
|| !retry) {
|
||||||
// retrying probably won't help much, so we should give up
|
// retrying probably won't help much, so we should give up
|
||||||
// FIXME: disable backups?
|
// FIXME: disable backups?
|
||||||
return;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numFailures) {
|
if (numFailures) {
|
||||||
@@ -1076,7 +1082,7 @@ Crypto.prototype.backupGroupSession = async function(
|
|||||||
Crypto.prototype.backupAllGroupSessions = async function(version) {
|
Crypto.prototype.backupAllGroupSessions = async function(version) {
|
||||||
await this._cryptoStore.doTxn(
|
await this._cryptoStore.doTxn(
|
||||||
'readwrite',
|
'readwrite',
|
||||||
[IndexedDBCryptoStore.STORE_SESSIONS, IndexedDBCryptoStore.STORE_BACKUP],
|
[IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS, IndexedDBCryptoStore.STORE_BACKUP],
|
||||||
(txn) => {
|
(txn) => {
|
||||||
this._cryptoStore.getAllEndToEndInboundGroupSessions(txn, (session) => {
|
this._cryptoStore.getAllEndToEndInboundGroupSessions(txn, (session) => {
|
||||||
if (session !== null) {
|
if (session !== null) {
|
||||||
@@ -1086,7 +1092,7 @@ Crypto.prototype.backupAllGroupSessions = async function(version) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await this._maybeSendKeyBackup();
|
await this._maybeSendKeyBackup(0, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* eslint-disable valid-jsdoc */ //https://github.com/eslint/eslint/issues/7307
|
/* eslint-disable valid-jsdoc */ //https://github.com/eslint/eslint/issues/7307
|
||||||
|
|||||||
Reference in New Issue
Block a user