mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 06:53:09 -06:00
add config key for default room version
This commit is contained in:
parent
a3f15a193a
commit
2da09ef2f5
|
|
@ -929,7 +929,7 @@ func TestCapabilities(t *testing.T) {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
},
|
},
|
||||||
"m.room_versions": map[string]interface{}{
|
"m.room_versions": map[string]interface{}{
|
||||||
"default": version.DefaultRoomVersion(),
|
"default": config.DefaultForDefaultRoomVersion(),
|
||||||
"available": versionsMap,
|
"available": versionsMap,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ package routing
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/version"
|
"github.com/matrix-org/dendrite/roomserver/version"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
@ -24,7 +25,7 @@ import (
|
||||||
|
|
||||||
// GetCapabilities returns information about the server's supported feature set
|
// GetCapabilities returns information about the server's supported feature set
|
||||||
// and other relevant capabilities to an authenticated user.
|
// and other relevant capabilities to an authenticated user.
|
||||||
func GetCapabilities() util.JSONResponse {
|
func GetCapabilities(rsAPI roomserverAPI.ClientRoomserverAPI) util.JSONResponse {
|
||||||
versionsMap := map[gomatrixserverlib.RoomVersion]string{}
|
versionsMap := map[gomatrixserverlib.RoomVersion]string{}
|
||||||
for v, desc := range version.SupportedRoomVersions() {
|
for v, desc := range version.SupportedRoomVersions() {
|
||||||
if desc.Stable() {
|
if desc.Stable() {
|
||||||
|
|
@ -40,7 +41,7 @@ func GetCapabilities() util.JSONResponse {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
},
|
},
|
||||||
"m.room_versions": map[string]interface{}{
|
"m.room_versions": map[string]interface{}{
|
||||||
"default": version.DefaultRoomVersion(),
|
"default": rsAPI.DefaultRoomVersion(),
|
||||||
"available": versionsMap,
|
"available": versionsMap,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ func createRoom(
|
||||||
|
|
||||||
// Clobber keys: creator, room_version
|
// Clobber keys: creator, room_version
|
||||||
|
|
||||||
roomVersion := roomserverVersion.DefaultRoomVersion()
|
roomVersion := rsAPI.DefaultRoomVersion()
|
||||||
if createRequest.RoomVersion != "" {
|
if createRequest.RoomVersion != "" {
|
||||||
candidateVersion := gomatrixserverlib.RoomVersion(createRequest.RoomVersion)
|
candidateVersion := gomatrixserverlib.RoomVersion(createRequest.RoomVersion)
|
||||||
_, roomVersionError := roomserverVersion.SupportedRoomVersion(candidateVersion)
|
_, roomVersionError := roomserverVersion.SupportedRoomVersion(candidateVersion)
|
||||||
|
|
|
||||||
|
|
@ -1256,7 +1256,7 @@ func Setup(
|
||||||
if r := rateLimits.Limit(req, device); r != nil {
|
if r := rateLimits.Limit(req, device); r != nil {
|
||||||
return *r
|
return *r
|
||||||
}
|
}
|
||||||
return GetCapabilities()
|
return GetCapabilities(rsAPI)
|
||||||
}, httputil.WithAllowGuests()),
|
}, httputil.WithAllowGuests()),
|
||||||
).Methods(http.MethodGet, http.MethodOptions)
|
).Methods(http.MethodGet, http.MethodOptions)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/roomserver/version"
|
|
||||||
|
|
||||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
|
|
@ -135,7 +134,7 @@ func SendServerNotice(
|
||||||
|
|
||||||
var (
|
var (
|
||||||
roomID string
|
roomID string
|
||||||
roomVersion = version.DefaultRoomVersion()
|
roomVersion = rsAPI.DefaultRoomVersion()
|
||||||
)
|
)
|
||||||
|
|
||||||
// create a new room for the user
|
// create a new room for the user
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ type RestrictedJoinAPI interface {
|
||||||
LocallyJoinedUsers(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, roomNID types.RoomNID) ([]gomatrixserverlib.PDU, error)
|
LocallyJoinedUsers(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, roomNID types.RoomNID) ([]gomatrixserverlib.PDU, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DefaultRoomVersionAPI interface {
|
||||||
|
// Returns the default room version used.
|
||||||
|
DefaultRoomVersion() gomatrixserverlib.RoomVersion
|
||||||
|
}
|
||||||
|
|
||||||
// RoomserverInputAPI is used to write events to the room server.
|
// RoomserverInputAPI is used to write events to the room server.
|
||||||
type RoomserverInternalAPI interface {
|
type RoomserverInternalAPI interface {
|
||||||
SyncRoomserverAPI
|
SyncRoomserverAPI
|
||||||
|
|
@ -64,6 +69,7 @@ type RoomserverInternalAPI interface {
|
||||||
FederationRoomserverAPI
|
FederationRoomserverAPI
|
||||||
QuerySenderIDAPI
|
QuerySenderIDAPI
|
||||||
UserRoomPrivateKeyCreator
|
UserRoomPrivateKeyCreator
|
||||||
|
DefaultRoomVersionAPI
|
||||||
|
|
||||||
// needed to avoid chicken and egg scenario when setting up the
|
// needed to avoid chicken and egg scenario when setting up the
|
||||||
// interdependencies between the roomserver and other input APIs
|
// interdependencies between the roomserver and other input APIs
|
||||||
|
|
@ -210,6 +216,7 @@ type ClientRoomserverAPI interface {
|
||||||
QuerySenderIDAPI
|
QuerySenderIDAPI
|
||||||
UserRoomPrivateKeyCreator
|
UserRoomPrivateKeyCreator
|
||||||
QueryRoomHierarchyAPI
|
QueryRoomHierarchyAPI
|
||||||
|
DefaultRoomVersionAPI
|
||||||
QueryMembershipForUser(ctx context.Context, req *QueryMembershipForUserRequest, res *QueryMembershipForUserResponse) error
|
QueryMembershipForUser(ctx context.Context, req *QueryMembershipForUserRequest, res *QueryMembershipForUserResponse) error
|
||||||
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
||||||
QueryRoomsForUser(ctx context.Context, req *QueryRoomsForUserRequest, res *QueryRoomsForUserResponse) error
|
QueryRoomsForUser(ctx context.Context, req *QueryRoomsForUserRequest, res *QueryRoomsForUserResponse) error
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ type RoomserverInternalAPI struct {
|
||||||
OutputProducer *producers.RoomEventProducer
|
OutputProducer *producers.RoomEventProducer
|
||||||
PerspectiveServerNames []spec.ServerName
|
PerspectiveServerNames []spec.ServerName
|
||||||
enableMetrics bool
|
enableMetrics bool
|
||||||
|
defaultRoomVersion gomatrixserverlib.RoomVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRoomserverAPI(
|
func NewRoomserverAPI(
|
||||||
|
|
@ -92,6 +93,7 @@ func NewRoomserverAPI(
|
||||||
Durable: dendriteCfg.Global.JetStream.Durable("RoomserverInputConsumer"),
|
Durable: dendriteCfg.Global.JetStream.Durable("RoomserverInputConsumer"),
|
||||||
ServerACLs: serverACLs,
|
ServerACLs: serverACLs,
|
||||||
enableMetrics: enableMetrics,
|
enableMetrics: enableMetrics,
|
||||||
|
defaultRoomVersion: dendriteCfg.RoomServer.DefaultRoomVersion,
|
||||||
// perform-er structs + queryer struct get initialised when we have a federation sender to use
|
// perform-er structs + queryer struct get initialised when we have a federation sender to use
|
||||||
}
|
}
|
||||||
return a
|
return a
|
||||||
|
|
@ -218,6 +220,10 @@ func (r *RoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceInternalA
|
||||||
r.asAPI = asAPI
|
r.asAPI = asAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *RoomserverInternalAPI) DefaultRoomVersion() gomatrixserverlib.RoomVersion {
|
||||||
|
return r.defaultRoomVersion
|
||||||
|
}
|
||||||
|
|
||||||
func (r *RoomserverInternalAPI) IsKnownRoom(ctx context.Context, roomID spec.RoomID) (bool, error) {
|
func (r *RoomserverInternalAPI) IsKnownRoom(ctx context.Context, roomID spec.RoomID) (bool, error) {
|
||||||
return r.Inviter.IsKnownRoom(ctx, roomID)
|
return r.Inviter.IsKnownRoom(ctx, roomID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/version"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
@ -1060,7 +1059,7 @@ func TestUpgrade(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("upgrade userID is invalid")
|
t.Fatalf("upgrade userID is invalid")
|
||||||
}
|
}
|
||||||
newRoomID, err := rsAPI.PerformRoomUpgrade(processCtx.Context(), roomID, *userID, version.DefaultRoomVersion())
|
newRoomID, err := rsAPI.PerformRoomUpgrade(processCtx.Context(), roomID, *userID, rsAPI.DefaultRoomVersion())
|
||||||
if err != nil && tc.wantNewRoom {
|
if err != nil && tc.wantNewRoom {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,6 @@ import (
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultRoomVersion contains the room version that will, by
|
|
||||||
// default, be used to create new rooms on this server.
|
|
||||||
func DefaultRoomVersion() gomatrixserverlib.RoomVersion {
|
|
||||||
return gomatrixserverlib.RoomVersionV10
|
|
||||||
}
|
|
||||||
|
|
||||||
// RoomVersions returns a map of all known room versions to this
|
// RoomVersions returns a map of all known room versions to this
|
||||||
// server.
|
// server.
|
||||||
func RoomVersions() map[gomatrixserverlib.RoomVersion]gomatrixserverlib.IRoomVersion {
|
func RoomVersions() map[gomatrixserverlib.RoomVersion]gomatrixserverlib.IRoomVersion {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,22 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
type RoomServer struct {
|
type RoomServer struct {
|
||||||
Matrix *Global `yaml:"-"`
|
Matrix *Global `yaml:"-"`
|
||||||
|
|
||||||
|
DefaultRoomVersion gomatrixserverlib.RoomVersion
|
||||||
|
|
||||||
Database DatabaseOptions `yaml:"database,omitempty"`
|
Database DatabaseOptions `yaml:"database,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RoomServer) Defaults(opts DefaultOpts) {
|
func (c *RoomServer) Defaults(opts DefaultOpts) {
|
||||||
|
c.DefaultRoomVersion = DefaultForDefaultRoomVersion()
|
||||||
if opts.Generate {
|
if opts.Generate {
|
||||||
if !opts.SingleDatabase {
|
if !opts.SingleDatabase {
|
||||||
c.Database.ConnectionString = "file:roomserver.db"
|
c.Database.ConnectionString = "file:roomserver.db"
|
||||||
|
|
@ -18,4 +28,18 @@ func (c *RoomServer) Verify(configErrs *ConfigErrors) {
|
||||||
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
||||||
checkNotEmpty(configErrs, "room_server.database.connection_string", string(c.Database.ConnectionString))
|
checkNotEmpty(configErrs, "room_server.database.connection_string", string(c.Database.ConnectionString))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !gomatrixserverlib.KnownRoomVersion(c.DefaultRoomVersion) {
|
||||||
|
configErrs.Add(fmt.Sprintf("invalid value for config key 'room_server.default_room_version': unsupported default room version: %q", c.DefaultRoomVersion))
|
||||||
|
} else if gomatrixserverlib.StableRoomVersion(c.DefaultRoomVersion) {
|
||||||
|
log.Warnf("WARNING: Provided default room version %q is unstable", c.DefaultRoomVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the value that is the default for the room_server.default_room_version config key
|
||||||
|
//
|
||||||
|
// Do not use this if you want the default room version, use roomserverAPI.DefaultRoomVersion instead.
|
||||||
|
// This function exists for easier test writing.
|
||||||
|
func DefaultForDefaultRoomVersion() gomatrixserverlib.RoomVersion {
|
||||||
|
return gomatrixserverlib.RoomVersionV10
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue