crypto: Simplify counting the number of messages a to-device request has

master
Damir Jelić 2021-03-13 11:50:05 +01:00
parent 880818a588
commit 75ac29540d
2 changed files with 15 additions and 3 deletions

View File

@ -63,6 +63,14 @@ impl ToDeviceRequest {
pub fn txn_id_string(&self) -> String { pub fn txn_id_string(&self) -> String {
self.txn_id.to_string() self.txn_id.to_string()
} }
/// Get the number of unique messages this request contains.
///
/// *Note*: A single message may be sent to multiple devices, so this may or
/// may not be the number of devices that will receive the messages as well.
pub fn message_count(&self) -> usize {
self.messages.values().map(|d| d.len()).sum()
}
} }
/// Request that will publish a cross signing identity. /// Request that will publish a cross signing identity.

View File

@ -251,6 +251,12 @@ impl GroupSessionManager {
messages, messages,
}; };
trace!(
recipient_count = request.message_count(),
transaction_id = ?id,
"Created a to-device request carrying a room_key"
);
Ok((id, request, changed_sessions)) Ok((id, request, changed_sessions))
} }
@ -593,9 +599,7 @@ mod test {
.await .await
.unwrap(); .unwrap();
let event_count = requests.iter().fold(0, |acc, r| { let event_count: usize = requests.iter().map(|r| r.message_count()).sum();
acc + r.messages.values().fold(0, |acc, v| acc + v.len())
});
// The keys claim response has a couple of one-time keys with invalid // The keys claim response has a couple of one-time keys with invalid
// signatures, thus only 148 sessions are actually created, we check // signatures, thus only 148 sessions are actually created, we check