diff --git a/federationapi/inthttp/client.go b/federationapi/inthttp/client.go index 0d0a02883..a65df906f 100644 --- a/federationapi/inthttp/client.go +++ b/federationapi/inthttp/client.go @@ -360,14 +360,16 @@ type lookupMissingEvents struct { RoomID string Missing gomatrixserverlib.MissingEvents RoomVersion gomatrixserverlib.RoomVersion - Res *gomatrixserverlib.RespMissingEvents - Err *api.FederationClientError + Res struct { + Events []gomatrixserverlib.RawJSON `json:"events"` + } + Err *api.FederationClientError } func (h *httpFederationInternalAPI) LookupMissingEvents( ctx context.Context, s gomatrixserverlib.ServerName, roomID string, missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion, -) (gomatrixserverlib.RespMissingEvents, error) { +) (res gomatrixserverlib.RespMissingEvents, err error) { span, ctx := opentracing.StartSpanFromContext(ctx, "LookupMissingEvents") defer span.Finish() @@ -377,16 +379,23 @@ func (h *httpFederationInternalAPI) LookupMissingEvents( Missing: missing, RoomVersion: roomVersion, } - var response lookupMissingEvents apiURL := h.federationAPIURL + FederationAPILookupMissingEventsPath - err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response) + err = httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &request) if err != nil { - return gomatrixserverlib.RespMissingEvents{}, err + return res, err } - if response.Err != nil { - return gomatrixserverlib.RespMissingEvents{}, response.Err + if request.Err != nil { + return res, request.Err } - return *response.Res, nil + res.Events = make([]*gomatrixserverlib.Event, 0, len(request.Res.Events)) + for _, js := range request.Res.Events { + ev, err := gomatrixserverlib.NewEventFromUntrustedJSON(js, roomVersion) + if err != nil { + return res, err + } + res.Events = append(res.Events, ev) + } + return res, nil } type getEvent struct { diff --git a/federationapi/inthttp/server.go b/federationapi/inthttp/server.go index d5ebb508c..8d193d9c9 100644 --- a/federationapi/inthttp/server.go +++ b/federationapi/inthttp/server.go @@ -259,7 +259,13 @@ func AddRoutes(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router) { } } } - request.Res = &res + for _, event := range res.Events { + js, err := json.Marshal(event) + if err != nil { + return util.MessageResponse(http.StatusInternalServerError, err.Error()) + } + request.Res.Events = append(request.Res.Events, js) + } return util.JSONResponse{Code: http.StatusOK, JSON: request} }), ) diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go index 59ce99691..b9f6cb2dc 100644 --- a/roomserver/internal/input/input_events.go +++ b/roomserver/internal/input/input_events.go @@ -101,6 +101,10 @@ func (r *Inputer) processRoomEvent( "type": event.Type(), }) + if _, err := headered.RoomVersion.EventIDFormat(); err != nil { + panic("UNKNOWN ROOM VERSION") + } + // if we have already got this event then do not process it again, if the input kind is an outlier. // Outliers contain no extra information which may warrant a re-processing. if input.Kind == api.KindOutlier {