diff options
Diffstat (limited to 'roomserver')
23 files changed, 98 insertions, 101 deletions
diff --git a/roomserver/acls/acls.go b/roomserver/acls/acls.go index 775b6c73..b18daa3d 100644 --- a/roomserver/acls/acls.go +++ b/roomserver/acls/acls.go @@ -61,7 +61,7 @@ func NewServerACLs(db ServerACLDatabase) *ServerACLs { continue } if state != nil { - acls.OnServerACLUpdate(&state.Event) + acls.OnServerACLUpdate(state.Event) } } return acls diff --git a/roomserver/api/input.go b/roomserver/api/input.go index e1a8afa0..8e6e4ac7 100644 --- a/roomserver/api/input.go +++ b/roomserver/api/input.go @@ -53,7 +53,7 @@ type InputRoomEvent struct { // This controls how the event is processed. Kind Kind `json:"kind"` // The event JSON for the event to add. - Event gomatrixserverlib.HeaderedEvent `json:"event"` + Event *gomatrixserverlib.HeaderedEvent `json:"event"` // List of state event IDs that authenticate this event. // These are likely derived from the "auth_events" JSON key of the event. // But can be different because the "auth_events" key can be incomplete or wrong. diff --git a/roomserver/api/output.go b/roomserver/api/output.go index 9cb814a4..fb512a93 100644 --- a/roomserver/api/output.go +++ b/roomserver/api/output.go @@ -94,7 +94,7 @@ const ( // prev_events. type OutputNewRoomEvent struct { // The Event. - Event gomatrixserverlib.HeaderedEvent `json:"event"` + Event *gomatrixserverlib.HeaderedEvent `json:"event"` // Does the event completely rewrite the room state? If so, then AddsStateEventIDs // will contain the entire room state. RewritesState bool `json:"rewrites_state"` @@ -111,7 +111,7 @@ type OutputNewRoomEvent struct { // may decide a bunch of state events on one branch are now valid, so they will be // present in this list. This is useful when trying to maintain the current state of a room // as to do so you need to include both these events and `Event`. - AddStateEvents []gomatrixserverlib.HeaderedEvent `json:"adds_state_events"` + AddStateEvents []*gomatrixserverlib.HeaderedEvent `json:"adds_state_events"` // The state event IDs that were removed from the state of the room by this event. RemovesStateEventIDs []string `json:"removes_state_event_ids"` @@ -168,7 +168,7 @@ type OutputNewRoomEvent struct { // the original event to save space, so you cannot use that slice alone. // Instead, use this function which will add the original event if it is present // in `AddsStateEventIDs`. -func (ore *OutputNewRoomEvent) AddsState() []gomatrixserverlib.HeaderedEvent { +func (ore *OutputNewRoomEvent) AddsState() []*gomatrixserverlib.HeaderedEvent { includeOutputEvent := false for _, id := range ore.AddsStateEventIDs { if id == ore.Event.EventID() { @@ -193,7 +193,7 @@ func (ore *OutputNewRoomEvent) AddsState() []gomatrixserverlib.HeaderedEvent { // should build their current room state up from OutputNewRoomEvents only. type OutputOldRoomEvent struct { // The Event. - Event gomatrixserverlib.HeaderedEvent `json:"event"` + Event *gomatrixserverlib.HeaderedEvent `json:"event"` } // An OutputNewInviteEvent is written whenever an invite becomes active. @@ -203,7 +203,7 @@ type OutputNewInviteEvent struct { // The room version of the invited room. RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"` // The "m.room.member" invite event. - Event gomatrixserverlib.HeaderedEvent `json:"event"` + Event *gomatrixserverlib.HeaderedEvent `json:"event"` } // An OutputRetireInviteEvent is written whenever an existing invite is no longer @@ -230,7 +230,7 @@ type OutputRedactedEvent struct { // The event ID that was redacted RedactedEventID string // The value of `unsigned.redacted_because` - the redaction event itself - RedactedBecause gomatrixserverlib.HeaderedEvent + RedactedBecause *gomatrixserverlib.HeaderedEvent } // An OutputNewPeek is written whenever a user starts peeking into a room diff --git a/roomserver/api/perform.go b/roomserver/api/perform.go index eda53c3e..29dbd25c 100644 --- a/roomserver/api/perform.go +++ b/roomserver/api/perform.go @@ -98,7 +98,7 @@ type PerformLeaveResponse struct { type PerformInviteRequest struct { RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"` - Event gomatrixserverlib.HeaderedEvent `json:"event"` + Event *gomatrixserverlib.HeaderedEvent `json:"event"` InviteRoomState []gomatrixserverlib.InviteV2StrippedState `json:"invite_room_state"` SendAsServer string `json:"send_as_server"` TransactionID *TransactionID `json:"transaction_id"` @@ -147,7 +147,7 @@ func (r *PerformBackfillRequest) PrevEventIDs() []string { // PerformBackfillResponse is a response to PerformBackfill. type PerformBackfillResponse struct { // Missing events, arbritrary order. - Events []gomatrixserverlib.HeaderedEvent `json:"events"` + Events []*gomatrixserverlib.HeaderedEvent `json:"events"` } type PerformPublishRequest struct { diff --git a/roomserver/api/query.go b/roomserver/api/query.go index bdfbf6fb..55922b7f 100644 --- a/roomserver/api/query.go +++ b/roomserver/api/query.go @@ -50,7 +50,7 @@ type QueryLatestEventsAndStateResponse struct { // This list will be in an arbitrary order. // These are used to set the auth_events when sending an event. // These are used to check whether the event is allowed. - StateEvents []gomatrixserverlib.HeaderedEvent `json:"state_events"` + StateEvents []*gomatrixserverlib.HeaderedEvent `json:"state_events"` // The depth of the latest events. // This is one greater than the maximum depth of the latest events. // This is used to set the depth when sending an event. @@ -80,7 +80,7 @@ type QueryStateAfterEventsResponse struct { PrevEventsExist bool `json:"prev_events_exist"` // The state events requested. // This list will be in an arbitrary order. - StateEvents []gomatrixserverlib.HeaderedEvent `json:"state_events"` + StateEvents []*gomatrixserverlib.HeaderedEvent `json:"state_events"` } type QueryMissingAuthPrevEventsRequest struct { @@ -119,7 +119,7 @@ type QueryEventsByIDResponse struct { // fails to read it from the database then it will fail // the entire request. // This list will be in an arbitrary order. - Events []gomatrixserverlib.HeaderedEvent `json:"events"` + Events []*gomatrixserverlib.HeaderedEvent `json:"events"` } // QueryMembershipForUserRequest is a request to QueryMembership @@ -213,7 +213,7 @@ type QueryMissingEventsRequest struct { // QueryMissingEventsResponse is a response to QueryMissingEvents type QueryMissingEventsResponse struct { // Missing events, arbritrary order. - Events []gomatrixserverlib.HeaderedEvent `json:"events"` + Events []*gomatrixserverlib.HeaderedEvent `json:"events"` } // QueryStateAndAuthChainRequest is a request to QueryStateAndAuthChain @@ -242,8 +242,8 @@ type QueryStateAndAuthChainResponse struct { PrevEventsExist bool `json:"prev_events_exist"` // The state and auth chain events that were requested. // The lists will be in an arbitrary order. - StateEvents []gomatrixserverlib.HeaderedEvent `json:"state_events"` - AuthChainEvents []gomatrixserverlib.HeaderedEvent `json:"auth_chain_events"` + StateEvents []*gomatrixserverlib.HeaderedEvent `json:"state_events"` + AuthChainEvents []*gomatrixserverlib.HeaderedEvent `json:"auth_chain_events"` } // QueryRoomVersionCapabilitiesRequest asks for the default room version diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go index 9e821910..7779dbde 100644 --- a/roomserver/api/wrapper.go +++ b/roomserver/api/wrapper.go @@ -25,7 +25,7 @@ import ( // SendEvents to the roomserver The events are written with KindNew. func SendEvents( ctx context.Context, rsAPI RoomserverInternalAPI, - kind Kind, events []gomatrixserverlib.HeaderedEvent, + kind Kind, events []*gomatrixserverlib.HeaderedEvent, sendAsServer gomatrixserverlib.ServerName, txnID *TransactionID, ) error { ires := make([]InputRoomEvent, len(events)) @@ -46,7 +46,7 @@ func SendEvents( // marked as `true` in haveEventIDs func SendEventWithState( ctx context.Context, rsAPI RoomserverInternalAPI, kind Kind, - state *gomatrixserverlib.RespState, event gomatrixserverlib.HeaderedEvent, + state *gomatrixserverlib.RespState, event *gomatrixserverlib.HeaderedEvent, haveEventIDs map[string]bool, ) error { outliers, err := state.Events() @@ -97,7 +97,7 @@ func SendInputRoomEvents( // If we are in the room then the event should be sent using the SendEvents method. func SendInvite( ctx context.Context, - rsAPI RoomserverInternalAPI, inviteEvent gomatrixserverlib.HeaderedEvent, + rsAPI RoomserverInternalAPI, inviteEvent *gomatrixserverlib.HeaderedEvent, inviteRoomState []gomatrixserverlib.InviteV2StrippedState, sendAsServer gomatrixserverlib.ServerName, txnID *TransactionID, ) error { @@ -134,7 +134,7 @@ func GetEvent(ctx context.Context, rsAPI RoomserverInternalAPI, eventID string) if len(res.Events) != 1 { return nil } - return &res.Events[0] + return res.Events[0] } // GetStateEvent returns the current state event in the room or nil. diff --git a/roomserver/auth/auth.go b/roomserver/auth/auth.go index fdcf9f06..aa1d5bc2 100644 --- a/roomserver/auth/auth.go +++ b/roomserver/auth/auth.go @@ -25,7 +25,7 @@ import ( func IsServerAllowed( serverName gomatrixserverlib.ServerName, serverCurrentlyInRoom bool, - authEvents []gomatrixserverlib.Event, + authEvents []*gomatrixserverlib.Event, ) bool { historyVisibility := HistoryVisibilityForRoom(authEvents) @@ -52,7 +52,7 @@ func IsServerAllowed( return false } -func HistoryVisibilityForRoom(authEvents []gomatrixserverlib.Event) string { +func HistoryVisibilityForRoom(authEvents []*gomatrixserverlib.Event) string { // https://matrix.org/docs/spec/client_server/r0.6.0#id87 // By default if no history_visibility is set, or if the value is not understood, the visibility is assumed to be shared. visibility := "shared" @@ -78,7 +78,7 @@ func HistoryVisibilityForRoom(authEvents []gomatrixserverlib.Event) string { return visibility } -func IsAnyUserOnServerWithMembership(serverName gomatrixserverlib.ServerName, authEvents []gomatrixserverlib.Event, wantMembership string) bool { +func IsAnyUserOnServerWithMembership(serverName gomatrixserverlib.ServerName, authEvents []*gomatrixserverlib.Event, wantMembership string) bool { for _, ev := range authEvents { membership, err := ev.Membership() if err != nil || membership != wantMembership { diff --git a/roomserver/internal/alias.go b/roomserver/internal/alias.go index 3e023d2a..97b2ddf5 100644 --- a/roomserver/internal/alias.go +++ b/roomserver/internal/alias.go @@ -229,7 +229,7 @@ func (r *RoomserverInternalAPI) sendUpdatedAliasesEvent( // Add auth events authEvents := gomatrixserverlib.NewAuthEvents(nil) for i := range res.StateEvents { - err = authEvents.AddEvent(&res.StateEvents[i].Event) + err = authEvents.AddEvent(res.StateEvents[i].Event) if err != nil { return err } diff --git a/roomserver/internal/helpers/auth.go b/roomserver/internal/helpers/auth.go index 0fa89d9c..1f4215e7 100644 --- a/roomserver/internal/helpers/auth.go +++ b/roomserver/internal/helpers/auth.go @@ -31,7 +31,7 @@ import ( func CheckForSoftFail( ctx context.Context, db storage.Database, - event gomatrixserverlib.HeaderedEvent, + event *gomatrixserverlib.HeaderedEvent, stateEventIDs []string, ) (bool, error) { rewritesState := len(stateEventIDs) > 1 @@ -72,7 +72,7 @@ func CheckForSoftFail( } // Work out which of the state events we actually need. - stateNeeded := gomatrixserverlib.StateNeededForAuth([]gomatrixserverlib.Event{event.Unwrap()}) + stateNeeded := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{event.Unwrap()}) // Load the actual auth events from the database. authEvents, err := loadAuthEvents(ctx, db, stateNeeded, authStateEntries) @@ -93,7 +93,7 @@ func CheckForSoftFail( func CheckAuthEvents( ctx context.Context, db storage.Database, - event gomatrixserverlib.HeaderedEvent, + event *gomatrixserverlib.HeaderedEvent, authEventIDs []string, ) ([]types.EventNID, error) { // Grab the numeric IDs for the supplied auth state events from the database. @@ -104,7 +104,7 @@ func CheckAuthEvents( authStateEntries = types.DeduplicateStateEntries(authStateEntries) // Work out which of the state events we actually need. - stateNeeded := gomatrixserverlib.StateNeededForAuth([]gomatrixserverlib.Event{event.Unwrap()}) + stateNeeded := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{event.Unwrap()}) // Load the actual auth events from the database. authEvents, err := loadAuthEvents(ctx, db, stateNeeded, authStateEntries) @@ -168,7 +168,7 @@ func (ae *authEvents) lookupEventWithEmptyStateKey(typeNID types.EventTypeNID) * if !ok { return nil } - return &event.Event + return event.Event } func (ae *authEvents) lookupEvent(typeNID types.EventTypeNID, stateKey string) *gomatrixserverlib.Event { @@ -187,7 +187,7 @@ func (ae *authEvents) lookupEvent(typeNID types.EventTypeNID, stateKey string) * if !ok { return nil } - return &event.Event + return event.Event } // loadAuthEvents loads the events needed for authentication from the supplied room state. diff --git a/roomserver/internal/helpers/helpers.go b/roomserver/internal/helpers/helpers.go index 4c072e44..e4de878e 100644 --- a/roomserver/internal/helpers/helpers.go +++ b/roomserver/internal/helpers/helpers.go @@ -67,7 +67,7 @@ func IsServerCurrentlyInRoom(ctx context.Context, db storage.Database, serverNam if err != nil { return false, err } - gmslEvents := make([]gomatrixserverlib.Event, len(events)) + gmslEvents := make([]*gomatrixserverlib.Event, len(events)) for i := range events { gmslEvents[i] = events[i].Event } @@ -190,13 +190,13 @@ func StateBeforeEvent(ctx context.Context, db storage.Database, info types.RoomI func LoadEvents( ctx context.Context, db storage.Database, eventNIDs []types.EventNID, -) ([]gomatrixserverlib.Event, error) { +) ([]*gomatrixserverlib.Event, error) { stateEvents, err := db.Events(ctx, eventNIDs) if err != nil { return nil, err } - result := make([]gomatrixserverlib.Event, len(stateEvents)) + result := make([]*gomatrixserverlib.Event, len(stateEvents)) for i := range stateEvents { result[i] = stateEvents[i].Event } @@ -205,7 +205,7 @@ func LoadEvents( func LoadStateEvents( ctx context.Context, db storage.Database, stateEntries []types.StateEntry, -) ([]gomatrixserverlib.Event, error) { +) ([]*gomatrixserverlib.Event, error) { eventNIDs := make([]types.EventNID, len(stateEntries)) for i := range stateEntries { eventNIDs[i] = stateEntries[i].EventNID diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go index 99c15f77..d7257539 100644 --- a/roomserver/internal/input/input.go +++ b/roomserver/internal/input/input.go @@ -92,7 +92,7 @@ func (r *Inputer) WriteOutputEvents(roomID string, updates []api.OutputEvent) er }) if updates[i].NewRoomEvent.Event.Type() == "m.room.server_acl" && updates[i].NewRoomEvent.Event.StateKeyEquals("") { ev := updates[i].NewRoomEvent.Event.Unwrap() - defer r.ACLs.OnServerACLUpdate(&ev) + defer r.ACLs.OnServerACLUpdate(ev) } } logger.Infof("Producing to topic '%s'", r.OutputRoomEventTopic) diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go index c055289c..d62621c2 100644 --- a/roomserver/internal/input/input_events.go +++ b/roomserver/internal/input/input_events.go @@ -111,11 +111,11 @@ func (r *Inputer) processRoomEvent( // if storing this event results in it being redacted then do so. if !isRejected && redactedEventID == event.EventID() { - r, rerr := eventutil.RedactEvent(redactionEvent, &event) + r, rerr := eventutil.RedactEvent(redactionEvent, event) if rerr != nil { return "", fmt.Errorf("eventutil.RedactEvent: %w", rerr) } - event = *r + event = r } // For outliers we can stop after we've stored the event itself as it @@ -215,7 +215,7 @@ func (r *Inputer) calculateAndSetState( input *api.InputRoomEvent, roomInfo types.RoomInfo, stateAtEvent *types.StateAtEvent, - event gomatrixserverlib.Event, + event *gomatrixserverlib.Event, isRejected bool, ) error { var err error diff --git a/roomserver/internal/input/input_latest_events.go b/roomserver/internal/input/input_latest_events.go index 2bf6b9f8..3608ef4b 100644 --- a/roomserver/internal/input/input_latest_events.go +++ b/roomserver/internal/input/input_latest_events.go @@ -50,7 +50,7 @@ func (r *Inputer) updateLatestEvents( ctx context.Context, roomInfo *types.RoomInfo, stateAtEvent types.StateAtEvent, - event gomatrixserverlib.Event, + event *gomatrixserverlib.Event, sendAsServer string, transactionID *api.TransactionID, rewritesState bool, @@ -92,7 +92,7 @@ type latestEventsUpdater struct { updater *shared.LatestEventsUpdater roomInfo *types.RoomInfo stateAtEvent types.StateAtEvent - event gomatrixserverlib.Event + event *gomatrixserverlib.Event transactionID *api.TransactionID rewritesState bool // Which server to send this event as. @@ -140,7 +140,7 @@ func (u *latestEventsUpdater) doUpdateLatestEvents() error { // Work out what the latest events are. This will include the new // event if it is not already referenced. extremitiesChanged, err := u.calculateLatest( - oldLatest, &u.event, + oldLatest, u.event, types.StateAtEventAndReference{ EventReference: u.event.EventReference(), StateAtEvent: u.stateAtEvent, @@ -373,7 +373,7 @@ func (u *latestEventsUpdater) makeOutputNewRoomEvent() (*api.OutputEvent, error) // extraEventsForIDs returns the full events for the event IDs given, but does not include the current event being // updated. -func (u *latestEventsUpdater) extraEventsForIDs(roomVersion gomatrixserverlib.RoomVersion, eventIDs []string) ([]gomatrixserverlib.HeaderedEvent, error) { +func (u *latestEventsUpdater) extraEventsForIDs(roomVersion gomatrixserverlib.RoomVersion, eventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error) { var extraEventIDs []string for _, e := range eventIDs { if e == u.event.EventID() { @@ -388,7 +388,7 @@ func (u *latestEventsUpdater) extraEventsForIDs(roomVersion gomatrixserverlib.Ro if err != nil { return nil, err } - var h []gomatrixserverlib.HeaderedEvent + var h []*gomatrixserverlib.HeaderedEvent for _, e := range extraEvents { h = append(h, e.Headered(roomVersion)) } diff --git a/roomserver/internal/input/input_membership.go b/roomserver/internal/input/input_membership.go index 8befcd64..692d8147 100644 --- a/roomserver/internal/input/input_membership.go +++ b/roomserver/internal/input/input_membership.go @@ -62,13 +62,13 @@ func (r *Inputer) updateMemberships( if change.removedEventNID != 0 { ev, _ := helpers.EventMap(events).Lookup(change.removedEventNID) if ev != nil { - re = &ev.Event + re = ev.Event } } if change.addedEventNID != 0 { ev, _ := helpers.EventMap(events).Lookup(change.addedEventNID) if ev != nil { - ae = &ev.Event + ae = ev.Event } } if updates, err = r.updateMembership(updater, targetUserNID, re, ae, updates); err != nil { diff --git a/roomserver/internal/perform/perform_backfill.go b/roomserver/internal/perform/perform_backfill.go index 6c05b3b8..eb47ac21 100644 --- a/roomserver/internal/perform/perform_backfill.go +++ b/roomserver/internal/perform/perform_backfill.go @@ -83,7 +83,7 @@ func (r *Backfiller) PerformBackfill( } // Retrieve events from the list that was filled previously. - var loadedEvents []gomatrixserverlib.Event + var loadedEvents []*gomatrixserverlib.Event loadedEvents, err = helpers.LoadEvents(ctx, r.DB, resultNIDs) if err != nil { return err @@ -211,10 +211,10 @@ func (r *Backfiller) fetchAndStoreMissingEvents(ctx context.Context, roomVer gom } } - var newEvents []gomatrixserverlib.HeaderedEvent + var newEvents []*gomatrixserverlib.HeaderedEvent for _, ev := range missingMap { if ev != nil { - newEvents = append(newEvents, *ev) + newEvents = append(newEvents, ev) } } util.GetLogger(ctx).Infof("Persisting %d new events", len(newEvents)) @@ -232,7 +232,7 @@ type backfillRequester struct { // per-request state servers []gomatrixserverlib.ServerName eventIDToBeforeStateIDs map[string][]string - eventIDMap map[string]gomatrixserverlib.Event + eventIDMap map[string]*gomatrixserverlib.Event } func newBackfillRequester( @@ -248,13 +248,13 @@ func newBackfillRequester( fsAPI: fsAPI, thisServer: thisServer, eventIDToBeforeStateIDs: make(map[string][]string), - eventIDMap: make(map[string]gomatrixserverlib.Event), + eventIDMap: make(map[string]*gomatrixserverlib.Event), bwExtrems: bwExtrems, preferServer: preferServer, } } -func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent gomatrixserverlib.HeaderedEvent) ([]string, error) { +func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent *gomatrixserverlib.HeaderedEvent) ([]string, error) { b.eventIDMap[targetEvent.EventID()] = targetEvent.Unwrap() if ids, ok := b.eventIDToBeforeStateIDs[targetEvent.EventID()]; ok { return ids, nil @@ -305,7 +305,7 @@ FederationHit: return nil, lastErr } -func (b *backfillRequester) calculateNewStateIDs(targetEvent, prevEvent gomatrixserverlib.Event, prevEventStateIDs []string) []string { +func (b *backfillRequester) calculateNewStateIDs(targetEvent, prevEvent *gomatrixserverlib.Event, prevEventStateIDs []string) []string { newStateIDs := prevEventStateIDs[:] if prevEvent.StateKey() == nil { // state is the same as the previous event @@ -343,7 +343,7 @@ func (b *backfillRequester) calculateNewStateIDs(targetEvent, prevEvent gomatrix } func (b *backfillRequester) StateBeforeEvent(ctx context.Context, roomVer gomatrixserverlib.RoomVersion, - event gomatrixserverlib.HeaderedEvent, eventIDs []string) (map[string]*gomatrixserverlib.Event, error) { + event *gomatrixserverlib.HeaderedEvent, eventIDs []string) (map[string]*gomatrixserverlib.Event, error) { // try to fetch the events from the database first events, err := b.ProvideEvents(roomVer, eventIDs) @@ -355,7 +355,7 @@ func (b *backfillRequester) StateBeforeEvent(ctx context.Context, roomVer gomatr if len(events) == len(eventIDs) { result := make(map[string]*gomatrixserverlib.Event) for i := range events { - result[events[i].EventID()] = &events[i] + result[events[i].EventID()] = events[i] b.eventIDMap[events[i].EventID()] = events[i] } return result, nil @@ -372,7 +372,7 @@ func (b *backfillRequester) StateBeforeEvent(ctx context.Context, roomVer gomatr return nil, err } for eventID, ev := range result { - b.eventIDMap[eventID] = *ev + b.eventIDMap[eventID] = ev } return result, nil } @@ -476,7 +476,7 @@ func (b *backfillRequester) Backfill(ctx context.Context, server gomatrixserverl return tx, err } -func (b *backfillRequester) ProvideEvents(roomVer gomatrixserverlib.RoomVersion, eventIDs []string) ([]gomatrixserverlib.Event, error) { +func (b *backfillRequester) ProvideEvents(roomVer gomatrixserverlib.RoomVersion, eventIDs []string) ([]*gomatrixserverlib.Event, error) { ctx := context.Background() nidMap, err := b.db.EventNIDs(ctx, eventIDs) if err != nil { @@ -494,7 +494,7 @@ func (b *backfillRequester) ProvideEvents(roomVer gomatrixserverlib.RoomVersion, logrus.WithError(err).WithField("event_nids", eventNIDs).Error("Failed to load events") return nil, err } - events := make([]gomatrixserverlib.Event, len(eventsWithNids)) + events := make([]*gomatrixserverlib.Event, len(eventsWithNids)) for i := range eventsWithNids { events[i] = eventsWithNids[i].Event } @@ -522,7 +522,7 @@ func joinEventsFromHistoryVisibility( if err != nil { return nil, err } - events := make([]gomatrixserverlib.Event, len(stateEvents)) + events := make([]*gomatrixserverlib.Event, len(stateEvents)) for i := range stateEvents { events[i] = stateEvents[i].Event } @@ -545,7 +545,7 @@ func joinEventsFromHistoryVisibility( return db.Events(ctx, joinEventNIDs) } -func persistEvents(ctx context.Context, db storage.Database, events []gomatrixserverlib.HeaderedEvent) (types.RoomNID, map[string]types.Event) { +func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixserverlib.HeaderedEvent) (types.RoomNID, map[string]types.Event) { var roomNID types.RoomNID backfilledEventMap := make(map[string]types.Event) for j, ev := range events { @@ -573,7 +573,7 @@ func persistEvents(ctx context.Context, db storage.Database, events []gomatrixse // redacted, which we don't care about since we aren't returning it in this backfill. if redactedEventID == ev.EventID() { eventToRedact := ev.Unwrap() - redactedEvent, err := eventutil.RedactEvent(redactionEvent, &eventToRedact) + redactedEvent, err := eventutil.RedactEvent(redactionEvent, eventToRedact) if err != nil { logrus.WithError(err).WithField("event_id", ev.EventID()).Error("Failed to redact event") continue diff --git a/roomserver/internal/perform/perform_invite.go b/roomserver/internal/perform/perform_invite.go index 0630ed45..0fb6ddd4 100644 --- a/roomserver/internal/perform/perform_invite.go +++ b/roomserver/internal/perform/perform_invite.go @@ -198,7 +198,7 @@ func (r *Inviter) PerformInvite( } unwrapped := event.Unwrap() - outputUpdates, err := helpers.UpdateToInviteMembership(updater, &unwrapped, nil, req.Event.RoomVersion) + outputUpdates, err := helpers.UpdateToInviteMembership(updater, unwrapped, nil, req.Event.RoomVersion) if err != nil { return nil, fmt.Errorf("updateToInviteMembership: %w", err) } @@ -248,11 +248,11 @@ func buildInviteStrippedState( return nil, err } inviteState := []gomatrixserverlib.InviteV2StrippedState{ - gomatrixserverlib.NewInviteV2StrippedState(&input.Event.Event), + gomatrixserverlib.NewInviteV2StrippedState(input.Event.Event), } stateEvents = append(stateEvents, types.Event{Event: input.Event.Unwrap()}) for _, event := range stateEvents { - inviteState = append(inviteState, gomatrixserverlib.NewInviteV2StrippedState(&event.Event)) + inviteState = append(inviteState, gomatrixserverlib.NewInviteV2StrippedState(event.Event)) } return inviteState, nil } diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index 64ece4eb..c9940c3c 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -416,7 +416,7 @@ func (r *Queryer) QueryMissingEvents( return err } - response.Events = make([]gomatrixserverlib.HeaderedEvent, 0, len(loadedEvents)-len(eventsToFilter)) + response.Events = make([]*gomatrixserverlib.HeaderedEvent, 0, len(loadedEvents)-len(eventsToFilter)) for _, event := range loadedEvents { if !eventsToFilter[event.EventID()] { roomVersion, verr := r.roomVersion(event.RoomID()) @@ -485,7 +485,7 @@ func (r *Queryer) QueryStateAndAuthChain( return err } -func (r *Queryer) loadStateAtEventIDs(ctx context.Context, roomInfo types.RoomInfo, eventIDs []string) ([]gomatrixserverlib.Event, error) { +func (r *Queryer) loadStateAtEventIDs(ctx context.Context, roomInfo types.RoomInfo, eventIDs []string) ([]*gomatrixserverlib.Event, error) { roomState := state.NewStateResolution(r.DB, roomInfo) prevStates, err := r.DB.StateAtEventIDs(ctx, eventIDs) if err != nil { @@ -516,13 +516,13 @@ type eventsFromIDs func(context.Context, []string) ([]types.Event, error) // given events. Will *not* error if we don't have all auth events. func getAuthChain( ctx context.Context, fn eventsFromIDs, authEventIDs []string, -) ([]gomatrixserverlib.Event, error) { +) ([]*gomatrixserverlib.Event, error) { // List of event IDs to fetch. On each pass, these events will be requested // from the database and the `eventsToFetch` will be updated with any new // events that we have learned about and need to find. When `eventsToFetch` // is eventually empty, we should have reached the end of the chain. eventsToFetch := authEventIDs - authEventsMap := make(map[string]gomatrixserverlib.Event) + authEventsMap := make(map[string]*gomatrixserverlib.Event) for len(eventsToFetch) > 0 { // Try to retrieve the events from the database. @@ -553,7 +553,7 @@ func getAuthChain( // We've now retrieved all of the events we can. Flatten them down into an // array and return them. - var authEvents []gomatrixserverlib.Event + var authEvents []*gomatrixserverlib.Event for _, event := range authEventsMap { authEvents = append(authEvents, event) } diff --git a/roomserver/internal/query/query_test.go b/roomserver/internal/query/query_test.go index b4cb99b8..4e761d8e 100644 --- a/roomserver/internal/query/query_test.go +++ b/roomserver/internal/query/query_test.go @@ -26,12 +26,12 @@ import ( // used to implement RoomserverInternalAPIEventDB to test getAuthChain type getEventDB struct { - eventMap map[string]gomatrixserverlib.Event + eventMap map[string]*gomatrixserverlib.Event } func createEventDB() *getEventDB { return &getEventDB{ - eventMap: make(map[string]gomatrixserverlib.Event), + eventMap: make(map[string]*gomatrixserverlib.Event), } } diff --git a/roomserver/roomserver_test.go b/roomserver/roomserver_test.go index 41cbd263..7638f3f3 100644 --- a/roomserver/roomserver_test.go +++ b/roomserver/roomserver_test.go @@ -94,7 +94,7 @@ type fledglingEvent struct { RoomID string } -func mustCreateEvents(t *testing.T, roomVer gomatrixserverlib.RoomVersion, events []fledglingEvent) (result []gomatrixserverlib.HeaderedEvent) { +func mustCreateEvents(t *testing.T, roomVer gomatrixserverlib.RoomVersion, events []fledglingEvent) (result []*gomatrixserverlib.HeaderedEvent) { t.Helper() depth := int64(1) seed := make([]byte, ed25519.SeedSize) // zero seed @@ -143,16 +143,15 @@ func mustCreateEvents(t *testing.T, roomVer gomatrixserverlib.RoomVersion, event return } -func mustLoadRawEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events []json.RawMessage) []gomatrixserverlib.HeaderedEvent { +func mustLoadRawEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events []json.RawMessage) []*gomatrixserverlib.HeaderedEvent { t.Helper() - hs := make([]gomatrixserverlib.HeaderedEvent, len(events)) + hs := make([]*gomatrixserverlib.HeaderedEvent, len(events)) for i := range events { e, err := gomatrixserverlib.NewEventFromTrustedJSON(events[i], false, ver) if err != nil { t.Fatalf("cannot load test data: " + err.Error()) } - h := e.Headered(ver) - hs[i] = h + hs[i] = e.Headered(ver) } return hs } @@ -187,7 +186,7 @@ func mustCreateRoomserverAPI(t *testing.T) (api.RoomserverInternalAPI, *dummyPro ), dp } -func mustSendEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events []json.RawMessage) (api.RoomserverInternalAPI, *dummyProducer, []gomatrixserverlib.HeaderedEvent) { +func mustSendEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events []json.RawMessage) (api.RoomserverInternalAPI, *dummyProducer, []*gomatrixserverlib.HeaderedEvent) { t.Helper() rsAPI, dp := mustCreateRoomserverAPI(t) hevents := mustLoadRawEvents(t, ver, events) diff --git a/roomserver/state/state.go b/roomserver/state/state.go index d23f14c8..87715af4 100644 --- a/roomserver/state/state.go +++ b/roomserver/state/state.go @@ -522,7 +522,7 @@ func init() { // Returns a numeric ID for the snapshot of the state before the event. func (v StateResolution) CalculateAndStoreStateBeforeEvent( ctx context.Context, - event gomatrixserverlib.Event, + event *gomatrixserverlib.Event, isRejected bool, ) (types.StateSnapshotNID, error) { // Load the state at the prev events. @@ -689,17 +689,17 @@ func (v StateResolution) calculateStateAfterManyEvents( // TODO: Some of this can possibly be deduplicated func ResolveConflictsAdhoc( version gomatrixserverlib.RoomVersion, - events []gomatrixserverlib.Event, - authEvents []gomatrixserverlib.Event, -) ([]gomatrixserverlib.Event, error) { + events []*gomatrixserverlib.Event, + authEvents []*gomatrixserverlib.Event, +) ([]*gomatrixserverlib.Event, error) { type stateKeyTuple struct { Type string StateKey string } // Prepare our data structures. - eventMap := make(map[stateKeyTuple][]gomatrixserverlib.Event) - var conflicted, notConflicted, resolved []gomatrixserverlib.Event + eventMap := make(map[stateKeyTuple][]*gomatrixserverlib.Event) + var conflicted, notConflicted, resolved []*gomatrixserverlib.Event // Run through all of the events that we were given and sort them // into a map, sorted by (event_type, state_key) tuple. This means @@ -868,15 +868,15 @@ func (v StateResolution) resolveConflictsV2( // For each conflicted event, we will add a new set of auth events. Auth // events may be duplicated across these sets but that's OK. - authSets := make(map[string][]gomatrixserverlib.Event) - var authEvents []gomatrixserverlib.Event - var authDifference []gomatrixserverlib.Event + authSets := make(map[string][]*gomatrixserverlib.Event) + var authEvents []*gomatrixserverlib.Event + var authDifference []*gomatrixserverlib.Event // For each conflicted event, let's try and get the needed auth events. for _, conflictedEvent := range conflictedEvents { // Work out which auth events we need to load. key := conflictedEvent.EventID() - needed := gomatrixserverlib.StateNeededForAuth([]gomatrixserverlib.Event{conflictedEvent}) + needed := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{conflictedEvent}) // Find the numeric IDs for the necessary state keys. var neededStateKeys []string @@ -909,7 +909,7 @@ func (v StateResolution) resolveConflictsV2( // This function helps us to work out whether an event exists in one of the // auth sets. - isInAuthList := func(k string, event gomatrixserverlib.Event) bool { + isInAuthList := func(k string, event *gomatrixserverlib.Event) bool { for _, e := range authSets[k] { if e.EventID() == event.EventID() { return true @@ -919,7 +919,7 @@ func (v StateResolution) resolveConflictsV2( } // This function works out if an event exists in all of the auth sets. - isInAllAuthLists := func(event gomatrixserverlib.Event) bool { + isInAllAuthLists := func(event *gomatrixserverlib.Event) bool { found := true for k := range authSets { found = found && isInAuthList(k, event) @@ -1006,7 +1006,7 @@ func (v StateResolution) stateKeyTuplesNeeded(stateKeyNIDMap map[string]types.Ev // Returns an error if there was a problem talking to the database. func (v StateResolution) loadStateEvents( ctx context.Context, entries []types.StateEntry, -) ([]gomatrixserverlib.Event, map[string]types.StateEntry, error) { +) ([]*gomatrixserverlib.Event, map[string]types.StateEntry, error) { eventNIDs := make([]types.EventNID, len(entries)) for i := range entries { eventNIDs[i] = entries[i].EventNID @@ -1016,7 +1016,7 @@ func (v StateResolution) loadStateEvents( return nil, nil, err } eventIDMap := map[string]types.StateEntry{} - result := make([]gomatrixserverlib.Event, len(entries)) + result := make([]*gomatrixserverlib.Event, len(entries)) for i := range entries { event, ok := eventMap(events).lookup(entries[i].EventNID) if !ok { diff --git a/roomserver/storage/interface.go b/roomserver/storage/interface.go index c6f5c808..d2b0e75c 100644 --- a/roomserver/storage/interface.go +++ b/roomserver/storage/interface.go @@ -69,7 +69,7 @@ type Database interface { SnapshotNIDFromEventID(ctx context.Context, eventID string) (types.StateSnapshotNID, error) // Stores a matrix room event in the database. Returns the room NID, the state snapshot and the redacted event ID if any, or an error. StoreEvent( - ctx context.Context, event gomatrixserverlib.Event, txnAndSessionID *api.TransactionID, authEventNIDs []types.EventNID, + ctx context.Context, event *gomatrixserverlib.Event, txnAndSessionID *api.TransactionID, authEventNIDs []types.EventNID, isRejected bool, ) (types.RoomNID, types.StateAtEvent, *gomatrixserverlib.Event, string, error) // Look up the state entries for a list of string event IDs diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go index 5361bd21..2548980d 100644 --- a/roomserver/storage/shared/storage.go +++ b/roomserver/storage/shared/storage.go @@ -388,7 +388,7 @@ func (d *Database) GetLatestEventsForUpdate( // nolint:gocyclo func (d *Database) StoreEvent( - ctx context.Context, event gomatrixserverlib.Event, + ctx context.Context, event *gomatrixserverlib.Event, txnAndSessionID *api.TransactionID, authEventNIDs []types.EventNID, isRejected bool, ) (types.RoomNID, types.StateAtEvent, *gomatrixserverlib.Event, string, error) { var ( @@ -611,7 +611,7 @@ func (d *Database) assignStateKeyNID( return eventStateKeyNID, err } -func extractRoomVersionFromCreateEvent(event gomatrixserverlib.Event) ( +func extractRoomVersionFromCreateEvent(event *gomatrixserverlib.Event) ( gomatrixserverlib.RoomVersion, error, ) { var err error @@ -651,7 +651,7 @@ func extractRoomVersionFromCreateEvent(event gomatrixserverlib.Event) ( // Returns the redaction event and the event ID of the redacted event if this call resulted in a redaction. // nolint:gocyclo func (d *Database) handleRedactions( - ctx context.Context, txn *sql.Tx, eventNID types.EventNID, event gomatrixserverlib.Event, + ctx context.Context, txn *sql.Tx, eventNID types.EventNID, event *gomatrixserverlib.Event, ) (*gomatrixserverlib.Event, string, error) { var err error isRedactionEvent := event.Type() == gomatrixserverlib.MRoomRedaction && event.StateKey() == nil @@ -703,12 +703,12 @@ func (d *Database) handleRedactions( err = fmt.Errorf("d.RedactionsTable.MarkRedactionValidated: %w", err) } - return &redactionEvent.Event, redactedEvent.EventID(), err + return redactionEvent.Event, redactedEvent.EventID(), err } // loadRedactionPair returns both the redaction event and the redacted event, else nil. func (d *Database) loadRedactionPair( - ctx context.Context, txn *sql.Tx, eventNID types.EventNID, event gomatrixserverlib.Event, + ctx context.Context, txn *sql.Tx, eventNID types.EventNID, event *gomatrixserverlib.Event, ) (*types.Event, *types.Event, bool, error) { var redactionEvent, redactedEvent *types.Event var info *tables.RedactionInfo @@ -814,8 +814,7 @@ func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey s if err != nil { return nil, err } - h := ev.Headered(roomInfo.RoomVersion) - return &h, nil + return ev.Headered(roomInfo.RoomVersion), nil } } @@ -934,12 +933,11 @@ func (d *Database) GetBulkStateContent(ctx context.Context, roomIDs []string, tu if err != nil { return nil, fmt.Errorf("GetBulkStateContent: failed to load event JSON for event NID %v : %w", events[i].EventNID, err) } - hev := ev.Headered(roomVer) result[i] = tables.StrippedEvent{ EventType: ev.Type(), RoomID: ev.RoomID(), StateKey: *ev.StateKey(), - ContentValue: tables.ExtractContentValue(&hev), + ContentValue: tables.ExtractContentValue(ev.Headered(roomVer)), } } diff --git a/roomserver/types/types.go b/roomserver/types/types.go index c0fcef65..e866f6cb 100644 --- a/roomserver/types/types.go +++ b/roomserver/types/types.go @@ -126,7 +126,7 @@ type StateAtEventAndReference struct { // It is when performing bulk event lookup in the database. type Event struct { EventNID EventNID - gomatrixserverlib.Event + *gomatrixserverlib.Event } const ( |