aboutsummaryrefslogtreecommitdiff
path: root/federationapi
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2021-07-09 16:36:45 +0100
committerGitHub <noreply@github.com>2021-07-09 16:36:45 +0100
commitc8408a6387f6d155fe4e0547cbfdde7123832c84 (patch)
treedafecdf16214eefcb995e75734c60421eb6304e8 /federationapi
parent3e50bac9441ae43387fee510d5838039bc07e0bb (diff)
Add more optimised code path for checking if we're in a room (#1909)
* Add more optimised code path for checking if we're in a room * Fix database queries * Fix federation API test * Fix logging * Review comments * Make separate API call for room membership
Diffstat (limited to 'federationapi')
-rw-r--r--federationapi/routing/send.go27
-rw-r--r--federationapi/routing/send_test.go4
2 files changed, 20 insertions, 11 deletions
diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go
index 1c9e72bf..5f214e0f 100644
--- a/federationapi/routing/send.go
+++ b/federationapi/routing/send.go
@@ -573,6 +573,23 @@ func (t *txnReq) processEvent(ctx context.Context, e *gomatrixserverlib.Event) e
logger := util.GetLogger(ctx).WithField("event_id", e.EventID()).WithField("room_id", e.RoomID())
t.work = "" // reset from previous event
+ // Ask the roomserver if we know about the room and/or if we're joined
+ // to it. If we aren't then we won't bother processing the event.
+ joinedReq := api.QueryServerJoinedToRoomRequest{
+ RoomID: e.RoomID(),
+ }
+ var joinedRes api.QueryServerJoinedToRoomResponse
+ if err := t.rsAPI.QueryServerJoinedToRoom(ctx, &joinedReq, &joinedRes); err != nil {
+ return fmt.Errorf("t.rsAPI.QueryServerJoinedToRoom: %w", err)
+ }
+
+ if !joinedRes.RoomExists || !joinedRes.IsInRoom {
+ // We don't believe we're a member of this room, therefore there's
+ // no point in wasting work trying to figure out what to do with
+ // missing auth or prev events. Drop the event.
+ return roomNotFoundError{e.RoomID()}
+ }
+
// Work out if the roomserver knows everything it needs to know to auth
// the event. This includes the prev_events and auth_events.
// NOTE! This is going to include prev_events that have an empty state
@@ -589,16 +606,6 @@ func (t *txnReq) processEvent(ctx context.Context, e *gomatrixserverlib.Event) e
return fmt.Errorf("t.rsAPI.QueryMissingAuthPrevEvents: %w", err)
}
- if !stateResp.RoomExists {
- // TODO: When synapse receives a message for a room it is not in it
- // asks the remote server for the state of the room so that it can
- // check if the remote server knows of a join "m.room.member" event
- // that this server is unaware of.
- // However generally speaking we should reject events for rooms we
- // aren't a member of.
- return roomNotFoundError{e.RoomID()}
- }
-
// Prepare a map of all the events we already had before this point, so
// that we don't send them to the roomserver again.
for _, eventID := range append(e.AuthEventIDs(), e.PrevEventIDs()...) {
diff --git a/federationapi/routing/send_test.go b/federationapi/routing/send_test.go
index 98ff1a0a..0da06aa9 100644
--- a/federationapi/routing/send_test.go
+++ b/federationapi/routing/send_test.go
@@ -190,7 +190,9 @@ func (t *testRoomserverAPI) QueryServerJoinedToRoom(
request *api.QueryServerJoinedToRoomRequest,
response *api.QueryServerJoinedToRoomResponse,
) error {
- return fmt.Errorf("not implemented")
+ response.RoomExists = true
+ response.IsInRoom = true
+ return nil
}
// Query whether a server is allowed to see an event