add warning if calculated event id != requested event id

next
Timo Kösters 2021-08-28 19:35:15 +02:00
parent afca61fe7c
commit 1601027605
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
3 changed files with 76 additions and 12 deletions

View File

@ -93,9 +93,8 @@ impl Engine {
}
pub fn flush_wal(self: &Arc<Self>) -> Result<()> {
// We use autocheckpoints
//self.write_lock()
//.pragma_update(Some(Main), "wal_checkpoint", &"TRUNCATE")?;
self.write_lock()
.pragma_update(Some(Main), "wal_checkpoint", &"TRUNCATE")?;
Ok(())
}
}

View File

@ -1544,6 +1544,66 @@ impl Rooms {
}
}
}
"parse_pdu" => {
if body.len() > 2
&& body[0].trim() == "```"
&& body.last().unwrap().trim() == "```"
{
let string = body[1..body.len() - 1].join("\n");
match serde_json::from_str(&string) {
Ok(value) => {
let event_id = EventId::try_from(&*format!(
"${}",
// Anything higher than version3 behaves the same
ruma::signatures::reference_hash(
&value,
&RoomVersionId::Version6
)
.expect("ruma can calculate reference hashes")
))
.expect(
"ruma's reference hashes are valid event ids",
);
match serde_json::from_value::<PduEvent>(
serde_json::to_value(value)
.expect("value is json"),
) {
Ok(pdu) => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
format!("EventId: {:?}\n{:#?}", event_id, pdu),
),
));
}
Err(e) => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
format!("EventId: {:?}\nCould not parse event: {}", event_id, e),
),
));
}
}
}
Err(e) => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
format!(
"Invalid json in command body: {}",
e
),
),
));
}
}
} else {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
"Expected code block in command body.",
),
));
}
}
"get_pdu" => {
if args.len() == 1 {
if let Ok(event_id) = EventId::try_from(args[0]) {

View File

@ -1184,13 +1184,13 @@ fn handle_outlier_pdu<'a>(
// Build map of auth events
let mut auth_events = HashMap::new();
for id in &incoming_pdu.auth_events {
let auth_event = db
.rooms
.get_pdu(id)
.map_err(|e| e.to_string())?
.ok_or_else(|| {
"Auth event not found, event failed recursive auth checks.".to_string()
})?;
let auth_event = match db.rooms.get_pdu(id).map_err(|e| e.to_string())? {
Some(e) => e,
None => {
warn!("Could not find auth event {}", id);
continue;
}
};
match auth_events.entry((
auth_event.kind.clone(),
@ -1767,7 +1767,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
{
Ok(res) => {
warn!("Got {} over federation", id);
let (event_id, value) =
let (calculated_event_id, value) =
match crate::pdu::gen_event_id_canonical_json(&res.pdu) {
Ok(t) => t,
Err(_) => {
@ -1776,11 +1776,16 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
}
};
if calculated_event_id != **id {
warn!("Server didn't return event id we requested: requested: {}, we got {}. Event: {:?}",
id, calculated_event_id, &res.pdu);
}
// This will also fetch the auth chain
match handle_outlier_pdu(
origin,
create_event,
&event_id,
&id,
&room_id,
value.clone(),
db,