|
|
|
@ -1856,28 +1856,51 @@ fn get_auth_chain( |
|
|
|
) -> Result<impl Iterator<Item = EventId> + '_> { |
|
|
|
) -> Result<impl Iterator<Item = EventId> + '_> { |
|
|
|
let mut full_auth_chain = HashSet::new(); |
|
|
|
let mut full_auth_chain = HashSet::new(); |
|
|
|
|
|
|
|
|
|
|
|
let starting_events = starting_events |
|
|
|
let mut events = starting_events |
|
|
|
.iter() |
|
|
|
.iter() |
|
|
|
.map(|id| { |
|
|
|
.map(|id| { |
|
|
|
db.rooms |
|
|
|
db.rooms |
|
|
|
.get_or_create_shorteventid(id, &db.globals) |
|
|
|
.get_or_create_shorteventid(id, &db.globals) |
|
|
|
.map(|s| (s, id)) |
|
|
|
.map(|s| (s, id.clone())) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.collect::<Result<Vec<_>>>()?; |
|
|
|
.collect::<Result<Vec<_>>>()?; |
|
|
|
|
|
|
|
|
|
|
|
let mut cache = db.rooms.auth_chain_cache(); |
|
|
|
let mut cache = db.rooms.auth_chain_cache(); |
|
|
|
|
|
|
|
|
|
|
|
for (sevent_id, event_id) in starting_events { |
|
|
|
while events.len() != 0 { |
|
|
|
if let Some(cached) = cache.get_mut(&sevent_id) { |
|
|
|
let mut new_events = Vec::new(); |
|
|
|
full_auth_chain.extend(cached.iter().cloned()); |
|
|
|
for (sevent_id, event_id) in &events { |
|
|
|
} else { |
|
|
|
if let Some(cached) = cache.get_mut(&sevent_id) { |
|
|
|
drop(cache); |
|
|
|
full_auth_chain.extend(cached.iter().cloned()); |
|
|
|
let mut auth_chain = HashSet::new(); |
|
|
|
} else { |
|
|
|
get_auth_chain_recursive(&event_id, &mut auth_chain, db)?; |
|
|
|
drop(cache); |
|
|
|
cache = db.rooms.auth_chain_cache(); |
|
|
|
let mut auth_chain = HashSet::new(); |
|
|
|
cache.insert(sevent_id, auth_chain.clone()); |
|
|
|
let r = db.rooms.get_pdu(&event_id); |
|
|
|
full_auth_chain.extend(auth_chain); |
|
|
|
match r { |
|
|
|
}; |
|
|
|
Ok(Some(pdu)) => { |
|
|
|
|
|
|
|
for auth_event in &pdu.auth_events { |
|
|
|
|
|
|
|
let sauthevent = db |
|
|
|
|
|
|
|
.rooms |
|
|
|
|
|
|
|
.get_or_create_shorteventid(auth_event, &db.globals)?; |
|
|
|
|
|
|
|
if !auth_chain.contains(&sauthevent) { |
|
|
|
|
|
|
|
auth_chain.insert(sauthevent); |
|
|
|
|
|
|
|
new_events.push((sauthevent, auth_event.clone())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Ok(None) => { |
|
|
|
|
|
|
|
warn!("Could not find pdu mentioned in auth events."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Err(e) => { |
|
|
|
|
|
|
|
warn!("Could not load event in auth chain: {}", e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cache = db.rooms.auth_chain_cache(); |
|
|
|
|
|
|
|
cache.insert(*sevent_id, auth_chain.clone()); |
|
|
|
|
|
|
|
full_auth_chain.extend(auth_chain); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
events = new_events; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
drop(cache); |
|
|
|
drop(cache); |
|
|
|
@ -1887,35 +1910,6 @@ fn get_auth_chain( |
|
|
|
.filter_map(move |sid| db.rooms.get_eventid_from_short(sid).ok())) |
|
|
|
.filter_map(move |sid| db.rooms.get_eventid_from_short(sid).ok())) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_auth_chain_recursive( |
|
|
|
|
|
|
|
event_id: &EventId, |
|
|
|
|
|
|
|
found: &mut HashSet<u64>, |
|
|
|
|
|
|
|
db: &Database, |
|
|
|
|
|
|
|
) -> Result<()> { |
|
|
|
|
|
|
|
let r = db.rooms.get_pdu(&event_id); |
|
|
|
|
|
|
|
match r { |
|
|
|
|
|
|
|
Ok(Some(pdu)) => { |
|
|
|
|
|
|
|
for auth_event in &pdu.auth_events { |
|
|
|
|
|
|
|
let sauthevent = db |
|
|
|
|
|
|
|
.rooms |
|
|
|
|
|
|
|
.get_or_create_shorteventid(auth_event, &db.globals)?; |
|
|
|
|
|
|
|
if !found.contains(&sauthevent) { |
|
|
|
|
|
|
|
found.insert(sauthevent); |
|
|
|
|
|
|
|
get_auth_chain_recursive(&auth_event, found, db)?; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Ok(None) => { |
|
|
|
|
|
|
|
warn!("Could not find pdu mentioned in auth events."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Err(e) => { |
|
|
|
|
|
|
|
warn!("Could not load event in auth chain: {}", e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "conduit_bin", |
|
|
|
feature = "conduit_bin", |
|
|
|
get("/_matrix/federation/v1/event/<_>", data = "<body>") |
|
|
|
get("/_matrix/federation/v1/event/<_>", data = "<body>") |
|
|
|
|