diff --git a/federationapi/routing/send_test.go b/federationapi/routing/send_test.go index 9b9db873b..8bdf54c4a 100644 --- a/federationapi/routing/send_test.go +++ b/federationapi/routing/send_test.go @@ -9,7 +9,6 @@ import ( "time" eduAPI "github.com/matrix-org/dendrite/eduserver/api" - fsAPI "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" @@ -85,6 +84,7 @@ func (o *testEDUProducer) InputReceiptEvent( } type testRoomserverAPI struct { + api.RoomserverInternalAPITrace inputRoomEvents []api.InputRoomEvent queryMissingAuthPrevEvents func(*api.QueryMissingAuthPrevEventsRequest) api.QueryMissingAuthPrevEventsResponse queryStateAfterEvents func(*api.QueryStateAfterEventsRequest) api.QueryStateAfterEventsResponse @@ -92,12 +92,6 @@ type testRoomserverAPI struct { queryLatestEventsAndState func(*api.QueryLatestEventsAndStateRequest) api.QueryLatestEventsAndStateResponse } -func (t *testRoomserverAPI) PerformForget(ctx context.Context, req *api.PerformForgetRequest, resp *api.PerformForgetResponse) error { - return nil -} - -func (t *testRoomserverAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI) {} - func (t *testRoomserverAPI) InputRoomEvents( ctx context.Context, request *api.InputRoomEventsRequest, @@ -109,43 +103,6 @@ func (t *testRoomserverAPI) InputRoomEvents( } } -func (t *testRoomserverAPI) PerformInvite( - ctx context.Context, - req *api.PerformInviteRequest, - res *api.PerformInviteResponse, -) error { - return nil -} - -func (t *testRoomserverAPI) PerformJoin( - ctx context.Context, - req *api.PerformJoinRequest, - res *api.PerformJoinResponse, -) { -} - -func (t *testRoomserverAPI) PerformPeek( - ctx context.Context, - req *api.PerformPeekRequest, - res *api.PerformPeekResponse, -) { -} - -func (t *testRoomserverAPI) PerformPublish( - ctx context.Context, - req *api.PerformPublishRequest, - res *api.PerformPublishResponse, -) { -} - -func (t *testRoomserverAPI) PerformLeave( - ctx context.Context, - req *api.PerformLeaveRequest, - res *api.PerformLeaveResponse, -) error { - return nil -} - // Query the latest events and state for a room from the room server. func (t *testRoomserverAPI) QueryLatestEventsAndState( ctx context.Context, diff --git a/roomserver/api/api.go b/roomserver/api/api.go index 2683918a8..fff61ed6f 100644 --- a/roomserver/api/api.go +++ b/roomserver/api/api.go @@ -126,6 +126,14 @@ type RoomserverInternalAPI interface { response *QueryStateAndAuthChainResponse, ) error + // QueryAuthChain returns the entire auth chain for the event IDs given. + // Omits without error any missing auth events. + QueryAuthChain( + ctx context.Context, + request *QueryAuthChainRequest, + response *QueryAuthChainResponse, + ) error + // QueryCurrentState retrieves the requested state events. If state events are not found, they will be missing from // the response. QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error diff --git a/roomserver/api/api_trace.go b/roomserver/api/api_trace.go index e625fb04a..13c1fe1c0 100644 --- a/roomserver/api/api_trace.go +++ b/roomserver/api/api_trace.go @@ -315,6 +315,16 @@ func (t *RoomserverInternalAPITrace) QueryServerBannedFromRoom(ctx context.Conte return err } +func (t *RoomserverInternalAPITrace) QueryAuthChain( + ctx context.Context, + request *QueryAuthChainRequest, + response *QueryAuthChainResponse, +) error { + err := t.Impl.QueryAuthChain(ctx, request, response) + util.GetLogger(ctx).WithError(err).Infof("QueryAuthChain req=%+v res=%+v", js(request), js(response)) + return err +} + func js(thing interface{}) string { b, err := json.Marshal(thing) if err != nil { diff --git a/roomserver/api/query.go b/roomserver/api/query.go index 55922b7fe..43e562a98 100644 --- a/roomserver/api/query.go +++ b/roomserver/api/query.go @@ -275,6 +275,14 @@ type QueryPublishedRoomsResponse struct { RoomIDs []string } +type QueryAuthChainRequest struct { + EventIDs []string +} + +type QueryAuthChainResponse struct { + AuthChain []*gomatrixserverlib.HeaderedEvent +} + type QuerySharedUsersRequest struct { UserID string ExcludeRoomIDs []string diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index c9940c3c2..7346c7a77 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -716,3 +716,16 @@ func (r *Queryer) QueryServerBannedFromRoom(ctx context.Context, req *api.QueryS res.Banned = r.ServerACLs.IsServerBannedFromRoom(req.ServerName, req.RoomID) return nil } + +func (r *Queryer) QueryAuthChain(ctx context.Context, req *api.QueryAuthChainRequest, res *api.QueryAuthChainResponse) error { + chain, err := getAuthChain(ctx, r.DB.EventsFromIDs, req.EventIDs) + if err != nil { + return err + } + hchain := make([]*gomatrixserverlib.HeaderedEvent, len(chain)) + for i := range chain { + hchain[i] = chain[i].Headered(chain[i].Version()) + } + res.AuthChain = hchain + return nil +} diff --git a/roomserver/inthttp/client.go b/roomserver/inthttp/client.go index f5b66ca6a..6e3b2c661 100644 --- a/roomserver/inthttp/client.go +++ b/roomserver/inthttp/client.go @@ -53,6 +53,7 @@ const ( RoomserverQuerySharedUsersPath = "/roomserver/querySharedUsers" RoomserverQueryKnownUsersPath = "/roomserver/queryKnownUsers" RoomserverQueryServerBannedFromRoomPath = "/roomserver/queryServerBannedFromRoom" + RoomserverQueryAuthChainPath = "/roomserver/queryAuthChain" ) type httpRoomserverInternalAPI struct { @@ -484,6 +485,16 @@ func (h *httpRoomserverInternalAPI) QueryKnownUsers( return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) } +func (h *httpRoomserverInternalAPI) QueryAuthChain( + ctx context.Context, req *api.QueryAuthChainRequest, res *api.QueryAuthChainResponse, +) error { + span, ctx := opentracing.StartSpanFromContext(ctx, "QueryAuthChain") + defer span.Finish() + + apiURL := h.roomserverURL + RoomserverQueryAuthChainPath + return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) +} + func (h *httpRoomserverInternalAPI) QueryServerBannedFromRoom( ctx context.Context, req *api.QueryServerBannedFromRoomRequest, res *api.QueryServerBannedFromRoomResponse, ) error { diff --git a/roomserver/inthttp/server.go b/roomserver/inthttp/server.go index 2bc8f82df..9d0793cb1 100644 --- a/roomserver/inthttp/server.go +++ b/roomserver/inthttp/server.go @@ -441,4 +441,17 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) + internalAPIMux.Handle(RoomserverQueryAuthChainPath, + httputil.MakeInternalAPI("queryAuthChain", func(req *http.Request) util.JSONResponse { + request := api.QueryAuthChainRequest{} + response := api.QueryAuthChainResponse{} + if err := json.NewDecoder(req.Body).Decode(&request); err != nil { + return util.MessageResponse(http.StatusBadRequest, err.Error()) + } + if err := r.QueryAuthChain(req.Context(), &request, &response); err != nil { + return util.ErrorResponse(err) + } + return util.JSONResponse{Code: http.StatusOK, JSON: &response} + }), + ) }