Keep track of State at event for state resolution

feat: first steps towards joining rooms over federation
Add state-res as a dependency of conduit
Add reverse_topological_power_sort before append_pdu
Implement statehashstatid_pduid tree for keeping track of state
Clean up implementation of state_hash as key for tracking state
This commit is contained in:
Devin Ragotzy 2020-08-06 08:29:59 -04:00
parent 8e55623bde
commit c4f5a0a631
24 changed files with 818 additions and 356 deletions

View file

@ -177,6 +177,35 @@ impl PduEvent {
}
}
impl PduEvent {
pub fn convert_for_state_res(&self) -> Result<state_res::StateEvent> {
serde_json::from_value(json!({
"event_id": self.event_id,
"room_id": self.room_id,
"sender": self.sender,
"origin": self.origin,
"origin_server_ts": self.origin_server_ts,
"type": self.kind,
"content": self.content,
"state_key": self.state_key,
"prev_events": self.prev_events
.iter()
.map(|id| (id, EventHash { sha256: "hello".into() }))
.collect::<Vec<_>>(),
"depth": self.depth,
"auth_events": self.auth_events
.iter()
.map(|id| (id, EventHash { sha256: "hello".into() }))
.collect::<Vec<_>>(),
"redacts": self.redacts,
"unsigned": self.unsigned,
"hashes": self.hashes,
"signatures": self.signatures,
}))
.map_err(|_| Error::bad_database("Failed to convert PDU to ruma::Pdu type."))
}
}
/// Build the start of a PDU in order to add it to the `Database`.
#[derive(Debug)]
pub struct PduBuilder {