14 releases (breaking)

0.12.0 Oct 27, 2024
0.11.0 May 9, 2024
0.10.0 Oct 5, 2023
0.9.1 Feb 15, 2023
0.2.0 Jun 21, 2021

#1174 in Web programming

Download history 26/week @ 2024-08-19 70/week @ 2024-08-26 26/week @ 2024-09-02 39/week @ 2024-09-09 44/week @ 2024-09-16 90/week @ 2024-09-23 82/week @ 2024-09-30 62/week @ 2024-10-14 134/week @ 2024-10-21 167/week @ 2024-10-28 120/week @ 2024-11-04 62/week @ 2024-11-11 85/week @ 2024-11-18 86/week @ 2024-11-25 155/week @ 2024-12-02

391 downloads per month
Used in 12 crates (via ruma)

MIT license

1.5MB
28K SLoC

Matrix State Resolution in Rust!

/// Abstraction of a PDU so users can have their own PDU types.
pub trait Event {
    /// The `EventId` of this event.
    fn event_id(&self) -> &EventId;
    /// The `RoomId` of this event.
    fn room_id(&self) -> &RoomId;
    /// The `UserId` of this event.
    fn sender(&self) -> &UserId;
    // and so on...
}

/// A mapping of event type and state_key to some value `T`, usually an `EventId`.
pub type StateMap<T> = BTreeMap<(StateEventType, Option<String>), T>;

/// A mapping of `EventId` to `T`, usually a `OriginalStateEvent`.
pub type EventMap<T> = BTreeMap<OwnedEventId, T>;

struct StateResolution {
    // For now the StateResolution struct is empty. If "caching" `event_map`
    // between `resolve` calls ends up being more efficient (probably not, as this would eat memory)
    // it may have an `event_map` field. The `event_map` is all the events
    // `StateResolution` has to know about to resolve state.
}

impl StateResolution {
    /// The point of this all, resolve the possibly conflicting sets of events.
    pub fn resolve<E: Event>(
        room_id: &RoomId,
        room_version: &RoomVersionId,
        state_sets: &[StateMap<OwnedEventId>],
        auth_events: Vec<Vec<OwnedEventId>>,
        event_map: &mut EventMap<Arc<E>>,
    ) -> Result<StateMap<OwnedEventId>> {;
}

The StateStore trait is an abstraction around what ever database your server (or maybe even client) uses to store Persistent Data Units.

We use rumas types when deserializing any PDU or it's contents which helps avoid a lot of type checking logic synapse must do while authenticating event chains.

Dependencies

~10–21MB
~295K SLoC