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

pass room versions around #6823

Merged
merged 3 commits into from
Feb 6, 2020
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/6823.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactoring work in preparation for changing the event redaction algorithm.
24 changes: 11 additions & 13 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async def get_pdu(
self,
destinations: Iterable[str],
event_id: str,
room_version: str,
room_version: RoomVersion,
outlier: bool = False,
timeout: Optional[int] = None,
) -> Optional[EventBase]:
Expand Down Expand Up @@ -262,7 +262,7 @@ async def get_pdu(

pdu_attempts = self.pdu_destination_tried.setdefault(event_id, {})

format_ver = room_version_to_event_format(room_version)
format_ver = room_version.event_format

signed_pdu = None
for destination in destinations:
Expand Down Expand Up @@ -292,7 +292,9 @@ async def get_pdu(
pdu = pdu_list[0]

# Check signatures are correct.
signed_pdu = await self._check_sigs_and_hash(room_version, pdu)
signed_pdu = await self._check_sigs_and_hash(
room_version.identifier, pdu
)

break

Expand Down Expand Up @@ -663,28 +665,25 @@ async def _do_send_join(self, destination: str, pdu: EventBase):
async def send_invite(
self, destination: str, room_id: str, event_id: str, pdu: EventBase,
) -> EventBase:
room_version = await self.store.get_room_version_id(room_id)
room_version = await self.store.get_room_version(room_id)

content = await self._do_send_invite(destination, pdu, room_version)

pdu_dict = content["event"]

logger.debug("Got response to send_invite: %s", pdu_dict)

room_version = await self.store.get_room_version_id(room_id)
format_ver = room_version_to_event_format(room_version)

pdu = event_from_pdu_json(pdu_dict, format_ver)
pdu = event_from_pdu_json(pdu_dict, room_version.event_format)

# Check signatures are correct.
pdu = await self._check_sigs_and_hash(room_version, pdu)
pdu = await self._check_sigs_and_hash(room_version.identifier, pdu)

# FIXME: We should handle signature failures more gracefully.

return pdu

async def _do_send_invite(
self, destination: str, pdu: EventBase, room_version: str
self, destination: str, pdu: EventBase, room_version: RoomVersion
) -> JsonDict:
"""Actually sends the invite, first trying v2 API and falling back to
v1 API if necessary.
Expand All @@ -701,7 +700,7 @@ async def _do_send_invite(
event_id=pdu.event_id,
content={
"event": pdu.get_pdu_json(time_now),
"room_version": room_version,
"room_version": room_version.identifier,
"invite_room_state": pdu.unsigned.get("invite_room_state", []),
},
)
Expand All @@ -719,8 +718,7 @@ async def _do_send_invite(
# Otherwise, we assume that the remote server doesn't understand
# the v2 invite API. That's ok provided the room uses old-style event
# IDs.
v = KNOWN_ROOM_VERSIONS.get(room_version)
if v.event_format != EventFormatVersions.V1:
if room_version.event_format != EventFormatVersions.V1:
raise SynapseError(
400,
"User's homeserver does not support this room version",
Expand Down
8 changes: 2 additions & 6 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ async def _get_events_and_persist(
Logs a warning if we can't find the given event.
"""

room_version = await self.store.get_room_version_id(room_id)
room_version = await self.store.get_room_version(room_id)

event_infos = []

Expand Down Expand Up @@ -1916,11 +1916,7 @@ async def _persist_auth_tree(

for e_id in missing_auth_events:
m_ev = await self.federation_client.get_pdu(
[origin],
e_id,
room_version=room_version.identifier,
outlier=True,
timeout=10000,
[origin], e_id, room_version=room_version, outlier=True, timeout=10000,
)
if m_ev and m_ev.event_id == e_id:
event_map[e_id] = m_ev
Expand Down