From fe74f1ba0e64e216552d3370995f7fe7849ca639 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 5 Feb 2020 13:23:15 +0000 Subject: [PATCH] Update room version metadata --- roomserver/version/version.go | 106 ++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 44 deletions(-) diff --git a/roomserver/version/version.go b/roomserver/version/version.go index 6c726991f..807a39276 100644 --- a/roomserver/version/version.go +++ b/roomserver/version/version.go @@ -18,56 +18,74 @@ const ( ) const ( - EventFormatV1 EventFormatID = iota + 1 - EventFormatV2 - EventFormatV3 + EventFormatV1 EventFormatID = iota + 1 // original event ID formatting + EventFormatV2 // event ID is event hash + EventFormatV3 // event ID is URL-safe base64 event hash ) type RoomVersionDescription struct { - Supported bool - Stable bool - StateResolution state.StateResolutionVersion - EventFormat EventFormatID + Supported bool + Stable bool + StateResolution state.StateResolutionVersion + EventFormat EventFormatID + EnforceSigningKeyValidity bool } -func GetRoomVersionDescription(version RoomVersionID) (desc RoomVersionDescription, err error) { - switch version { - case RoomVersionV1: - desc = RoomVersionDescription{ - Supported: true, - Stable: true, - StateResolution: state.StateResolutionAlgorithmV1, - EventFormat: EventFormatV1, +var roomVersions = map[string]RoomVersionDescription{ + RoomVersionV1: RoomVersionDescription{ + Supported: true, + Stable: true, + StateResolution: state.StateResolutionAlgorithmV1, + EventFormat: EventFormatV1, + EnforceSigningKeyValidity: false, + }, + RoomVersionV2: RoomVersionDescription{ + Supported: false, + Stable: true, + StateResolution: state.StateResolutionAlgorithmV2, + EventFormat: EventFormatV1, + EnforceSigningKeyValidity: false, + }, + RoomVersionV3: RoomVersionDescription{ + Supported: false, + Stable: true, + StateResolution: state.StateResolutionAlgorithmV2, + EventFormat: EventFormatV2, + EnforceSigningKeyValidity: false, + }, + RoomVersionV4: RoomVersionDescription{ + Supported: false, + Stable: true, + StateResolution: state.StateResolutionAlgorithmV2, + EventFormat: EventFormatV3, + EnforceSigningKeyValidity: false, + }, + RoomVersionV5: RoomVersionDescription{ + Supported: false, + Stable: true, + StateResolution: state.StateResolutionAlgorithmV2, + EventFormat: EventFormatV3, + EnforceSigningKeyValidity: true, + }, +} + +func GetRoomVersions() map[string]RoomVersionDescription { + return roomVersions +} + +func GetSupportedRoomVersions() map[string]RoomVersionDescription { + versions := make(map[string]RoomVersionDescription) + for id, version := range GetRoomVersionDescriptions() { + if version.Supported { + versions[id] = version } - case RoomVersionV2: - desc = RoomVersionDescription{ - Supported: false, - Stable: true, - StateResolution: state.StateResolutionAlgorithmV2, - EventFormat: EventFormatV1, - } - case RoomVersionV3: - desc = RoomVersionDescription{ - Supported: false, - Stable: true, - StateResolution: state.StateResolutionAlgorithmV2, - EventFormat: EventFormatV1, - } - case RoomVersionV4: - desc = RoomVersionDescription{ - Supported: false, - Stable: true, - StateResolution: state.StateResolutionAlgorithmV2, - EventFormat: EventFormatV2, - } - case RoomVersionV5: - desc = RoomVersionDescription{ - Supported: false, - Stable: true, - StateResolution: state.StateResolutionAlgorithmV2, - EventFormat: EventFormatV3, - } - default: + } + return versions +} + +func GetSupportedRoomVersion(version RoomVersionID) (desc RoomVersionDescription, err error) { + if version, ok := roomVersions[version]; ok { + desc = version } if !desc.Supported { err = errors.New("unsupported room version")