You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
don't always do second phase of olm creation
don't need to do the shorter timeout when doing preparation to encrypt, and skip the second phase if the first phase already took longer than a normal otk claim
This commit is contained in:
@@ -185,12 +185,14 @@ utils.inherits(MegolmEncryption, EncryptionAlgorithm);
|
|||||||
*
|
*
|
||||||
* @param {Object} devicesInRoom The devices in this room, indexed by user ID
|
* @param {Object} devicesInRoom The devices in this room, indexed by user ID
|
||||||
* @param {Object} blocked The devices that are blocked, indexed by user ID
|
* @param {Object} blocked The devices that are blocked, indexed by user ID
|
||||||
|
* @param {boolean} [singleOlmCreationPhase] Only perform one round of olm
|
||||||
|
* session creation
|
||||||
*
|
*
|
||||||
* @return {Promise} Promise which resolves to the
|
* @return {Promise} Promise which resolves to the
|
||||||
* OutboundSessionInfo when setup is complete.
|
* OutboundSessionInfo when setup is complete.
|
||||||
*/
|
*/
|
||||||
MegolmEncryption.prototype._ensureOutboundSession = async function(
|
MegolmEncryption.prototype._ensureOutboundSession = async function(
|
||||||
devicesInRoom, blocked,
|
devicesInRoom, blocked, singleOlmCreationPhase,
|
||||||
) {
|
) {
|
||||||
let session;
|
let session;
|
||||||
|
|
||||||
@@ -270,12 +272,19 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
|
|||||||
const errorDevices = [];
|
const errorDevices = [];
|
||||||
|
|
||||||
// meanwhile, establish olm sessions for devices that we don't
|
// meanwhile, establish olm sessions for devices that we don't
|
||||||
// already have a session for, and share keys with them. Use a
|
// already have a session for, and share keys with them. If
|
||||||
// shorter timeout when fetching one-time keys.
|
// we're doing two phases of olm session creation, use a
|
||||||
|
// shorter timeout when fetching one-time keys for the first
|
||||||
|
// phase.
|
||||||
|
const start = Date.now();
|
||||||
await this._shareKeyWithDevices(
|
await this._shareKeyWithDevices(
|
||||||
session, key, payload, devicesWithoutSession, errorDevices, 2000,
|
session, key, payload, devicesWithoutSession, errorDevices,
|
||||||
|
singleOlmCreationPhase ? 10000 : 2000,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!singleOlmCreationPhase && (Date.now() - start < 10000)) {
|
||||||
|
// perform the second phase of olm session creation if requested,
|
||||||
|
// and if the first phase didn't take too long
|
||||||
(async () => {
|
(async () => {
|
||||||
// Retry sending keys to devices that we were unable to establish
|
// Retry sending keys to devices that we were unable to establish
|
||||||
// an olm session for. This time, we use a longer timeout, but we
|
// an olm session for. This time, we use a longer timeout, but we
|
||||||
@@ -314,12 +323,15 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
|
|||||||
|
|
||||||
// mark this device as "handled" because we don't want to try
|
// mark this device as "handled" because we don't want to try
|
||||||
// to claim a one-time-key for dead devices on every message.
|
// to claim a one-time-key for dead devices on every message.
|
||||||
session.markSharedWithDevice(userId, deviceId, key.chain_index);
|
session.markSharedWithDevice(
|
||||||
|
userId, deviceId, key.chain_index,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify devices that we couldn't get an olm session
|
// notify devices that we couldn't get an olm session
|
||||||
await this._notifyBlockedDevices(session, blockedMap);
|
await this._notifyBlockedDevices(session, blockedMap);
|
||||||
})();
|
})();
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
(async () => {
|
(async () => {
|
||||||
// also, notify blocked devices that they're blocked
|
// also, notify blocked devices that they're blocked
|
||||||
@@ -786,7 +798,7 @@ MegolmEncryption.prototype.prepareToEncrypt = function(room) {
|
|||||||
this._removeUnknownDevices(devicesInRoom);
|
this._removeUnknownDevices(devicesInRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this._ensureOutboundSession(devicesInRoom, blocked);
|
await this._ensureOutboundSession(devicesInRoom, blocked, true);
|
||||||
|
|
||||||
delete this.encryptionPreparation;
|
delete this.encryptionPreparation;
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user