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

Add rooms.room_version column #6729

Merged
merged 13 commits into from
Jan 27, 2020
28 changes: 20 additions & 8 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
StoreError,
SynapseError,
)
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersions
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion, RoomVersions
from synapse.crypto.event_signing import compute_event_signature
from synapse.event_auth import auth_types_for_event
from synapse.events import EventBase, room_version_to_event_format
Expand Down Expand Up @@ -1242,7 +1242,9 @@ def do_invite_join(self, target_hosts, room_id, joinee, content):
# FIXME
pass

yield self._persist_auth_tree(origin, auth_chain, state, event)
yield self._persist_auth_tree(
origin, auth_chain, state, event, room_version
)

# Check whether this room is the result of an upgrade of a room we already know
# about. If so, migrate over user information
Expand Down Expand Up @@ -1816,7 +1818,14 @@ def prep(ev_info: _NewEventInfo):
)

@defer.inlineCallbacks
def _persist_auth_tree(self, origin, auth_events, state, event):
def _persist_auth_tree(
self,
origin: str,
auth_events: List[EventBase],
state: List[EventBase],
event: EventBase,
room_version: RoomVersion,
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
):
"""Checks the auth chain is valid (and passes auth checks) for the
state and event. Then persists the auth chain and state atomically.
Persists the event separately. Notifies about the persisted events
Expand All @@ -1825,10 +1834,10 @@ def _persist_auth_tree(self, origin, auth_events, state, event):
Will attempt to fetch missing auth events.

Args:
origin (str): Where the events came from
auth_events (list)
state (list)
event (Event)
origin: Where the events came from
auth_events
state
event

Returns:
Deferred
Expand All @@ -1854,10 +1863,13 @@ def _persist_auth_tree(self, origin, auth_events, state, event):
# invalid, and it would fail auth checks anyway.
raise SynapseError(400, "No create event in state")

room_version = create_event.content.get(
room_version_id = create_event.content.get(
"room_version", RoomVersions.V1.identifier
)

if room_version.identifier != room_version_id:
raise SynapseError(400, "Room version mismatch")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that 400 is the right response code when the remote server lies to us, but 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the closest error code to "please bugger off and never sully our doors with that request again" that I know of :)


missing_auth_events = set()
for e in itertools.chain(auth_events, state, [event]):
for e_id in e.auth_event_ids():
Expand Down