Fix edge case that could lead to no new one time keys being uploaded

This commit is contained in:
Nicolas Werner 2021-07-24 14:59:14 +02:00
parent ace16b8c4d
commit a61678242b
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
1 changed files with 23 additions and 21 deletions

View File

@ -929,31 +929,33 @@ ChatPage::currentPresence() const
void void
ChatPage::ensureOneTimeKeyCount(const std::map<std::string, uint16_t> &counts) ChatPage::ensureOneTimeKeyCount(const std::map<std::string, uint16_t> &counts)
{ {
for (const auto &entry : counts) { uint16_t count = 0;
if (entry.second < MAX_ONETIME_KEYS) { if (auto c = counts.find(mtx::crypto::SIGNED_CURVE25519); c != counts.end())
const int nkeys = MAX_ONETIME_KEYS - entry.second; count = c->second;
nhlog::crypto()->info("uploading {} {} keys", nkeys, entry.first); if (count < MAX_ONETIME_KEYS) {
olm::client()->generate_one_time_keys(nkeys); const int nkeys = MAX_ONETIME_KEYS - count;
http::client()->upload_keys( nhlog::crypto()->info(
olm::client()->create_upload_keys_request(), "uploading {} {} keys", nkeys, mtx::crypto::SIGNED_CURVE25519);
[](const mtx::responses::UploadKeys &, mtx::http::RequestErr err) { olm::client()->generate_one_time_keys(nkeys);
if (err) {
nhlog::crypto()->warn(
"failed to update one-time keys: {} {} {}",
err->matrix_error.error,
static_cast<int>(err->status_code),
static_cast<int>(err->error_code));
if (err->status_code < 400 || err->status_code >= 500) http::client()->upload_keys(
return; olm::client()->create_upload_keys_request(),
} [](const mtx::responses::UploadKeys &, mtx::http::RequestErr err) {
if (err) {
nhlog::crypto()->warn("failed to update one-time keys: {} {} {}",
err->matrix_error.error,
static_cast<int>(err->status_code),
static_cast<int>(err->error_code));
// mark as published anyway, otherwise we may end up in a loop. if (err->status_code < 400 || err->status_code >= 500)
olm::mark_keys_as_published(); return;
}); }
}
// mark as published anyway, otherwise we may end up in a loop.
olm::mark_keys_as_published();
});
} }
} }