Documentation
¶
Index ¶
- func AuthDifference(ctx context.Context, conflictedEvents EventMap, fetchEvent EventFetcher) []*pdu.PDU
- func ConflictingPowerEvents(ctx context.Context, roomVersion id.RoomVersion, events []*pdu.PDU) []*pdu.PDU
- func FetchAuthChains(ctx context.Context, eventID id.EventID, fetchEvent EventFetcher) map[id.EventID]StateMap
- func IsPowerEvent(evt *pdu.PDU) bool
- func MainlineDepth(ctx context.Context, eventID id.EventID, depthMap map[id.EventID]uint64, ...) uint64
- func MainlineOrdering(ctx context.Context, roomVersion id.RoomVersion, eventIDs []id.EventID, ...) []id.EventID
- func ReverseTopologicalPowerOrdering(events EventMap) []id.EventID
- func StateKeyOf(evt *pdu.PDU) pdu.StateKey
- type AuthMap
- type ComparableEvent
- type EventFetcher
- type EventMap
- type StateMap
- func CalculateStateMaps(ctx context.Context, eventIDs []id.EventID, getEvent EventFetcher) []StateMap
- func IterativeAuthChecks(ctx context.Context, roomVersion id.RoomVersion, events []id.EventID, ...) StateMap
- func Resolve(ctx context.Context, roomVersion id.RoomVersion, roomID id.RoomID, ...) (StateMap, error)
- func SeparateConflicts(ctx context.Context, roomVersion id.RoomVersion, stateSets []StateMap) (unconflictedStateMap StateMap, ...)
- type TMainlineMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthDifference ¶
func AuthDifference( ctx context.Context, conflictedEvents EventMap, fetchEvent EventFetcher, ) []*pdu.PDU
AuthDifference calculates the difference in auth events between forks.
The auth difference is calculated by first calculating the full auth chain for each state Si, that is the union of the auth chains for each event in Si, and then taking every event that doesn’t appear in every auth chain. If Ci is the full auth chain of Si, then the auth difference is the union of .
func ConflictingPowerEvents ¶
func ConflictingPowerEvents(ctx context.Context, roomVersion id.RoomVersion, events []*pdu.PDU) []*pdu.PDU
ConflictingPowerEvents goes through and filters for conflicting power events, returning a slices of conflicts.
func FetchAuthChains ¶
func FetchAuthChains(ctx context.Context, eventID id.EventID, fetchEvent EventFetcher) map[id.EventID]StateMap
FetchAuthChains walks and compiles an auth chain from the given event ID. The auth chain of E is each of E's auth events and the events that authorised those, recursively.
It works like this: 1. fetch(eID) 2. for each of e's auth events: fetch(aid) 3. result[eID][statekey] = aid 4. for each of a's auth events: 5. repeat step 3-4 until the recursion is exhausted 6. yield.
func IsPowerEvent ¶
IsPowerEvent checks if the event is a power event, which includes power levels, join rules, and member events that indicate a user has been kicked or banned from the room.
func MainlineDepth ¶
func MainlineOrdering ¶
func ReverseTopologicalPowerOrdering ¶
ReverseTopologicalPowerOrdering returns a set of events is the lexicographically smallest topological ordering based on the DAG formed by auth events. The reverse topological power ordering is ordered from earliest event to latest with some special comparisons and modified khan's algorithm.
Types ¶
type AuthMap ¶
AuthMap is a mapping of {event_id: {event_id: PDU}}, representing a map of {root: {auth1: PDU, auth2: PDU}}, etc.
type ComparableEvent ¶
func (ComparableEvent) CompareTo ¶
func (c ComparableEvent) CompareTo(other ComparableEvent) int
CompareTo compares this comparable against another one.
* Positive number: this < other * Negative number: this > other * Zero: this == other (?)
type EventFetcher ¶
EventFetcher is a function abstraction that is used to fetch events, typically from a cache.
type EventMap ¶
EventMap is a mapping of {event_id: PDU}.
func ConflictedStateSubgraph ¶
func ConflictedStateSubgraph( ctx context.Context, conflictedStateSet map[pdu.StateKey]map[id.EventID]*pdu.PDU, fetchEvent EventFetcher, ) EventMap
ConflictedStateSubgraph calculates the conflicted state subgraph from the provided conflicted state set.
Starting from an event in the conflicted state set and following auth_events edges may lead to another event in the conflicted state set. The union of all such paths between any pair of events in the conflicted state set (including endpoints) forms a subgraph of the original auth_event graph, called the conflicted state subgraph.
func ToEventMap ¶
func ToEventMap(roomVersion id.RoomVersion, events []*pdu.PDU) EventMap
ToEventMap flattens the given events into an EventMap (ID -> PDU mapping).
type StateMap ¶
StateMap is used to map a state by {(type, key): PDU}, to build a state object.
func CalculateStateMaps ¶
func CalculateStateMaps(ctx context.Context, eventIDs []id.EventID, getEvent EventFetcher) []StateMap
CalculateStateMaps calculates the state maps for the given event IDs using the provided event map.
func IterativeAuthChecks ¶
func IterativeAuthChecks( ctx context.Context, roomVersion id.RoomVersion, events []id.EventID, base StateMap, fetchEvent EventFetcher, fetchSigningKey pdu.GetKeyFunc, ) StateMap
func Resolve ¶
func Resolve( ctx context.Context, roomVersion id.RoomVersion, roomID id.RoomID, stateSets []StateMap, eventCache *utils.KVCache[id.EventID, *pdu.PDU], fetchSigningKey pdu.GetKeyFunc, fetchEvent func(id.EventID) *pdu.PDU, ) (StateMap, error)
Resolve runs a set of events through the state resolution v2 algorithm to resolve the final state of the room.
ctx: The current context to use (ideally with a zerolog.Logger attached) roomVersion: The id.RoomVersion of the given room roomID: The ID of the room we're resolving stateSets: The possible forks of the room eventMap: Every relevant event (all auth_events in practice) fetchSigningKey: An event to fetch the signing key for server names
Returns: A StateMap for the resolved state, and any error that was fatal.
func SeparateConflicts ¶
func SeparateConflicts(ctx context.Context, roomVersion id.RoomVersion, stateSets []StateMap) ( unconflictedStateMap StateMap, conflictedStateSet map[pdu.StateKey]map[id.EventID]*pdu.PDU, )
SeparateConflicts goes through all provided state events, and separates them into a tuple of (unconflicted, conflicted).
The keys of the state maps Si are 2-tuples of strings of the form K = (event_type, state_key). The values V are state events. The key-value pairs (K, V) across all state maps Si can be divided into two collections. If a given key K is present in every Si with the same value V in each state map, then the pair (K, V) belongs to the unconflicted state map. Otherwise, V belongs to the conflicted state set.
type TMainlineMap ¶
type TMainlineMap map[id.EventID]ComparableEvent