[lib] handle race condition when creating olm session
Summary:
This is the code that chooses which session to keep and which to reset.
When there is a race condition and the device has a higher deviceID - ignore the request (the other device will get our session request and then decide to accept the session as it has a lower deviceID). Already queued messages can be ignored, while decrypting we will get OLM_SENDER_CHAIN_NOT_ACKNOWLEDGED which is different than BAD_MESSAGE_MAC so those messages will not cause a resetting session again.
When there is a race condition and the device has a lower deviceID - overwrite session and resend all messages, there is a separate task to work on this (see comment).
Depends on D11595
Test Plan:
- Create two new devices.
- Hardcode session versions (high value).
- Send session request - should be created.
- Send session request again - this simulates race condition (one device already have session with ID and receives request with the same ID).
- Device should ignore it to accept depending on deviceID - tested both cases.
Reviewers: bartek, marcin, tomek
Reviewed By: marcin
Subscribers: ashoat
Differential Revision: https://phab.comm.dev/D11596