diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-06-23 08:34:53 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-06-23 18:37:08 +0200 |
commit | 143ac38aabab90b40fbe73b489b91fb159e66b6b (patch) | |
tree | 4781d895b1b5c0fe42dc50a104fa7b752db7489e /lib | |
parent | 19746de7426aeb67eb90e8c48448356691e270b0 (diff) | |
download | libquotient-143ac38aabab90b40fbe73b489b91fb159e66b6b.tar.gz libquotient-143ac38aabab90b40fbe73b489b91fb159e66b6b.zip |
Streamline Room::P::shouldRotateMegolmSession()
Now there's only 1 instead of 5 lookups of the same EncryptionEvent,
and the code is shorter.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/events/encryptionevent.h | 2 | ||||
-rw-r--r-- | lib/room.cpp | 30 |
2 files changed, 12 insertions, 20 deletions
diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h index c73e5598..945b17e7 100644 --- a/lib/events/encryptionevent.h +++ b/lib/events/encryptionevent.h @@ -52,6 +52,8 @@ public: QString algorithm() const { return content().algorithm; } int rotationPeriodMs() const { return content().rotationPeriodMs; } int rotationPeriodMsgs() const { return content().rotationPeriodMsgs; } + + bool useEncryption() const { return !algorithm().isEmpty(); } }; REGISTER_EVENT_TYPE(EncryptionEvent) } // namespace Quotient diff --git a/lib/room.cpp b/lib/room.cpp index 2d4cfeb4..35a89cc6 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -411,10 +411,17 @@ public: bool shouldRotateMegolmSession() const { - if (!q->usesEncryption()) { + const auto* encryptionConfig = currentState.get<EncryptionEvent>(); + if (!encryptionConfig || !encryptionConfig->useEncryption()) return false; - } - return currentOutboundMegolmSession->messageCount() >= rotationMessageCount() || currentOutboundMegolmSession->creationTime().addMSecs(rotationInterval()) < QDateTime::currentDateTime(); + + const auto rotationInterval = encryptionConfig->rotationPeriodMs(); + const auto rotationMessageCount = encryptionConfig->rotationPeriodMsgs(); + return currentOutboundMegolmSession->messageCount() + >= rotationMessageCount + || currentOutboundMegolmSession->creationTime().addMSecs( + rotationInterval) + < QDateTime::currentDateTime(); } bool hasValidMegolmSession() const @@ -425,23 +432,6 @@ public: return currentOutboundMegolmSession != nullptr; } - /// Time in milliseconds after which the outgoing megolmsession should be replaced - unsigned int rotationInterval() const - { - if (!q->usesEncryption()) { - return 0; - } - return q->getCurrentState<EncryptionEvent>()->rotationPeriodMs(); - } - - // Number of messages sent by this user after which the outgoing megolm session should be replaced - int rotationMessageCount() const - { - if (!q->usesEncryption()) { - return 0; - } - return q->getCurrentState<EncryptionEvent>()->rotationPeriodMsgs(); - } void createMegolmSession() { qCDebug(E2EE) << "Creating new outbound megolm session for room " << q->objectName(); |