Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Back out implementation of MSC2314
Browse files Browse the repository at this point in the history
MSC2314 has now been closed, so we're backing out its implementation, which
originally happened in #6176.

Unfortunately it's not a direct revert, as that PR mixed in a bunch of
unrelated changes to tests etc.
  • Loading branch information
richvdh committed Apr 14, 2022
1 parent 0922462 commit 0e9d0ba
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 81 deletions.
1 change: 1 addition & 0 deletions changelog.d/12474.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Back out experimental implementation of [MSC2314](https://github.com/matrix-org/matrix-spec-proposals/pull/2314).
26 changes: 9 additions & 17 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ async def _process_edu(edu_dict: JsonDict) -> None:
)

async def on_room_state_request(
self, origin: str, room_id: str, event_id: Optional[str]
self, origin: str, room_id: str, event_id: str
) -> Tuple[int, JsonDict]:
origin_host, _ = parse_server_name(origin)
await self.check_server_matches_acl(origin_host, room_id)
Expand All @@ -530,18 +530,13 @@ async def on_room_state_request(
# - but that's non-trivial to get right, and anyway somewhat defeats
# the point of the linearizer.
async with self._server_linearizer.queue((origin, room_id)):
resp: JsonDict = dict(
await self._state_resp_cache.wrap(
(room_id, event_id),
self._on_context_state_request_compute,
room_id,
event_id,
)
resp = await self._state_resp_cache.wrap(
(room_id, event_id),
self._on_context_state_request_compute,
room_id,
event_id,
)

room_version = await self.store.get_room_version_id(room_id)
resp["room_version"] = room_version

return 200, resp

async def on_state_ids_request(
Expand Down Expand Up @@ -574,14 +569,11 @@ async def _on_state_ids_request_compute(
return {"pdu_ids": state_ids, "auth_chain_ids": list(auth_chain_ids)}

async def _on_context_state_request_compute(
self, room_id: str, event_id: Optional[str]
self, room_id: str, event_id: str
) -> Dict[str, list]:
pdus: Collection[EventBase]
if event_id:
event_ids = await self.handler.get_state_ids_for_pdu(room_id, event_id)
pdus = await self.store.get_events_as_list(event_ids)
else:
pdus = (await self.state.get_current_state(room_id)).values()
event_ids = await self.handler.get_state_ids_for_pdu(room_id, event_id)
pdus = await self.store.get_events_as_list(event_ids)

auth_chain = await self.store.get_auth_chain(
room_id, [pdu.event_id for pdu in pdus]
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/transport/server/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def on_GET(
return await self.handler.on_room_state_request(
origin,
room_id,
parse_string_from_args(query, "event_id", None, required=False),
parse_string_from_args(query, "event_id", None, required=True),
)


Expand Down
4 changes: 0 additions & 4 deletions sytest-blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ Newly created users see their own presence in /initialSync (SYT-34)
# Blacklisted due to https://github.com/matrix-org/synapse/issues/1396
Should reject keys claiming to belong to a different user

# Blacklisted due to https://github.com/matrix-org/matrix-doc/pull/2314 removing
# this requirement from the spec
Inbound federation of state requires event_id as a mandatory paramater

# Blacklisted until MSC2753 is implemented
Local users can peek into world_readable rooms by room ID
We can't peek into rooms with shared history_visibility
Expand Down
59 changes: 0 additions & 59 deletions tests/federation/test_federation_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright 2018 New Vector Ltd
# Copyright 2019 Matrix.org Federation C.I.C
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -103,64 +102,6 @@ def test_wildcard_matching(self):
)


class StateQueryTests(unittest.FederatingHomeserverTestCase):

servlets = [
admin.register_servlets,
room.register_servlets,
login.register_servlets,
]

def test_without_event_id(self):
"""
Querying v1/state/<room_id> without an event ID will return the current
known state.
"""
u1 = self.register_user("u1", "pass")
u1_token = self.login("u1", "pass")

room_1 = self.helper.create_room_as(u1, tok=u1_token)
self.inject_room_member(room_1, "@user:other.example.com", "join")

channel = self.make_signed_federation_request(
"GET", "/_matrix/federation/v1/state/%s" % (room_1,)
)
self.assertEqual(200, channel.code, channel.result)

self.assertEqual(
channel.json_body["room_version"],
self.hs.config.server.default_room_version.identifier,
)

members = set(
map(
lambda x: x["state_key"],
filter(
lambda x: x["type"] == "m.room.member", channel.json_body["pdus"]
),
)
)

self.assertEqual(members, {"@user:other.example.com", u1})
self.assertEqual(len(channel.json_body["pdus"]), 6)

def test_needs_to_be_in_room(self):
"""
Querying v1/state/<room_id> requires the server
be in the room to provide data.
"""
u1 = self.register_user("u1", "pass")
u1_token = self.login("u1", "pass")

room_1 = self.helper.create_room_as(u1, tok=u1_token)

channel = self.make_signed_federation_request(
"GET", "/_matrix/federation/v1/state/%s" % (room_1,)
)
self.assertEqual(403, channel.code, channel.result)
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")


class SendJoinFederationTests(unittest.FederatingHomeserverTestCase):
servlets = [
admin.register_servlets,
Expand Down

0 comments on commit 0e9d0ba

Please sign in to comment.