aboutsummaryrefslogtreecommitdiff
path: root/federationapi/routing/routing.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-04-28 11:45:56 +0100
committerGitHub <noreply@github.com>2022-04-28 11:45:56 +0100
commit6deb10f3f61e4da0360a8910f6b5375a2d31f182 (patch)
treecbcacfc15979704377c2ecf4ddb2071c5a2970f6 /federationapi/routing/routing.go
parent2ff75b7c806829b211be0c310497728055e898cc (diff)
Don't answer expensive federation requests for rooms we no longer belong to (#2398)
This includes `/state`, `/state_ids`, `/get_missing_events` and `/backfill`. This should fix #2396.
Diffstat (limited to 'federationapi/routing/routing.go')
-rw-r--r--federationapi/routing/routing.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go
index a085ed78..6d24c8b4 100644
--- a/federationapi/routing/routing.go
+++ b/federationapi/routing/routing.go
@@ -15,6 +15,8 @@
package routing
import (
+ "context"
+ "fmt"
"net/http"
"github.com/gorilla/mux"
@@ -24,6 +26,7 @@ import (
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/httputil"
keyserverAPI "github.com/matrix-org/dendrite/keyserver/api"
+ "github.com/matrix-org/dendrite/roomserver/api"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
@@ -491,3 +494,27 @@ func Setup(
}),
).Methods(http.MethodGet)
}
+
+func ErrorIfLocalServerNotInRoom(
+ ctx context.Context,
+ rsAPI api.RoomserverInternalAPI,
+ roomID string,
+) *util.JSONResponse {
+ // Check if we think we're in this room. If we aren't then
+ // we won't waste CPU cycles serving this request.
+ joinedReq := &api.QueryServerJoinedToRoomRequest{
+ RoomID: roomID,
+ }
+ joinedRes := &api.QueryServerJoinedToRoomResponse{}
+ if err := rsAPI.QueryServerJoinedToRoom(ctx, joinedReq, joinedRes); err != nil {
+ res := util.ErrorResponse(err)
+ return &res
+ }
+ if !joinedRes.IsInRoom {
+ return &util.JSONResponse{
+ Code: http.StatusNotFound,
+ JSON: jsonerror.NotFound(fmt.Sprintf("This server is not joined to room %s", roomID)),
+ }
+ }
+ return nil
+}