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

Also use stable name in SendJoinResponse struct #14841

Merged
merged 6 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14841.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Faster joins: use stable identifiers from [MSC3706](https://github.com/matrix-org/matrix-spec-proposals/pull/3706).
6 changes: 3 additions & 3 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,17 +1142,17 @@ async def _execute(pdu: EventBase) -> None:
% (auth_chain_create_events,)
)

if response.partial_state and not response.servers_in_room:
if response.members_omitted and not response.servers_in_room:
raise InvalidResponseError(
"partial_state was set, but no servers were listed in the room"
"members_omitted was set, but no servers were listed in the room"
)

return SendJoinResult(
event=event,
state=signed_state,
auth_chain=signed_auth,
origin=destination,
partial_state=response.partial_state,
partial_state=response.members_omitted,
servers_in_room=response.servers_in_room or [],
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ def _get_event_ids_for_partial_state_join(
prev_state_ids: StateMap[str],
summary: Dict[str, MemberSummary],
) -> Collection[str]:
"""Calculate state to be retuned in a partial_state send_join
"""Calculate state to be returned in a partial_state send_join

Args:
join_event: the join event being send_joined
Expand Down
16 changes: 9 additions & 7 deletions synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ class SendJoinResponse:
event: Optional[EventBase] = None

# The room state is incomplete
partial_state: bool = False
members_omitted: bool = False

# List of servers in the room
servers_in_room: Optional[List[str]] = None
Expand Down Expand Up @@ -835,16 +835,18 @@ def _event_list_parser(


@ijson.coroutine
def _partial_state_parser(response: SendJoinResponse) -> Generator[None, Any, None]:
def _members_omitted_parser(response: SendJoinResponse) -> Generator[None, Any, None]:
"""Helper function for use with `ijson.items_coro`

Parses the partial_state field in send_join responses
Parses the members_omitted field in send_join responses
"""
while True:
val = yield
if not isinstance(val, bool):
raise TypeError("partial_state must be a boolean")
response.partial_state = val
raise TypeError(
"members_omitted (formerly org.matrix.msc370c.partial_state) must be a boolean"
)
response.members_omitted = val


@ijson.coroutine
Expand Down Expand Up @@ -905,15 +907,15 @@ def __init__(self, room_version: RoomVersion, v1_api: bool):
if not v1_api:
self._coros.append(
ijson.items_coro(
_partial_state_parser(self._response),
_members_omitted_parser(self._response),
"org.matrix.msc3706.partial_state",
use_float="True",
)
)
# The stable field name comes last, so it "wins" if the fields disagree
self._coros.append(
ijson.items_coro(
_partial_state_parser(self._response),
_members_omitted_parser(self._response),
"members_omitted",
use_float="True",
)
Expand Down
6 changes: 3 additions & 3 deletions tests/federation/transport/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def test_two_writes(self) -> None:
self.assertEqual(len(parsed_response.state), 1, parsed_response)
self.assertEqual(parsed_response.event_dict, {}, parsed_response)
self.assertIsNone(parsed_response.event, parsed_response)
self.assertFalse(parsed_response.partial_state, parsed_response)
self.assertFalse(parsed_response.members_omitted, parsed_response)
self.assertEqual(parsed_response.servers_in_room, None, parsed_response)

def test_partial_state(self) -> None:
"""Check that the partial_state flag is correctly parsed"""
"""Check that the members_omitted flag is correctly parsed"""

def parse(response: JsonDict) -> bool:
parser = SendJoinParser(RoomVersions.V1, False)
Expand All @@ -83,7 +83,7 @@ def parse(response: JsonDict) -> bool:

# Retrieve and check the parsed SendJoinResponse
parsed_response = parser.finish()
return parsed_response.partial_state
return parsed_response.members_omitted

self.assertTrue(parse({"members_omitted": True}))
self.assertTrue(parse({"org.matrix.msc3706.partial_state": True}))
Expand Down