Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions src/client/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,7 @@ impl Client {
let mut failed_count = 0;

for jid in jids {
if let Some(bundle) = prekey_bundles
.bundles
.get(&jid.normalize_for_prekey_bundle())
{
if let Some(bundle) = prekey_bundles.bundles.get(jid) {
match self
.install_prekey_bundle_cached(jid, bundle, &mut adapter, &mut rng)
.await
Expand Down Expand Up @@ -986,21 +983,13 @@ mod tests {
let mut requested_jid = Jid::lid("123456789");
requested_jid.agent = 1;

// 1. Verify direct lookup fails (This is the bug)
// The agent is inert on a LID, so it does not hide the bundle: the raw
// lookup finds it. Normalising the key first was the workaround this
// replaced, and the helper that did it is gone.
assert!(
!prekey_bundles.contains_key(&requested_jid),
"Direct lookup of non-normalized JID should fail"
prekey_bundles.contains_key(&requested_jid),
"an inert agent must not hide the bundle"
);

// 2. Verify normalized lookup succeeds (This is the fix)
// This mirrors the logic change in fetch_and_establish_sessions
let normalized_lookup = requested_jid.normalize_for_prekey_bundle();
assert!(
prekey_bundles.contains_key(&normalized_lookup),
"Normalized lookup should succeed"
);

// Ensure the normalization actually produced the key we stored
assert_eq!(normalized_lookup, normalized_jid);
assert_eq!(requested_jid, normalized_jid);
}
}
6 changes: 1 addition & 5 deletions src/prekeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,7 @@ impl Client {
const COMPANION_IDENTITY_LOAD_CONCURRENCY: usize = 16;
let companions: Vec<Jid> = jids.iter().filter(|j| j.device != 0).cloned().collect();
futures::stream::iter(companions)
.map(|jid| async move {
self.load_account_identity(&jid)
.await
.map(|id| (jid.normalize_for_prekey_bundle(), id))
})
.map(|jid| async move { self.load_account_identity(&jid).await.map(|id| (jid, id)) })
.buffer_unordered(COMPANION_IDENTITY_LOAD_CONCURRENCY)
.filter_map(|entry| async move { entry })
.collect()
Expand Down
4 changes: 2 additions & 2 deletions wacore/binary/benches/jid_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ fn bench_jid_to_non_ad_string(bencher: divan::Bencher) {
/// The per-recipient fan-out formatter: writes the AD form into a reused
/// buffer instead of allocating a String per device.
#[divan::bench]
fn bench_jid_push_ad_to(bencher: divan::Bencher) {
fn bench_jid_push_phash_form(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let mut jid = Jid::lid("123456789012345");
jid.device = 7;
(jid, String::with_capacity(64))
})
.bench_refs(|(jid, buf)| {
jid.push_ad_to(buf);
jid.push_phash_form_to(buf);
// black-box the contents, not just the length: observing only
// `len` lets LLVM elide the actual formatting writes.
black_box(buf.as_bytes());
Expand Down
Loading
Loading