2020-02-05 18:06:39 +00:00
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2020-02-05 16:25:58 +00:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
2020-03-16 16:05:29 +00:00
|
|
|
"fmt"
|
2020-02-05 16:25:58 +00:00
|
|
|
|
2020-03-16 16:05:29 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2020-02-05 16:25:58 +00:00
|
|
|
)
|
|
|
|
|
2020-03-16 16:05:29 +00:00
|
|
|
// RoomVersionDescription contains information about a room version,
|
|
|
|
// namely whether it is marked as supported or stable in this server
|
|
|
|
// version.
|
|
|
|
// A version is supported if the server has some support for rooms
|
|
|
|
// that are this version. A version is marked as stable or unstable
|
|
|
|
// in order to hint whether the version should be used to clients
|
|
|
|
// calling the /capabilities endpoint.
|
|
|
|
// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-capabilities
|
2020-02-05 16:25:58 +00:00
|
|
|
type RoomVersionDescription struct {
|
2020-03-16 16:05:29 +00:00
|
|
|
Supported bool
|
|
|
|
Stable bool
|
2020-02-05 16:25:58 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 16:05:29 +00:00
|
|
|
var roomVersions = map[gomatrixserverlib.RoomVersion]RoomVersionDescription{
|
|
|
|
gomatrixserverlib.RoomVersionV1: RoomVersionDescription{
|
|
|
|
Supported: true,
|
|
|
|
Stable: true,
|
2020-02-05 16:25:58 +00:00
|
|
|
},
|
2020-03-16 16:05:29 +00:00
|
|
|
gomatrixserverlib.RoomVersionV2: RoomVersionDescription{
|
2020-03-27 16:28:22 +00:00
|
|
|
Supported: true,
|
|
|
|
Stable: true,
|
2020-02-05 16:25:58 +00:00
|
|
|
},
|
2020-03-16 16:05:29 +00:00
|
|
|
gomatrixserverlib.RoomVersionV3: RoomVersionDescription{
|
Federation for v3/v4 rooms (#954)
* Update gomatrixserverlib
* Default to room version 4
* Update gomatrixserverlib
* Limit prev_events and auth_events
* Fix auth_events, prev_events
* Fix linter issues
* Update gomatrixserverlib
* Fix getState
* Update sytest-whitelist
* Squashed commit of the following:
commit 067b87506357c996fd6ddb11271db9469ad4ce80
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Apr 3 14:29:06 2020 +0100
Invites v2 endpoint (#952)
* Start converting v1 invite endpoint to v2
* Update gomatrixserverlib
* Early federationsender code for sending invites
* Sending invites sorta happens now
* Populate invite request with stripped state
* Remodel a bit, don't reflect received invites
* Handle invite_room_state
* Handle room versions a bit better
* Update gomatrixserverlib
* Tweak order in destinationQueue.next
* Revert check in processMessage
* Tweak federation sender destination queue code a bit
* Add comments
commit 955244c09298d0e6c870377dad3af2ffa1f5e578
Author: Ben B <benne@klimlive.de>
Date: Fri Apr 3 12:40:50 2020 +0200
use custom http client instead of the http DefaultClient (#823)
This commit replaces the default client from the http lib with a custom one.
The previously used default client doesn't come with a timeout. This could cause
unwanted locks.
That solution chosen here creates a http client in the base component dendrite
with a constant timeout of 30 seconds. If it should be necessary to overwrite
this, we could include the timeout in the dendrite configuration.
Here it would be a good idea to extend the type "Address" by a timeout and
create an http client for each service.
Closes #820
Signed-off-by: Benedikt Bongartz <benne@klimlive.de>
Co-authored-by: Kegsay <kegan@matrix.org>
* Update sytest-whitelist, sytest-blacklist
* Update go.mod/go.sum
* Add some error wrapping for debug
* Add a NOTSPEC to common/events.go
* Perform state resolution at send_join
* Set default room version to v2 again
* Tweak GetCapabilities
* Add comments to ResolveConflictsAdhoc
* Update sytest-blacklist
* go mod tidy
* Update sytest-whitelist, sytest-blacklist
* Update versions
* Updates from review comments
* Update sytest-blacklist, sytest-whitelist
* Check room versions compatible at make_join, add some comments, update gomatrixserverlib, other tweaks
* Set default room version back to v2
* Update gomatrixserverlib, sytest-whitelist
2020-04-09 15:46:06 +01:00
|
|
|
Supported: true,
|
|
|
|
Stable: true,
|
2020-02-05 16:25:58 +00:00
|
|
|
},
|
2020-03-16 16:05:29 +00:00
|
|
|
gomatrixserverlib.RoomVersionV4: RoomVersionDescription{
|
Federation for v3/v4 rooms (#954)
* Update gomatrixserverlib
* Default to room version 4
* Update gomatrixserverlib
* Limit prev_events and auth_events
* Fix auth_events, prev_events
* Fix linter issues
* Update gomatrixserverlib
* Fix getState
* Update sytest-whitelist
* Squashed commit of the following:
commit 067b87506357c996fd6ddb11271db9469ad4ce80
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Apr 3 14:29:06 2020 +0100
Invites v2 endpoint (#952)
* Start converting v1 invite endpoint to v2
* Update gomatrixserverlib
* Early federationsender code for sending invites
* Sending invites sorta happens now
* Populate invite request with stripped state
* Remodel a bit, don't reflect received invites
* Handle invite_room_state
* Handle room versions a bit better
* Update gomatrixserverlib
* Tweak order in destinationQueue.next
* Revert check in processMessage
* Tweak federation sender destination queue code a bit
* Add comments
commit 955244c09298d0e6c870377dad3af2ffa1f5e578
Author: Ben B <benne@klimlive.de>
Date: Fri Apr 3 12:40:50 2020 +0200
use custom http client instead of the http DefaultClient (#823)
This commit replaces the default client from the http lib with a custom one.
The previously used default client doesn't come with a timeout. This could cause
unwanted locks.
That solution chosen here creates a http client in the base component dendrite
with a constant timeout of 30 seconds. If it should be necessary to overwrite
this, we could include the timeout in the dendrite configuration.
Here it would be a good idea to extend the type "Address" by a timeout and
create an http client for each service.
Closes #820
Signed-off-by: Benedikt Bongartz <benne@klimlive.de>
Co-authored-by: Kegsay <kegan@matrix.org>
* Update sytest-whitelist, sytest-blacklist
* Update go.mod/go.sum
* Add some error wrapping for debug
* Add a NOTSPEC to common/events.go
* Perform state resolution at send_join
* Set default room version to v2 again
* Tweak GetCapabilities
* Add comments to ResolveConflictsAdhoc
* Update sytest-blacklist
* go mod tidy
* Update sytest-whitelist, sytest-blacklist
* Update versions
* Updates from review comments
* Update sytest-blacklist, sytest-whitelist
* Check room versions compatible at make_join, add some comments, update gomatrixserverlib, other tweaks
* Set default room version back to v2
* Update gomatrixserverlib, sytest-whitelist
2020-04-09 15:46:06 +01:00
|
|
|
Supported: true,
|
|
|
|
Stable: true,
|
2020-02-05 16:25:58 +00:00
|
|
|
},
|
2020-03-16 16:05:29 +00:00
|
|
|
gomatrixserverlib.RoomVersionV5: RoomVersionDescription{
|
2020-04-29 19:37:00 +01:00
|
|
|
Supported: true,
|
|
|
|
Stable: true,
|
2020-02-05 16:25:58 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-03-16 16:05:29 +00:00
|
|
|
// DefaultRoomVersion contains the room version that will, by
|
|
|
|
// default, be used to create new rooms on this server.
|
|
|
|
func DefaultRoomVersion() gomatrixserverlib.RoomVersion {
|
2020-04-29 19:37:00 +01:00
|
|
|
return gomatrixserverlib.RoomVersionV5
|
2020-02-05 18:06:39 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 16:05:29 +00:00
|
|
|
// RoomVersions returns a map of all known room versions to this
|
|
|
|
// server.
|
|
|
|
func RoomVersions() map[gomatrixserverlib.RoomVersion]RoomVersionDescription {
|
2020-02-05 16:25:58 +00:00
|
|
|
return roomVersions
|
|
|
|
}
|
|
|
|
|
2020-03-16 16:05:29 +00:00
|
|
|
// SupportedRoomVersions returns a map of descriptions for room
|
|
|
|
// versions that are supported by this homeserver.
|
|
|
|
func SupportedRoomVersions() map[gomatrixserverlib.RoomVersion]RoomVersionDescription {
|
|
|
|
versions := make(map[gomatrixserverlib.RoomVersion]RoomVersionDescription)
|
|
|
|
for id, version := range RoomVersions() {
|
2020-02-05 16:25:58 +00:00
|
|
|
if version.Supported {
|
|
|
|
versions[id] = version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return versions
|
|
|
|
}
|
|
|
|
|
2020-03-16 16:05:29 +00:00
|
|
|
// RoomVersion returns information about a specific room version.
|
|
|
|
// An UnknownVersionError is returned if the version is not known
|
|
|
|
// to the server.
|
|
|
|
func RoomVersion(version gomatrixserverlib.RoomVersion) (RoomVersionDescription, error) {
|
2020-02-05 16:25:58 +00:00
|
|
|
if version, ok := roomVersions[version]; ok {
|
2020-03-16 16:05:29 +00:00
|
|
|
return version, nil
|
|
|
|
}
|
|
|
|
return RoomVersionDescription{}, UnknownVersionError{version}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SupportedRoomVersion returns information about a specific room
|
|
|
|
// version. An UnknownVersionError is returned if the version is not
|
|
|
|
// known to the server, or an UnsupportedVersionError is returned if
|
|
|
|
// the version is known but specifically marked as unsupported.
|
|
|
|
func SupportedRoomVersion(version gomatrixserverlib.RoomVersion) (RoomVersionDescription, error) {
|
|
|
|
result, err := RoomVersion(version)
|
|
|
|
if err != nil {
|
|
|
|
return RoomVersionDescription{}, err
|
2020-02-05 16:25:58 +00:00
|
|
|
}
|
2020-03-16 16:05:29 +00:00
|
|
|
if !result.Supported {
|
|
|
|
return RoomVersionDescription{}, UnsupportedVersionError{version}
|
2020-02-05 16:25:58 +00:00
|
|
|
}
|
2020-03-16 16:05:29 +00:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnknownVersionError is caused when the room version is not known.
|
|
|
|
type UnknownVersionError struct {
|
|
|
|
Version gomatrixserverlib.RoomVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e UnknownVersionError) Error() string {
|
|
|
|
return fmt.Sprintf("room version '%s' is not known", e.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnsupportedVersionError is caused when the room version is specifically
|
|
|
|
// marked as unsupported.
|
|
|
|
type UnsupportedVersionError struct {
|
|
|
|
Version gomatrixserverlib.RoomVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e UnsupportedVersionError) Error() string {
|
|
|
|
return fmt.Sprintf("room version '%s' is marked as unsupported", e.Version)
|
2020-02-05 16:25:58 +00:00
|
|
|
}
|