diff options
author | kegsay <kegan@matrix.org> | 2023-04-27 12:54:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 12:54:20 +0100 |
commit | b189edf4f43ff34b69d6c60aeb0efb60dd549c86 (patch) | |
tree | 4c08aeda694f3e1cf17c66cf0e4b2b306af6a8df /federationapi/routing | |
parent | 2475cf4b61747e76a524af6f71a4eb7e112812af (diff) |
Remove gmsl.HeaderedEvent (#3068)
Replaced with types.HeaderedEvent _for now_. In reality we want to move
them all to gmsl.Event and only use HeaderedEvent when we _need_ to
bundle the version/event ID with the event (seriailsation boundaries,
and even then only when we don't have the room version).
Requires https://github.com/matrix-org/gomatrixserverlib/pull/373
Diffstat (limited to 'federationapi/routing')
-rw-r--r-- | federationapi/routing/backfill.go | 3 | ||||
-rw-r--r-- | federationapi/routing/eventauth.go | 4 | ||||
-rw-r--r-- | federationapi/routing/invite.go | 5 | ||||
-rw-r--r-- | federationapi/routing/join.go | 9 | ||||
-rw-r--r-- | federationapi/routing/leave.go | 7 | ||||
-rw-r--r-- | federationapi/routing/missingevents.go | 8 | ||||
-rw-r--r-- | federationapi/routing/peek.go | 7 | ||||
-rw-r--r-- | federationapi/routing/state.go | 10 | ||||
-rw-r--r-- | federationapi/routing/threepid.go | 13 |
9 files changed, 36 insertions, 30 deletions
diff --git a/federationapi/routing/backfill.go b/federationapi/routing/backfill.go index e99d54a6..40cb88fb 100644 --- a/federationapi/routing/backfill.go +++ b/federationapi/routing/backfill.go @@ -23,6 +23,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/roomserver/api" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/fclient" @@ -104,7 +105,7 @@ func Backfill( // Filter any event that's not from the requested room out. evs := make([]*gomatrixserverlib.Event, 0) - var ev *gomatrixserverlib.HeaderedEvent + var ev *types.HeaderedEvent for _, ev = range res.Events { if ev.RoomID() == roomID { evs = append(evs, ev.Event) diff --git a/federationapi/routing/eventauth.go b/federationapi/routing/eventauth.go index 89db3e98..da1e77d8 100644 --- a/federationapi/routing/eventauth.go +++ b/federationapi/routing/eventauth.go @@ -18,7 +18,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/roomserver/api" - "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib/fclient" "github.com/matrix-org/util" ) @@ -72,7 +72,7 @@ func GetEventAuth( return util.JSONResponse{ Code: http.StatusOK, JSON: fclient.RespEventAuth{ - AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents), + AuthEvents: types.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents), }, } } diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index 88071892..a4ebeaed 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -22,6 +22,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/roomserver/api" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/fclient" @@ -196,11 +197,11 @@ func processInvite( ) // Add the invite event to the roomserver. - inviteEvent := signedEvent.Headered(roomVer) + inviteEvent := &types.HeaderedEvent{Event: &signedEvent} request := &api.PerformInviteRequest{ Event: inviteEvent, InviteRoomState: strippedState, - RoomVersion: inviteEvent.RoomVersion, + RoomVersion: inviteEvent.Version(), SendAsServer: string(api.DoNotSendToOtherServers), TransactionID: nil, } diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go index 84d4c093..eee0f3d9 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -30,6 +30,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/internal/eventutil" "github.com/matrix-org/dendrite/roomserver/api" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/setup/config" ) @@ -413,7 +414,7 @@ func SendJoin( InputRoomEvents: []api.InputRoomEvent{ { Kind: api.KindNew, - Event: signed.Headered(stateAndAuthChainResponse.RoomVersion), + Event: &types.HeaderedEvent{Event: &signed}, SendAsServer: string(cfg.Matrix.ServerName), TransactionID: nil, }, @@ -443,8 +444,8 @@ func SendJoin( return util.JSONResponse{ Code: http.StatusOK, JSON: fclient.RespSendJoin{ - StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents), - AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents), + StateEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents), + AuthEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents), Origin: cfg.Matrix.ServerName, Event: signed.JSON(), }, @@ -519,7 +520,7 @@ func checkRestrictedJoin( } } -type eventsByDepth []*gomatrixserverlib.HeaderedEvent +type eventsByDepth []*types.HeaderedEvent func (e eventsByDepth) Len() int { return len(e) diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index 1dd43168..ae7617fa 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -20,6 +20,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/internal/eventutil" "github.com/matrix-org/dendrite/roomserver/api" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/fclient" @@ -101,7 +102,7 @@ func MakeLeave( return util.JSONResponse{ Code: http.StatusOK, JSON: map[string]interface{}{ - "room_version": event.RoomVersion, + "room_version": event.Version(), "event": state, }, } @@ -124,7 +125,7 @@ func MakeLeave( return util.JSONResponse{ Code: http.StatusOK, JSON: map[string]interface{}{ - "room_version": event.RoomVersion, + "room_version": event.Version(), "event": builder, }, } @@ -312,7 +313,7 @@ func SendLeave( InputRoomEvents: []api.InputRoomEvent{ { Kind: api.KindNew, - Event: event.Headered(roomVersion), + Event: &types.HeaderedEvent{Event: event}, SendAsServer: string(cfg.Matrix.ServerName), TransactionID: nil, }, diff --git a/federationapi/routing/missingevents.go b/federationapi/routing/missingevents.go index 28dc31da..23a99bf0 100644 --- a/federationapi/routing/missingevents.go +++ b/federationapi/routing/missingevents.go @@ -18,7 +18,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/roomserver/api" - "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib/fclient" "github.com/matrix-org/util" ) @@ -69,7 +69,7 @@ func GetMissingEvents( eventsResponse.Events = filterEvents(eventsResponse.Events, roomID) resp := fclient.RespMissingEvents{ - Events: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(eventsResponse.Events), + Events: types.NewEventJSONsFromHeaderedEvents(eventsResponse.Events), } return util.JSONResponse{ @@ -80,8 +80,8 @@ func GetMissingEvents( // filterEvents returns only those events with matching roomID func filterEvents( - events []*gomatrixserverlib.HeaderedEvent, roomID string, -) []*gomatrixserverlib.HeaderedEvent { + events []*types.HeaderedEvent, roomID string, +) []*types.HeaderedEvent { ref := events[:0] for _, ev := range events { if ev.RoomID() == roomID { diff --git a/federationapi/routing/peek.go b/federationapi/routing/peek.go index 05c61a64..45dc7f8c 100644 --- a/federationapi/routing/peek.go +++ b/federationapi/routing/peek.go @@ -19,6 +19,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/roomserver/api" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/fclient" @@ -87,10 +88,10 @@ func Peek( } respPeek := fclient.RespPeek{ - StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.StateEvents), - AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents), + StateEvents: types.NewEventJSONsFromHeaderedEvents(response.StateEvents), + AuthEvents: types.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents), RoomVersion: response.RoomVersion, - LatestEvent: response.LatestEvent.Unwrap(), + LatestEvent: response.LatestEvent.Event, RenewalInterval: renewalInterval, } diff --git a/federationapi/routing/state.go b/federationapi/routing/state.go index 52a8c2b1..aa2cb283 100644 --- a/federationapi/routing/state.go +++ b/federationapi/routing/state.go @@ -19,7 +19,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/roomserver/api" - "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib/fclient" "github.com/matrix-org/util" ) @@ -42,8 +42,8 @@ func GetState( } return util.JSONResponse{Code: http.StatusOK, JSON: &fclient.RespState{ - AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(authChain), - StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateEvents), + AuthEvents: types.NewEventJSONsFromHeaderedEvents(authChain), + StateEvents: types.NewEventJSONsFromHeaderedEvents(stateEvents), }} } @@ -101,7 +101,7 @@ func getState( rsAPI api.FederationRoomserverAPI, roomID string, eventID string, -) (stateEvents, authEvents []*gomatrixserverlib.HeaderedEvent, errRes *util.JSONResponse) { +) (stateEvents, authEvents []*types.HeaderedEvent, errRes *util.JSONResponse) { // If we don't think we belong to this room then don't waste the effort // responding to expensive requests for it. if err := ErrorIfLocalServerNotInRoom(ctx, rsAPI, roomID); err != nil { @@ -157,7 +157,7 @@ func getState( return response.StateEvents, response.AuthChainEvents, nil } -func getIDsFromEvent(events []*gomatrixserverlib.HeaderedEvent) []string { +func getIDsFromEvent(events []*types.HeaderedEvent) []string { IDs := make([]string, len(events)) for i := range events { IDs[i] = events[i].EventID() diff --git a/federationapi/routing/threepid.go b/federationapi/routing/threepid.go index e075bab0..1b854501 100644 --- a/federationapi/routing/threepid.go +++ b/federationapi/routing/threepid.go @@ -24,6 +24,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/roomserver/api" + "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/setup/config" userapi "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/gomatrixserverlib/fclient" @@ -67,9 +68,9 @@ func CreateInvitesFrom3PIDInvites( return *reqErr } - evs := []*gomatrixserverlib.HeaderedEvent{} + evs := []*types.HeaderedEvent{} for _, inv := range body.Invites { - roomVersion, err := rsAPI.QueryRoomVersionForRoom(req.Context(), inv.RoomID) + _, err := rsAPI.QueryRoomVersionForRoom(req.Context(), inv.RoomID) if err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, @@ -85,7 +86,7 @@ func CreateInvitesFrom3PIDInvites( return jsonerror.InternalServerError() } if event != nil { - evs = append(evs, event.Headered(roomVersion)) + evs = append(evs, &types.HeaderedEvent{Event: event}) } } @@ -183,7 +184,7 @@ func ExchangeThirdPartyInvite( // Ask the requesting server to sign the newly created event so we know it // acknowledged it - inviteReq, err := fclient.NewInviteV2Request(event.Headered(roomVersion), nil) + inviteReq, err := fclient.NewInviteV2Request(event, nil) if err != nil { util.GetLogger(httpReq.Context()).WithError(err).Error("failed to make invite v2 request") return jsonerror.InternalServerError() @@ -208,8 +209,8 @@ func ExchangeThirdPartyInvite( if err = api.SendEvents( httpReq.Context(), rsAPI, api.KindNew, - []*gomatrixserverlib.HeaderedEvent{ - inviteEvent.Headered(roomVersion), + []*types.HeaderedEvent{ + {Event: inviteEvent}, }, request.Destination(), request.Origin(), |