aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2022-02-25 15:35:07 +0100
committerTobias Fella <fella@posteo.de>2022-02-25 15:35:41 +0100
commit9815e9a0a27f0c4a493ad96e9d865ee489ca9404 (patch)
treec47d9c7285227f8e9e1d4d48effe7d914dcf79b7
parent1458d1fc856c33b25c07ac16a86bbc2096110ba1 (diff)
downloadlibquotient-9815e9a0a27f0c4a493ad96e9d865ee489ca9404.tar.gz
libquotient-9815e9a0a27f0c4a493ad96e9d865ee489ca9404.zip
Save key counts to state
Otherwise new one time keys will be uploaded on every start
-rw-r--r--lib/connection.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 0ef27486..4c614176 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -117,6 +117,7 @@ public:
bool encryptionUpdateRequired = false;
PicklingMode picklingMode = Unencrypted {};
Database *database = nullptr;
+ QHash<QString, int> oneTimeKeysCount;
// A map from SenderKey to vector of InboundSession
UnorderedMap<QString, std::vector<QOlmSessionPtr>> olmSessions;
@@ -755,13 +756,12 @@ QJsonObject toJson(const DirectChatsMap& directChats)
void Connection::onSyncSuccess(SyncData&& data, bool fromCache)
{
#ifdef Quotient_E2EE_ENABLED
- const auto oneTimeKeyCount =
- static_cast<size_t>(data.deviceOneTimeKeysCount()[SignedCurve25519Key]);
- if (oneTimeKeyCount < 0.4 * d->olmAccount->maxNumberOfOneTimeKeys()
+ d->oneTimeKeysCount = data.deviceOneTimeKeysCount();
+ if (d->oneTimeKeysCount[SignedCurve25519Key] < 0.4 * d->olmAccount->maxNumberOfOneTimeKeys()
&& !d->isUploadingKeys) {
d->isUploadingKeys = true;
d->olmAccount->generateOneTimeKeys(
- d->olmAccount->maxNumberOfOneTimeKeys() / 2 - oneTimeKeyCount);
+ d->olmAccount->maxNumberOfOneTimeKeys() / 2 - d->oneTimeKeysCount[SignedCurve25519Key]);
auto keys = d->olmAccount->oneTimeKeys();
auto job = d->olmAccount->createUploadKeyRequest(keys);
run(job, ForegroundRequest);
@@ -1829,6 +1829,10 @@ void Connection::saveState() const
QJsonObject {
{ QStringLiteral("events"), accountDataEvents } });
}
+ {
+ QJsonObject keysJson = toJson(d->oneTimeKeysCount);
+ rootObj.insert(QStringLiteral("device_one_time_keys_count"), keysJson);
+ }
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
const auto data =