Merge pull request #6823 from matrix-org/rav/redact_changes/5

pass room versions around
This commit is contained in:
Richard van der Hoff 2020-02-06 11:32:33 +00:00 committed by GitHub
commit 9bcd37146e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 19 deletions

1
changelog.d/6823.misc Normal file
View File

@ -0,0 +1 @@
Refactoring work in preparation for changing the event redaction algorithm.

View File

@ -230,7 +230,7 @@ class FederationClient(FederationBase):
self, self,
destinations: Iterable[str], destinations: Iterable[str],
event_id: str, event_id: str,
room_version: str, room_version: RoomVersion,
outlier: bool = False, outlier: bool = False,
timeout: Optional[int] = None, timeout: Optional[int] = None,
) -> Optional[EventBase]: ) -> Optional[EventBase]:
@ -262,7 +262,7 @@ class FederationClient(FederationBase):
pdu_attempts = self.pdu_destination_tried.setdefault(event_id, {}) 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 signed_pdu = None
for destination in destinations: for destination in destinations:
@ -292,7 +292,9 @@ class FederationClient(FederationBase):
pdu = pdu_list[0] pdu = pdu_list[0]
# Check signatures are correct. # 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 break
@ -663,7 +665,7 @@ class FederationClient(FederationBase):
async def send_invite( async def send_invite(
self, destination: str, room_id: str, event_id: str, pdu: EventBase, self, destination: str, room_id: str, event_id: str, pdu: EventBase,
) -> 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) content = await self._do_send_invite(destination, pdu, room_version)
@ -671,20 +673,17 @@ class FederationClient(FederationBase):
logger.debug("Got response to send_invite: %s", pdu_dict) logger.debug("Got response to send_invite: %s", pdu_dict)
room_version = await self.store.get_room_version_id(room_id) pdu = event_from_pdu_json(pdu_dict, room_version.event_format)
format_ver = room_version_to_event_format(room_version)
pdu = event_from_pdu_json(pdu_dict, format_ver)
# Check signatures are correct. # 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. # FIXME: We should handle signature failures more gracefully.
return pdu return pdu
async def _do_send_invite( async def _do_send_invite(
self, destination: str, pdu: EventBase, room_version: str self, destination: str, pdu: EventBase, room_version: RoomVersion
) -> JsonDict: ) -> JsonDict:
"""Actually sends the invite, first trying v2 API and falling back to """Actually sends the invite, first trying v2 API and falling back to
v1 API if necessary. v1 API if necessary.
@ -701,7 +700,7 @@ class FederationClient(FederationBase):
event_id=pdu.event_id, event_id=pdu.event_id,
content={ content={
"event": pdu.get_pdu_json(time_now), "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", []), "invite_room_state": pdu.unsigned.get("invite_room_state", []),
}, },
) )
@ -719,8 +718,7 @@ class FederationClient(FederationBase):
# Otherwise, we assume that the remote server doesn't understand # Otherwise, we assume that the remote server doesn't understand
# the v2 invite API. That's ok provided the room uses old-style event # the v2 invite API. That's ok provided the room uses old-style event
# IDs. # IDs.
v = KNOWN_ROOM_VERSIONS.get(room_version) if room_version.event_format != EventFormatVersions.V1:
if v.event_format != EventFormatVersions.V1:
raise SynapseError( raise SynapseError(
400, 400,
"User's homeserver does not support this room version", "User's homeserver does not support this room version",

View File

@ -1156,7 +1156,7 @@ class FederationHandler(BaseHandler):
Logs a warning if we can't find the given event. 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 = [] event_infos = []
@ -1962,11 +1962,7 @@ class FederationHandler(BaseHandler):
for e_id in missing_auth_events: for e_id in missing_auth_events:
m_ev = await self.federation_client.get_pdu( m_ev = await self.federation_client.get_pdu(
[origin], [origin], e_id, room_version=room_version, outlier=True, timeout=10000,
e_id,
room_version=room_version.identifier,
outlier=True,
timeout=10000,
) )
if m_ev and m_ev.event_id == e_id: if m_ev and m_ev.event_id == e_id:
event_map[e_id] = m_ev event_map[e_id] = m_ev