aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-05-11Fix race condition in consumeRoomData()Alexey Rusakov
QCoreApplication::processEvents() is well-known to be a _wrong_ solution to the unresponsive UI problem; despite that, connection.cpp has long had that call to let UI update itself while processing bulky room updates (mainly from the initial sync). This commit finally fixes this, after an (admittedly rare) race condition has been hit, as follows: 0. Pre-requisite: quotest runs all the tests and is about to leave the room; there's an ongoing sync request. 1. Quotest calls /leave 2. Sync returns, with the batch of _several_ rooms (that's important) 3. The above code handles the first room in the batch 4. processEvents() is called, just in time for the /leave response. 5. The /leave response handler in quotest ends up calling Connection::logout() (processEvents() still hasn't returned). 6. Connection::logout() calls abandon() on the ongoing SyncJob, pulling the rug from under onSyncSuccess()/consumeRoomData(). 7. processEvents() returns and the above code proceeds to the next room - only to find that the roomDataList (that is a ref to a structure owned by SyncJob), is now pointing to garbage. Morals of the story: 1. processEvents() effectively makes code multi-threaded: one flow is suspended and another one may run _on the same data_. After the first flow is resumed, it cannot make any assumptions regarding which data the second flow touched and/or changed. 2. The library had quite a few cases of using &&-refs, avoiding even move operations but also leaving ownership of the data with the original producer (SyncJob). If the lifetime of that producer ends too soon, those refs become dangling. The fix makes two important things, respectively: 2. Ownership of room data is now transfered to the processing side, the moment it is scheduled (see below), in the form of moving into a lambda capture. 1. Instead of processEvents(), processing of room data is scheduled via QMetaObject::invokeMethod(), uncoupling the moment when the data was received in SyncJob from the moment they are processed in Room::updateData() (and all the numerous signal-slots it calls). Also: Room::baseStateLoaded now causes Connection::loadedRoomState, not the other way round - this is more natural and doesn't need Connection to keep firstTimeRooms map around.
2022-05-08Merge #548: Streamline usage of event types, part 1Alexey Rusakov
2022-05-08QUO_CONTENT_GETTERAlexey Rusakov
To streamline adding of simple getters of content parts.
2022-05-08Use std::pair instead of QPairAlexey Rusakov
QPair is giving way to its STL counterpart, becoming its alias in Qt 6.
2022-05-08More cleanupAlexey Rusakov
2022-05-08Generalise DEFINE_SIMPLE_EVENTAlexey Rusakov
This macro was defined in accountdataevents.h but adding one more parameter (base class) makes it applicable to pretty much any event with the content that has one key-value pair (though state events already have a non-macro solution in the form of `StateEvent<EventContent::SingleKeyValue>`). Now CustomEvent definition in quotest.cpp can be replaced with a single line.
2022-05-08Pass matrixType(QString), not Event::Type, to basicJson()Alexey Rusakov
Not that it was very important, as the two are basically the same thing (and matrixTypeId() is about to be obsoleted); but formally basicJson() is supposed to get the former, not the latter.
2022-05-08basic*EventJson() -> *Event::basicJson()Alexey Rusakov
This makes it easier and more intuitive to build a minimal JSON payload for a given event type. A common basicJson() call point is also convenient in template contexts (see next commits).
2022-05-08Event content: provide toJson() instead of deriving from EC::BaseAlexey Rusakov
EventContent::Base has been made primarily for the sake of dynamic polymorphism needed within RoomMessageEvent content (arguably, it might not be really needed even there, but that's a bigger matter for another time). When that polymorphism is not needed, it's easier for reading and maintenance to have toJson() member function (or even specialise JsonConverter<> outside of the content structure) instead of deriving from EC::Base and then still having fillJson() member function. This commit removes EventContent::Base dependency where it's not beneficial.
2022-05-08Simplify EventContent a bitAlexey Rusakov
Main changes: 1. Base::fillJson() gets a QJsonObject& instead of QJsonObject* - c'mon, there's nothing inherently wrong with using an lvalue reference for a read-write parameter. 2. UrlWithThumbnailContent merged into UrlBasedContent. The original UrlBasedContent was only used to produce a single class, AudioContent, and even that can logically have a thumbnail even if the spec doesn't provision that. And there's no guarantee even for visual content (ImageContent, e.g.) to have thumbnail data; the fallback is already tested. 3. toInfoJson is converted from a template to a couple of overloads that supersede fillInfoJson() member functions in FileInfo/ImageInfo. These overloads are easier on the eye; and clang-tidy no more warns about ImageInfo::fillInfoJson() shadowing FileInfo::fillInfoJson(). 4. Now that UrlWithThumbnail is gone, PlayableContent can directly derive from UrlBasedContent since both its specialisations use it. 5. Instead of FileInfo/ImageInfo, fillInfoJson() has been reinvented within UrlBasedContent so that, in particular, PlayableContent wouldn't need to extract 'info' subobject and then roll it back inside the content JSON object.
2022-05-08Cleanup; comments reformattingAlexey Rusakov
2022-05-08StateEvent: use non-member JSON convertersAlexey Rusakov
With the reworked JsonConverter code it is possible to work uniformly with structures that have a member toJson() and a constructor converting from QJsonObject, as well as with structures that rely on an external JsonConverter specialisation.
2022-05-08toSnakeCase and EventContent::SingleKeyValueAlexey Rusakov
This is a rework of EventContent::SimpleContent previously defined in simplestateevents.h. Quite a few events (and not only state events) have just a single key-value pair in their content - this structure (which is really just a template wrapper around the value) and the accompanying JsonConverter<> specialisation encapsulate the concept to streamline definition of such events. This commit only has simplestateevents.h using it; further commits will use SingleKeyValue in other places. toSnakeCase is a facility function that converts camelCase used for C++ variables into snake_case used in JSON payloads. Combined with the preprocessor trick that makes a string literal from an identifier, this allows to reduce boilerplate code that repeats the same name for fields in C++ event classes and fields in JSON. SingleKeyValue uses it, and there are other cases for it coming.
2022-05-05Fix license identifierTobias Fella
2022-05-04CMakeLists.txt: add roomcanonicalaliasevent.hAlexey Rusakov
Yet another missing header from times when .h files weren't added to CMakeLists.
2022-04-23CleanupAlexey Rusakov
2022-04-23SLICE()Alexey Rusakov
Add a macro to make slicing clear in the code and quiet for static analysis.
2022-04-16Merge pull request #544 from TobiasFella/checkedkeyAlexey Rusakov
Check edKey when receiving an olm message and prepare for MSC 3700
2022-04-16Use more idiomatic C++Tobias Fella
2022-04-16Only build function when E2EE is enabledTobias Fella
2022-04-16Try fixing lgtm.comTobias Fella
2022-04-09Comment out debug statementTobias Fella
2022-04-09Prepare for MSC 3700Tobias Fella
2022-04-09Don't crash when decrypting existing messagesTobias Fella
2022-04-09Make sure devices are known before decrypting olm messagesTobias Fella
2022-04-09Check edKey when receiving an olm messageTobias Fella
2022-04-09Correctly load EncryptedEventsTobias Fella
2022-03-12Merge #543: Fix loading images when E2EE is disabledAlexey Rusakov
2022-03-11Fix loading images when E2EE is disabledTobias Fella
2022-03-10Merge pull request #541 from TobiasFella/storesessionedkeyAlexey Rusakov
Store some more things in the database
2022-03-09Check for empty ed25519 key.Tobias Fella
2022-03-09Update lib/database.cppTobias Fella
Co-authored-by: Carl Schwan <carl@carlschwan.eu>
2022-03-09Merge #542: Guard against device reuse attacksAlexey Rusakov
2022-03-08Store time of last decrypted message for each olm sessionTobias Fella
Is required to correctly choose a session to use for sending messages
2022-03-07Add datbase migrationTobias Fella
2022-03-07Guard against device reuse attacksTobias Fella
2022-03-07Store the device's ed25519 in the databaseTobias Fella
2022-02-27Merge #538: Verification should return false instead of error for failed ↵Alexey Rusakov
signature checks
2022-02-27Merge #535: Convenience functions for querying user devices and keys from cacheAlexey Rusakov
2022-02-27Build with shared libs for SonarAlexey Rusakov
Building with static libs fails on QtKeychain apparently underlinking with glib when --coverage is passed.
2022-02-27Update lib/e2ee/qolmutility.cppTobias Fella
Co-authored-by: Carl Schwan <carl@carlschwan.eu>
2022-02-27Return false instead of error for failed signature checksTobias Fella
2022-02-27Merge pull request #537 from TobiasFella/decryptcheckroomAlexey Rusakov
2022-02-27Apply suggestionsTobias Fella
2022-02-27Apply suggestionsTobias Fella
2022-02-27Merge #536: Use QOlmMessage::Type in more placesAlexey Rusakov
2022-02-27CI: switch sonar CI config to include E2EEAlexey Rusakov
2022-02-27Merge #534: Handle to-device messages before handling roomdataAlexey Rusakov
2022-02-26Check that decrypted events are for the current roomTobias Fella
2022-02-26Use QOlmMessage::Type in more placesTobias Fella
Make sure that the enum values correspond to the values used in the spec and use them instead of magic constants