Fetch server keys concurrently
This speeds up handling of /_matrix/federation/v1/send/:transaction_id when more than one event contains unknown keys. In particular, when receiving multiple PDUs with dead servers in their auth chain, timeouts of each server accumulate and can make handling of incoming requests take several minutes, to the point the client closes the connection (eg. matrix.org has a 2 minute timeout), causing new events to be dropped eventually.
This commit is contained in:
parent
87d1040386
commit
d092820699
6 changed files with 156 additions and 53 deletions
|
@ -1033,6 +1033,11 @@ async fn join_room_by_id_helper(
|
|||
|
||||
drop(state_lock);
|
||||
let pub_key_map = RwLock::new(BTreeMap::new());
|
||||
services()
|
||||
.rooms
|
||||
.event_handler
|
||||
.fetch_required_signing_keys([&signed_value], &pub_key_map)
|
||||
.await?;
|
||||
services()
|
||||
.rooms
|
||||
.event_handler
|
||||
|
@ -1259,6 +1264,12 @@ pub(crate) async fn invite_helper<'a>(
|
|||
)
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Origin field is invalid."))?;
|
||||
|
||||
services()
|
||||
.rooms
|
||||
.event_handler
|
||||
.fetch_required_signing_keys([&value], &pub_key_map)
|
||||
.await?;
|
||||
|
||||
let pdu_id: Vec<u8> = services()
|
||||
.rooms
|
||||
.event_handler
|
||||
|
|
|
@ -220,7 +220,7 @@ where
|
|||
let keys_result = services()
|
||||
.rooms
|
||||
.event_handler
|
||||
.fetch_signing_keys(&x_matrix.origin, vec![x_matrix.key.to_owned()])
|
||||
.fetch_signing_keys_for_server(&x_matrix.origin, vec![x_matrix.key.to_owned()])
|
||||
.await;
|
||||
|
||||
let keys = match keys_result {
|
||||
|
|
|
@ -764,6 +764,7 @@ pub async fn send_transaction_message_route(
|
|||
// events that it references.
|
||||
// let mut auth_cache = EventMap::new();
|
||||
|
||||
let mut parsed_pdus = vec![];
|
||||
for pdu in &body.pdus {
|
||||
let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| {
|
||||
warn!("Error parsing incoming event {:?}: {:?}", pdu, e);
|
||||
|
@ -791,8 +792,28 @@ pub async fn send_transaction_message_route(
|
|||
continue;
|
||||
}
|
||||
};
|
||||
parsed_pdus.push((event_id, value, room_id));
|
||||
// We do not add the event_id field to the pdu here because of signature and hashes checks
|
||||
}
|
||||
|
||||
// We go through all the signatures we see on the PDUs and fetch the corresponding
|
||||
// signing keys
|
||||
services()
|
||||
.rooms
|
||||
.event_handler
|
||||
.fetch_required_signing_keys(
|
||||
parsed_pdus.iter().map(|(_event_id, event, _room_id)| event),
|
||||
&pub_key_map,
|
||||
)
|
||||
.await
|
||||
.unwrap_or_else(|e| {
|
||||
warn!(
|
||||
"Could not fetch all signatures for PDUs from {}: {:?}",
|
||||
sender_servername, e
|
||||
)
|
||||
});
|
||||
|
||||
for (event_id, value, room_id) in parsed_pdus {
|
||||
let mutex = Arc::clone(
|
||||
services()
|
||||
.globals
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue