Backfill implements the /backfill federation endpoint. https://matrix.org/docs/spec/server_server/unstable.html#get-matrix-federation-v1-backfill-roomid
( httpReq *http.Request, request *gomatrixserverlib.FederationRequest, rsAPI api.FederationRoomserverAPI, roomID string, cfg *config.FederationAPI, )
| 31 | // Backfill implements the /backfill federation endpoint. |
| 32 | // https://matrix.org/docs/spec/server_server/unstable.html#get-matrix-federation-v1-backfill-roomid |
| 33 | func Backfill( |
| 34 | httpReq *http.Request, |
| 35 | request *gomatrixserverlib.FederationRequest, |
| 36 | rsAPI api.FederationRoomserverAPI, |
| 37 | roomID string, |
| 38 | cfg *config.FederationAPI, |
| 39 | ) util.JSONResponse { |
| 40 | var res api.PerformBackfillResponse |
| 41 | var eIDs []string |
| 42 | var limit string |
| 43 | var exists bool |
| 44 | var err error |
| 45 | |
| 46 | // Check the room ID's format. |
| 47 | if _, _, err = gomatrixserverlib.SplitID('!', roomID); err != nil { |
| 48 | return util.JSONResponse{ |
| 49 | Code: http.StatusBadRequest, |
| 50 | JSON: jsonerror.MissingArgument("Bad room ID: " + err.Error()), |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // If we don't think we belong to this room then don't waste the effort |
| 55 | // responding to expensive requests for it. |
| 56 | if err := ErrorIfLocalServerNotInRoom(httpReq.Context(), rsAPI, roomID); err != nil { |
| 57 | return *err |
| 58 | } |
| 59 | |
| 60 | // Check if all of the required parameters are there. |
| 61 | eIDs, exists = httpReq.URL.Query()["v"] |
| 62 | if !exists { |
| 63 | return util.JSONResponse{ |
| 64 | Code: http.StatusBadRequest, |
| 65 | JSON: jsonerror.MissingArgument("v is missing"), |
| 66 | } |
| 67 | } |
| 68 | limit = httpReq.URL.Query().Get("limit") |
| 69 | if len(limit) == 0 { |
| 70 | return util.JSONResponse{ |
| 71 | Code: http.StatusBadRequest, |
| 72 | JSON: jsonerror.MissingArgument("limit is missing"), |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // Populate the request. |
| 77 | req := api.PerformBackfillRequest{ |
| 78 | RoomID: roomID, |
| 79 | // we don't know who the successors are for these events, which won't |
| 80 | // be a problem because we don't use that information when servicing /backfill requests, |
| 81 | // only when making them. TODO: Think of a better API shape |
| 82 | BackwardsExtremities: map[string][]string{ |
| 83 | "": eIDs, |
| 84 | }, |
| 85 | ServerName: request.Origin(), |
| 86 | } |
| 87 | if req.Limit, err = strconv.Atoi(limit); err != nil { |
| 88 | util.GetLogger(httpReq.Context()).WithError(err).Error("strconv.Atoi failed") |
| 89 | return util.JSONResponse{ |
| 90 | Code: http.StatusBadRequest, |
no test coverage detected