mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 13:08:48 +03:00
Try to avoid more olm loops
This commit is contained in:
parent
dba2fb525a
commit
bef2cbbd7f
1 changed files with 22 additions and 13 deletions
35
src/Olm.cpp
35
src/Olm.cpp
|
@ -214,12 +214,14 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
|
||||||
|
|
||||||
const auto my_key = olm::client()->identity_keys().curve25519;
|
const auto my_key = olm::client()->identity_keys().curve25519;
|
||||||
|
|
||||||
|
bool failed_decryption = false;
|
||||||
|
|
||||||
for (const auto &cipher : msg.ciphertext) {
|
for (const auto &cipher : msg.ciphertext) {
|
||||||
// We skip messages not meant for the current device.
|
// We skip messages not meant for the current device.
|
||||||
if (cipher.first != my_key) {
|
if (cipher.first != my_key) {
|
||||||
nhlog::crypto()->debug(
|
nhlog::crypto()->debug(
|
||||||
"Skipping message for {} since we are {}.", cipher.first, my_key);
|
"Skipping message for {} since we are {}.", cipher.first, my_key);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto type = cipher.second.type;
|
const auto type = cipher.second.type;
|
||||||
|
@ -234,6 +236,7 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
|
||||||
msg.sender, msg.sender_key, cipher.second);
|
msg.sender, msg.sender_key, cipher.second);
|
||||||
} else {
|
} else {
|
||||||
nhlog::crypto()->error("Undecryptable olm message!");
|
nhlog::crypto()->error("Undecryptable olm message!");
|
||||||
|
failed_decryption = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,22 +426,28 @@ handle_olm_message(const OlmMessage &msg, const UserKeyCache &otherUserDeviceKey
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
failed_decryption = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (failed_decryption) {
|
||||||
std::map<std::string, std::vector<std::string>> targets;
|
try {
|
||||||
for (auto [device_id, key] : otherUserDeviceKeys.device_keys) {
|
std::map<std::string, std::vector<std::string>> targets;
|
||||||
if (key.keys.at("curve25519:" + device_id) == msg.sender_key)
|
for (auto [device_id, key] : otherUserDeviceKeys.device_keys) {
|
||||||
targets[msg.sender].push_back(device_id);
|
if (key.keys.at("curve25519:" + device_id) == msg.sender_key)
|
||||||
}
|
targets[msg.sender].push_back(device_id);
|
||||||
|
}
|
||||||
|
|
||||||
send_encrypted_to_device_messages(
|
send_encrypted_to_device_messages(
|
||||||
targets, mtx::events::DeviceEvent<mtx::events::msg::Dummy>{}, true);
|
targets, mtx::events::DeviceEvent<mtx::events::msg::Dummy>{}, true);
|
||||||
nhlog::crypto()->info(
|
nhlog::crypto()->info("Recovering from broken olm channel with {}:{}",
|
||||||
"Recovering from broken olm channel with {}:{}", msg.sender, msg.sender_key);
|
msg.sender,
|
||||||
} catch (std::exception &e) {
|
msg.sender_key);
|
||||||
nhlog::crypto()->error("Failed to recover from broken olm sessions: {}", e.what());
|
} catch (std::exception &e) {
|
||||||
|
nhlog::crypto()->error("Failed to recover from broken olm sessions: {}",
|
||||||
|
e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue