2019-04-01 11:24:38 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2019 New Vector Ltd
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2019-10-02 14:29:01 +02:00
|
|
|
|
|
|
|
from typing import Dict
|
|
|
|
|
2019-04-01 11:24:38 +02:00
|
|
|
import attr
|
|
|
|
|
|
|
|
|
|
|
|
class EventFormatVersions(object):
|
|
|
|
"""This is an internal enum for tracking the version of the event format,
|
|
|
|
independently from the room version.
|
|
|
|
"""
|
2019-06-20 11:32:02 +02:00
|
|
|
|
|
|
|
V1 = 1 # $id:server event id format
|
|
|
|
V2 = 2 # MSC1659-style $hash event id format: introduced for room v3
|
|
|
|
V3 = 3 # MSC1884-style $hash format: introduced for room v4
|
2019-04-01 11:24:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
KNOWN_EVENT_FORMAT_VERSIONS = {
|
|
|
|
EventFormatVersions.V1,
|
|
|
|
EventFormatVersions.V2,
|
2019-05-20 16:54:42 +02:00
|
|
|
EventFormatVersions.V3,
|
2019-04-01 11:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class StateResolutionVersions(object):
|
|
|
|
"""Enum to identify the state resolution algorithms"""
|
2019-06-20 11:32:02 +02:00
|
|
|
|
|
|
|
V1 = 1 # room v1 state res
|
|
|
|
V2 = 2 # MSC1442 state res: room v2 and later
|
2019-04-01 11:24:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RoomDisposition(object):
|
|
|
|
STABLE = "stable"
|
|
|
|
UNSTABLE = "unstable"
|
|
|
|
|
|
|
|
|
|
|
|
@attr.s(slots=True, frozen=True)
|
|
|
|
class RoomVersion(object):
|
|
|
|
"""An object which describes the unique attributes of a room version."""
|
|
|
|
|
2019-06-20 11:32:02 +02:00
|
|
|
identifier = attr.ib() # str; the identifier for this version
|
|
|
|
disposition = attr.ib() # str; one of the RoomDispositions
|
|
|
|
event_format = attr.ib() # int; one of the EventFormatVersions
|
|
|
|
state_res = attr.ib() # int; one of the StateResolutionVersions
|
2019-06-05 11:38:25 +02:00
|
|
|
enforce_key_validity = attr.ib() # bool
|
2019-04-01 11:24:38 +02:00
|
|
|
|
2020-01-27 17:14:54 +01:00
|
|
|
# bool: before MSC2260, anyone was allowed to send an aliases event
|
|
|
|
special_case_aliases_auth = attr.ib(type=bool, default=False)
|
|
|
|
|
2019-04-01 11:24:38 +02:00
|
|
|
|
|
|
|
class RoomVersions(object):
|
|
|
|
V1 = RoomVersion(
|
|
|
|
"1",
|
|
|
|
RoomDisposition.STABLE,
|
|
|
|
EventFormatVersions.V1,
|
|
|
|
StateResolutionVersions.V1,
|
2019-06-05 11:38:25 +02:00
|
|
|
enforce_key_validity=False,
|
2020-01-27 17:14:54 +01:00
|
|
|
special_case_aliases_auth=True,
|
2019-04-01 11:24:38 +02:00
|
|
|
)
|
|
|
|
V2 = RoomVersion(
|
|
|
|
"2",
|
|
|
|
RoomDisposition.STABLE,
|
|
|
|
EventFormatVersions.V1,
|
|
|
|
StateResolutionVersions.V2,
|
2019-06-05 11:38:25 +02:00
|
|
|
enforce_key_validity=False,
|
2020-01-27 17:14:54 +01:00
|
|
|
special_case_aliases_auth=True,
|
2019-04-01 11:24:38 +02:00
|
|
|
)
|
|
|
|
V3 = RoomVersion(
|
|
|
|
"3",
|
|
|
|
RoomDisposition.STABLE,
|
|
|
|
EventFormatVersions.V2,
|
|
|
|
StateResolutionVersions.V2,
|
2019-06-05 11:38:25 +02:00
|
|
|
enforce_key_validity=False,
|
2020-01-27 17:14:54 +01:00
|
|
|
special_case_aliases_auth=True,
|
2019-04-01 11:24:38 +02:00
|
|
|
)
|
2019-05-21 17:22:54 +02:00
|
|
|
V4 = RoomVersion(
|
|
|
|
"4",
|
|
|
|
RoomDisposition.STABLE,
|
2019-05-20 16:54:42 +02:00
|
|
|
EventFormatVersions.V3,
|
|
|
|
StateResolutionVersions.V2,
|
2019-06-05 11:38:25 +02:00
|
|
|
enforce_key_validity=False,
|
2020-01-27 17:14:54 +01:00
|
|
|
special_case_aliases_auth=True,
|
2019-06-05 11:38:25 +02:00
|
|
|
)
|
2019-06-05 11:58:51 +02:00
|
|
|
V5 = RoomVersion(
|
|
|
|
"5",
|
|
|
|
RoomDisposition.STABLE,
|
2019-06-05 11:38:25 +02:00
|
|
|
EventFormatVersions.V3,
|
|
|
|
StateResolutionVersions.V2,
|
2019-06-05 11:58:51 +02:00
|
|
|
enforce_key_validity=True,
|
2020-01-27 17:14:54 +01:00
|
|
|
special_case_aliases_auth=True,
|
|
|
|
)
|
|
|
|
MSC2260_DEV = RoomVersion(
|
|
|
|
"org.matrix.msc2260",
|
|
|
|
RoomDisposition.UNSTABLE,
|
|
|
|
EventFormatVersions.V3,
|
|
|
|
StateResolutionVersions.V2,
|
|
|
|
enforce_key_validity=True,
|
2019-05-20 16:54:42 +02:00
|
|
|
)
|
2019-04-01 11:24:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
KNOWN_ROOM_VERSIONS = {
|
2019-06-20 11:32:02 +02:00
|
|
|
v.identifier: v
|
|
|
|
for v in (
|
2019-04-01 11:24:38 +02:00
|
|
|
RoomVersions.V1,
|
|
|
|
RoomVersions.V2,
|
|
|
|
RoomVersions.V3,
|
2019-05-21 17:22:54 +02:00
|
|
|
RoomVersions.V4,
|
2019-06-05 11:58:51 +02:00
|
|
|
RoomVersions.V5,
|
2020-01-27 17:14:54 +01:00
|
|
|
RoomVersions.MSC2260_DEV,
|
2019-04-01 11:24:38 +02:00
|
|
|
)
|
2019-10-02 14:29:01 +02:00
|
|
|
} # type: Dict[str, RoomVersion]
|