Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3380739
D11594.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11594.diff
View Options
diff --git a/lib/handlers/peer-to-peer-message-handler.js b/lib/handlers/peer-to-peer-message-handler.js
--- a/lib/handlers/peer-to-peer-message-handler.js
+++ b/lib/handlers/peer-to-peer-message-handler.js
@@ -9,6 +9,7 @@
type PeerToPeerMessage,
} from '../types/tunnelbroker/peer-to-peer-message-types.js';
import { getConfig } from '../utils/config.js';
+import { olmSessionErrors } from '../utils/olm-utils.js';
async function peerToPeerMessageHandler(
message: PeerToPeerMessage,
@@ -16,17 +17,16 @@
): Promise<void> {
const { olmAPI } = getConfig();
if (message.type === peerToPeerMessageTypes.OUTBOUND_SESSION_CREATION) {
+ const { senderInfo, encryptedData, sessionVersion } = message;
+ const { userID: senderUserID, deviceID: senderDeviceID } = senderInfo;
try {
- const { senderInfo, encryptedData, sessionVersion } = message;
- const { keys } = await identityClient.getInboundKeysForUser(
- senderInfo.userID,
- );
+ const { keys } = await identityClient.getInboundKeysForUser(senderUserID);
- const deviceKeys: ?DeviceOlmInboundKeys = keys[senderInfo.deviceID];
+ const deviceKeys: ?DeviceOlmInboundKeys = keys[senderDeviceID];
if (!deviceKeys) {
throw new Error(
'No keys for the device that requested creating a session, ' +
- `deviceID: ${senderInfo.deviceID}`,
+ `deviceID: ${senderDeviceID}`,
);
}
@@ -38,14 +38,27 @@
);
console.log(
'Created inbound session with device ' +
- `${message.senderInfo.deviceID}: ${result}, ` +
+ `${senderDeviceID}: ${result}, ` +
`session version: ${sessionVersion}`,
);
} catch (e) {
- console.log(
- 'Error creating inbound session with device ' +
- `${message.senderInfo.deviceID}: ${e.message}`,
- );
+ if (e.message?.includes(olmSessionErrors.alreadyCreated)) {
+ console.log(
+ 'Received session request with lower session version from ' +
+ `${senderDeviceID}, session version: ${sessionVersion}`,
+ );
+ } else if (e.message?.includes(olmSessionErrors.raceCondition)) {
+ console.log(
+ 'Race condition while creating session with ' +
+ `${senderDeviceID}, session version: ${sessionVersion}`,
+ );
+ } else {
+ console.log(
+ 'Error creating inbound session with device ' +
+ `${senderDeviceID}: ${e.message}, ` +
+ `session version: ${sessionVersion}`,
+ );
+ }
}
} else if (message.type === peerToPeerMessageTypes.ENCRYPTED_MESSAGE) {
try {
diff --git a/lib/utils/olm-utils.js b/lib/utils/olm-utils.js
--- a/lib/utils/olm-utils.js
+++ b/lib/utils/olm-utils.js
@@ -116,6 +116,15 @@
return { identityKeys, prekey, prekeySignature };
}
+const olmSessionErrors = Object.freeze({
+ // Two clients send the session request to each other at the same time,
+ // we choose which session to keep based on `deviceID`.
+ raceCondition: 'OLM_SESSION_CREATION_RACE_CONDITION',
+ // The client received a session request with a lower session version,
+ // this request can be ignored.
+ alreadyCreated: 'OLM_SESSION_ALREADY_CREATED',
+});
+
export {
retrieveAccountKeysSet,
getAccountPrekeysSet,
@@ -123,4 +132,5 @@
shouldRotatePrekey,
getAccountOneTimeKeys,
retrieveIdentityKeysAndPrekeys,
+ olmSessionErrors,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 1:50 AM (21 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595414
Default Alt Text
D11594.diff (3 KB)
Attached To
Mode
D11594: [lib] errors utils to distinguish between session creation issues
Attached
Detach File
Event Timeline
Log In to Comment