aboutsummaryrefslogtreecommitdiff
path: root/roomserver
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2023-04-19 15:50:33 +0100
committerGitHub <noreply@github.com>2023-04-19 15:50:33 +0100
commit72285b2659a31ebd52c91799c17105d81d996f40 (patch)
tree1855395f5efdc3ea6051dd502882bf62aaa57e7c /roomserver
parent9fa39263c0a4a8d349c8715f6ba30cae30b1b73a (diff)
refactor: update GMSL (#3058)
Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364 Read this commit by commit to avoid going insane.
Diffstat (limited to 'roomserver')
-rw-r--r--roomserver/acls/acls.go5
-rw-r--r--roomserver/api/api.go3
-rw-r--r--roomserver/api/input.go9
-rw-r--r--roomserver/api/output.go3
-rw-r--r--roomserver/api/perform.go54
-rw-r--r--roomserver/api/query.go11
-rw-r--r--roomserver/api/wrapper.go25
-rw-r--r--roomserver/auth/auth.go13
-rw-r--r--roomserver/internal/alias.go7
-rw-r--r--roomserver/internal/api.go7
-rw-r--r--roomserver/internal/helpers/auth.go3
-rw-r--r--roomserver/internal/helpers/helpers.go15
-rw-r--r--roomserver/internal/input/input.go5
-rw-r--r--roomserver/internal/input/input_events.go23
-rw-r--r--roomserver/internal/input/input_events_test.go9
-rw-r--r--roomserver/internal/input/input_membership.go13
-rw-r--r--roomserver/internal/input/input_missing.go13
-rw-r--r--roomserver/internal/perform/perform_admin.go11
-rw-r--r--roomserver/internal/perform/perform_backfill.go35
-rw-r--r--roomserver/internal/perform/perform_invite.go18
-rw-r--r--roomserver/internal/perform/perform_join.go17
-rw-r--r--roomserver/internal/perform/perform_leave.go9
-rw-r--r--roomserver/internal/perform/perform_peek.go3
-rw-r--r--roomserver/internal/perform/perform_unpeek.go3
-rw-r--r--roomserver/internal/perform/perform_upgrade.go59
-rw-r--r--roomserver/internal/query/query.go17
-rw-r--r--roomserver/roomserver_test.go29
-rw-r--r--roomserver/storage/interface.go3
-rw-r--r--roomserver/storage/postgres/membership_table.go4
-rw-r--r--roomserver/storage/shared/storage.go9
-rw-r--r--roomserver/storage/sqlite3/membership_table.go5
-rw-r--r--roomserver/storage/tables/interface.go15
32 files changed, 243 insertions, 212 deletions
diff --git a/roomserver/acls/acls.go b/roomserver/acls/acls.go
index b18daa3d..80d45e8c 100644
--- a/roomserver/acls/acls.go
+++ b/roomserver/acls/acls.go
@@ -24,6 +24,7 @@ import (
"sync"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/sirupsen/logrus"
)
@@ -120,7 +121,7 @@ func (s *ServerACLs) OnServerACLUpdate(state *gomatrixserverlib.Event) {
s.acls[state.RoomID()] = acls
}
-func (s *ServerACLs) IsServerBannedFromRoom(serverName gomatrixserverlib.ServerName, roomID string) bool {
+func (s *ServerACLs) IsServerBannedFromRoom(serverName spec.ServerName, roomID string) bool {
s.aclsMutex.RLock()
// First of all check if we have an ACL for this room. If we don't then
// no servers are banned from the room.
@@ -133,7 +134,7 @@ func (s *ServerACLs) IsServerBannedFromRoom(serverName gomatrixserverlib.ServerN
// Split the host and port apart. This is because the spec calls on us to
// validate the hostname only in cases where the port is also present.
if serverNameOnly, _, err := net.SplitHostPort(string(serverName)); err == nil {
- serverName = gomatrixserverlib.ServerName(serverNameOnly)
+ serverName = spec.ServerName(serverNameOnly)
}
// Check if the hostname is an IPv4 or IPv6 literal. We cheat here by adding
// a /0 prefix length just to trick ParseCIDR into working. If we find that
diff --git a/roomserver/api/api.go b/roomserver/api/api.go
index dda5bb5a..4ce40e3e 100644
--- a/roomserver/api/api.go
+++ b/roomserver/api/api.go
@@ -4,6 +4,7 @@ import (
"context"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
asAPI "github.com/matrix-org/dendrite/appservice/api"
fsAPI "github.com/matrix-org/dendrite/federationapi/api"
@@ -197,7 +198,7 @@ type FederationRoomserverAPI interface {
// Query missing events for a room from roomserver
QueryMissingEvents(ctx context.Context, req *QueryMissingEventsRequest, res *QueryMissingEventsResponse) error
// Query whether a server is allowed to see an event
- QueryServerAllowedToSeeEvent(ctx context.Context, serverName gomatrixserverlib.ServerName, eventID string) (allowed bool, err error)
+ QueryServerAllowedToSeeEvent(ctx context.Context, serverName spec.ServerName, eventID string) (allowed bool, err error)
QueryRoomsForUser(ctx context.Context, req *QueryRoomsForUserRequest, res *QueryRoomsForUserResponse) error
QueryRestrictedJoinAllowed(ctx context.Context, req *QueryRestrictedJoinAllowedRequest, res *QueryRestrictedJoinAllowedResponse) error
PerformInboundPeek(ctx context.Context, req *PerformInboundPeekRequest, res *PerformInboundPeekResponse) error
diff --git a/roomserver/api/input.go b/roomserver/api/input.go
index 88d52327..b52317cd 100644
--- a/roomserver/api/input.go
+++ b/roomserver/api/input.go
@@ -19,6 +19,7 @@ import (
"fmt"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type Kind int
@@ -68,7 +69,7 @@ type InputRoomEvent struct {
// The event JSON for the event to add.
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
// Which server told us about this event.
- Origin gomatrixserverlib.ServerName `json:"origin"`
+ Origin spec.ServerName `json:"origin"`
// Whether the state is supplied as a list of event IDs or whether it
// should be derived from the state at the previous events.
HasState bool `json:"has_state"`
@@ -94,9 +95,9 @@ type TransactionID struct {
// InputRoomEventsRequest is a request to InputRoomEvents
type InputRoomEventsRequest struct {
- InputRoomEvents []InputRoomEvent `json:"input_room_events"`
- Asynchronous bool `json:"async"`
- VirtualHost gomatrixserverlib.ServerName `json:"virtual_host"`
+ InputRoomEvents []InputRoomEvent `json:"input_room_events"`
+ Asynchronous bool `json:"async"`
+ VirtualHost spec.ServerName `json:"virtual_host"`
}
// InputRoomEventsResponse is a response to InputRoomEvents
diff --git a/roomserver/api/output.go b/roomserver/api/output.go
index 0c0f52c4..73788747 100644
--- a/roomserver/api/output.go
+++ b/roomserver/api/output.go
@@ -16,6 +16,7 @@ package api
import (
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
// An OutputType is a type of roomserver output.
@@ -250,7 +251,7 @@ type OutputNewInboundPeek struct {
// a race between tracking the state returned by /peek and emitting subsequent
// peeked events)
LatestEventID string
- ServerName gomatrixserverlib.ServerName
+ ServerName spec.ServerName
// how often we told the peeking server to renew the peek
RenewalInterval int64
}
diff --git a/roomserver/api/perform.go b/roomserver/api/perform.go
index 83cb0460..e125a300 100644
--- a/roomserver/api/perform.go
+++ b/roomserver/api/perform.go
@@ -6,6 +6,8 @@ import (
"net/http"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
@@ -76,18 +78,18 @@ const (
)
type PerformJoinRequest struct {
- RoomIDOrAlias string `json:"room_id_or_alias"`
- UserID string `json:"user_id"`
- IsGuest bool `json:"is_guest"`
- Content map[string]interface{} `json:"content"`
- ServerNames []gomatrixserverlib.ServerName `json:"server_names"`
- Unsigned map[string]interface{} `json:"unsigned"`
+ RoomIDOrAlias string `json:"room_id_or_alias"`
+ UserID string `json:"user_id"`
+ IsGuest bool `json:"is_guest"`
+ Content map[string]interface{} `json:"content"`
+ ServerNames []spec.ServerName `json:"server_names"`
+ Unsigned map[string]interface{} `json:"unsigned"`
}
type PerformJoinResponse struct {
// The room ID, populated on success.
RoomID string `json:"room_id"`
- JoinedVia gomatrixserverlib.ServerName
+ JoinedVia spec.ServerName
// If non-nil, the join request failed. Contains more information why it failed.
Error *PerformError
}
@@ -103,11 +105,11 @@ type PerformLeaveResponse struct {
}
type PerformInviteRequest struct {
- RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
- Event *gomatrixserverlib.HeaderedEvent `json:"event"`
- InviteRoomState []gomatrixserverlib.InviteV2StrippedState `json:"invite_room_state"`
- SendAsServer string `json:"send_as_server"`
- TransactionID *TransactionID `json:"transaction_id"`
+ RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
+ Event *gomatrixserverlib.HeaderedEvent `json:"event"`
+ InviteRoomState []fclient.InviteV2StrippedState `json:"invite_room_state"`
+ SendAsServer string `json:"send_as_server"`
+ TransactionID *TransactionID `json:"transaction_id"`
}
type PerformInviteResponse struct {
@@ -115,10 +117,10 @@ type PerformInviteResponse struct {
}
type PerformPeekRequest struct {
- RoomIDOrAlias string `json:"room_id_or_alias"`
- UserID string `json:"user_id"`
- DeviceID string `json:"device_id"`
- ServerNames []gomatrixserverlib.ServerName `json:"server_names"`
+ RoomIDOrAlias string `json:"room_id_or_alias"`
+ UserID string `json:"user_id"`
+ DeviceID string `json:"device_id"`
+ ServerNames []spec.ServerName `json:"server_names"`
}
type PerformPeekResponse struct {
@@ -148,9 +150,9 @@ type PerformBackfillRequest struct {
// The maximum number of events to retrieve.
Limit int `json:"limit"`
// The server interested in the events.
- ServerName gomatrixserverlib.ServerName `json:"server_name"`
+ ServerName spec.ServerName `json:"server_name"`
// Which virtual host are we doing this for?
- VirtualHost gomatrixserverlib.ServerName `json:"virtual_host"`
+ VirtualHost spec.ServerName `json:"virtual_host"`
}
// PrevEventIDs returns the prev_event IDs of all backwards extremities, de-duplicated in a lexicographically sorted order.
@@ -183,11 +185,11 @@ type PerformPublishResponse struct {
}
type PerformInboundPeekRequest struct {
- UserID string `json:"user_id"`
- RoomID string `json:"room_id"`
- PeekID string `json:"peek_id"`
- ServerName gomatrixserverlib.ServerName `json:"server_name"`
- RenewalInterval int64 `json:"renewal_interval"`
+ UserID string `json:"user_id"`
+ RoomID string `json:"room_id"`
+ PeekID string `json:"peek_id"`
+ ServerName spec.ServerName `json:"server_name"`
+ RenewalInterval int64 `json:"renewal_interval"`
}
type PerformInboundPeekResponse struct {
@@ -250,9 +252,9 @@ type PerformAdminPurgeRoomResponse struct {
}
type PerformAdminDownloadStateRequest struct {
- RoomID string `json:"room_id"`
- UserID string `json:"user_id"`
- ServerName gomatrixserverlib.ServerName `json:"server_name"`
+ RoomID string `json:"room_id"`
+ UserID string `json:"user_id"`
+ ServerName spec.ServerName `json:"server_name"`
}
type PerformAdminDownloadStateResponse struct {
diff --git a/roomserver/api/query.go b/roomserver/api/query.go
index 612c3315..56915b1e 100644
--- a/roomserver/api/query.go
+++ b/roomserver/api/query.go
@@ -22,6 +22,7 @@ import (
"strings"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/syncapi/synctypes"
@@ -159,7 +160,7 @@ type QueryMembershipsForRoomResponse struct {
type QueryServerJoinedToRoomRequest struct {
// Server name of the server to find. If not specified, we will
// default to checking if the local server is joined.
- ServerName gomatrixserverlib.ServerName `json:"server_name"`
+ ServerName spec.ServerName `json:"server_name"`
// ID of the room to see if we are still joined to
RoomID string `json:"room_id"`
}
@@ -177,7 +178,7 @@ type QueryServerAllowedToSeeEventRequest struct {
// The event ID to look up invites in.
EventID string `json:"event_id"`
// The server interested in the event
- ServerName gomatrixserverlib.ServerName `json:"server_name"`
+ ServerName spec.ServerName `json:"server_name"`
}
// QueryServerAllowedToSeeEventResponse is a response to QueryServerAllowedToSeeEvent
@@ -195,7 +196,7 @@ type QueryMissingEventsRequest struct {
// Limit the number of events this query returns.
Limit int `json:"limit"`
// The server interested in the event
- ServerName gomatrixserverlib.ServerName `json:"server_name"`
+ ServerName spec.ServerName `json:"server_name"`
}
// QueryMissingEventsResponse is a response to QueryMissingEvents
@@ -340,8 +341,8 @@ type QueryKnownUsersResponse struct {
}
type QueryServerBannedFromRoomRequest struct {
- ServerName gomatrixserverlib.ServerName `json:"server_name"`
- RoomID string `json:"room_id"`
+ ServerName spec.ServerName `json:"server_name"`
+ RoomID string `json:"room_id"`
}
type QueryServerBannedFromRoomResponse struct {
diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go
index 831ffe25..ff4445bf 100644
--- a/roomserver/api/wrapper.go
+++ b/roomserver/api/wrapper.go
@@ -19,6 +19,7 @@ import (
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
)
@@ -27,8 +28,8 @@ import (
func SendEvents(
ctx context.Context, rsAPI InputRoomEventsAPI,
kind Kind, events []*gomatrixserverlib.HeaderedEvent,
- virtualHost, origin gomatrixserverlib.ServerName,
- sendAsServer gomatrixserverlib.ServerName, txnID *TransactionID,
+ virtualHost, origin spec.ServerName,
+ sendAsServer spec.ServerName, txnID *TransactionID,
async bool,
) error {
ires := make([]InputRoomEvent, len(events))
@@ -49,9 +50,9 @@ func SendEvents(
// marked as `true` in haveEventIDs.
func SendEventWithState(
ctx context.Context, rsAPI InputRoomEventsAPI,
- virtualHost gomatrixserverlib.ServerName, kind Kind,
+ virtualHost spec.ServerName, kind Kind,
state gomatrixserverlib.StateResponse, event *gomatrixserverlib.HeaderedEvent,
- origin gomatrixserverlib.ServerName, haveEventIDs map[string]bool, async bool,
+ origin spec.ServerName, haveEventIDs map[string]bool, async bool,
) error {
outliers := gomatrixserverlib.LineariseStateResponse(event.RoomVersion, state)
ires := make([]InputRoomEvent, 0, len(outliers))
@@ -93,7 +94,7 @@ func SendEventWithState(
// SendInputRoomEvents to the roomserver.
func SendInputRoomEvents(
ctx context.Context, rsAPI InputRoomEventsAPI,
- virtualHost gomatrixserverlib.ServerName,
+ virtualHost spec.ServerName,
ires []InputRoomEvent, async bool,
) error {
request := InputRoomEventsRequest{
@@ -144,7 +145,7 @@ func GetStateEvent(ctx context.Context, rsAPI QueryEventsAPI, roomID string, tup
}
// IsServerBannedFromRoom returns whether the server is banned from a room by server ACLs.
-func IsServerBannedFromRoom(ctx context.Context, rsAPI FederationRoomserverAPI, roomID string, serverName gomatrixserverlib.ServerName) bool {
+func IsServerBannedFromRoom(ctx context.Context, rsAPI FederationRoomserverAPI, roomID string, serverName spec.ServerName) bool {
req := &QueryServerBannedFromRoomRequest{
ServerName: serverName,
RoomID: roomID,
@@ -163,11 +164,11 @@ func IsServerBannedFromRoom(ctx context.Context, rsAPI FederationRoomserverAPI,
func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI QueryBulkStateContentAPI) ([]fclient.PublicRoom, error) {
avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
- canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
+ canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: spec.MRoomCanonicalAlias, StateKey: ""}
topicTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.topic", StateKey: ""}
guestTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.guest_access", StateKey: ""}
- visibilityTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomHistoryVisibility, StateKey: ""}
- joinRuleTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomJoinRules, StateKey: ""}
+ visibilityTuple := gomatrixserverlib.StateKeyTuple{EventType: spec.MRoomHistoryVisibility, StateKey: ""}
+ joinRuleTuple := gomatrixserverlib.StateKeyTuple{EventType: spec.MRoomJoinRules, StateKey: ""}
var stateRes QueryBulkStateContentResponse
err := rsAPI.QueryBulkStateContent(ctx, &QueryBulkStateContentRequest{
@@ -175,7 +176,7 @@ func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI QueryBulkS
AllowWildcards: true,
StateTuples: []gomatrixserverlib.StateKeyTuple{
nameTuple, canonicalTuple, topicTuple, guestTuple, visibilityTuple, joinRuleTuple, avatarTuple,
- {EventType: gomatrixserverlib.MRoomMember, StateKey: "*"},
+ {EventType: spec.MRoomMember, StateKey: "*"},
},
}, &stateRes)
if err != nil {
@@ -191,7 +192,7 @@ func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI QueryBulkS
joinCount := 0
var joinRule, guestAccess string
for tuple, contentVal := range data {
- if tuple.EventType == gomatrixserverlib.MRoomMember && contentVal == "join" {
+ if tuple.EventType == spec.MRoomMember && contentVal == "join" {
joinCount++
continue
}
@@ -215,7 +216,7 @@ func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI QueryBulkS
guestAccess = contentVal
}
}
- if joinRule == gomatrixserverlib.Public && guestAccess == "can_join" {
+ if joinRule == spec.Public && guestAccess == "can_join" {
pub.GuestCanJoin = true
}
pub.JoinedMembersCount = joinCount
diff --git a/roomserver/auth/auth.go b/roomserver/auth/auth.go
index 31a856e8..5f72454a 100644
--- a/roomserver/auth/auth.go
+++ b/roomserver/auth/auth.go
@@ -14,6 +14,7 @@ package auth
import (
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
// TODO: This logic should live in gomatrixserverlib
@@ -21,7 +22,7 @@ import (
// IsServerAllowed returns true if the server is allowed to see events in the room
// at this particular state. This function implements https://matrix.org/docs/spec/client_server/r0.6.0#id87
func IsServerAllowed(
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
serverCurrentlyInRoom bool,
authEvents []*gomatrixserverlib.Event,
) bool {
@@ -32,7 +33,7 @@ func IsServerAllowed(
return true
}
// 2. If the user's membership was join, allow.
- joinedUserExists := IsAnyUserOnServerWithMembership(serverName, authEvents, gomatrixserverlib.Join)
+ joinedUserExists := IsAnyUserOnServerWithMembership(serverName, authEvents, spec.Join)
if joinedUserExists {
return true
}
@@ -41,7 +42,7 @@ func IsServerAllowed(
return true
}
// 4. If the user's membership was invite, and the history_visibility was set to invited, allow.
- invitedUserExists := IsAnyUserOnServerWithMembership(serverName, authEvents, gomatrixserverlib.Invite)
+ invitedUserExists := IsAnyUserOnServerWithMembership(serverName, authEvents, spec.Invite)
if invitedUserExists && historyVisibility == gomatrixserverlib.HistoryVisibilityInvited {
return true
}
@@ -55,7 +56,7 @@ func HistoryVisibilityForRoom(authEvents []*gomatrixserverlib.Event) gomatrixser
// By default if no history_visibility is set, or if the value is not understood, the visibility is assumed to be shared.
visibility := gomatrixserverlib.HistoryVisibilityShared
for _, ev := range authEvents {
- if ev.Type() != gomatrixserverlib.MRoomHistoryVisibility {
+ if ev.Type() != spec.MRoomHistoryVisibility {
continue
}
if vis, err := ev.HistoryVisibility(); err == nil {
@@ -65,9 +66,9 @@ func HistoryVisibilityForRoom(authEvents []*gomatrixserverlib.Event) gomatrixser
return visibility
}
-func IsAnyUserOnServerWithMembership(serverName gomatrixserverlib.ServerName, authEvents []*gomatrixserverlib.Event, wantMembership string) bool {
+func IsAnyUserOnServerWithMembership(serverName spec.ServerName, authEvents []*gomatrixserverlib.Event, wantMembership string) bool {
for _, ev := range authEvents {
- if ev.Type() != gomatrixserverlib.MRoomMember {
+ if ev.Type() != spec.MRoomMember {
continue
}
membership, err := ev.Membership()
diff --git a/roomserver/internal/alias.go b/roomserver/internal/alias.go
index 94b8b16c..46598746 100644
--- a/roomserver/internal/alias.go
+++ b/roomserver/internal/alias.go
@@ -26,6 +26,7 @@ import (
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/internal/helpers"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
@@ -142,7 +143,7 @@ func (r *RoomserverInternalAPI) RemoveRoomAlias(
var plEvent *gomatrixserverlib.HeaderedEvent
var pls *gomatrixserverlib.PowerLevelContent
- plEvent, err = r.DB.GetStateEvent(ctx, roomID, gomatrixserverlib.MRoomPowerLevels, "")
+ plEvent, err = r.DB.GetStateEvent(ctx, roomID, spec.MRoomPowerLevels, "")
if err != nil {
return fmt.Errorf("r.DB.GetStateEvent: %w", err)
}
@@ -152,13 +153,13 @@ func (r *RoomserverInternalAPI) RemoveRoomAlias(
return fmt.Errorf("plEvent.PowerLevels: %w", err)
}
- if pls.UserLevel(request.UserID) < pls.EventLevel(gomatrixserverlib.MRoomCanonicalAlias, true) {
+ if pls.UserLevel(request.UserID) < pls.EventLevel(spec.MRoomCanonicalAlias, true) {
response.Removed = false
return nil
}
}
- ev, err := r.DB.GetStateEvent(ctx, roomID, gomatrixserverlib.MRoomCanonicalAlias, "")
+ ev, err := r.DB.GetStateEvent(ctx, roomID, spec.MRoomCanonicalAlias, "")
if err != nil && err != sql.ErrNoRows {
return err
} else if ev != nil {
diff --git a/roomserver/internal/api.go b/roomserver/internal/api.go
index 47e1bf2f..975e7796 100644
--- a/roomserver/internal/api.go
+++ b/roomserver/internal/api.go
@@ -5,6 +5,7 @@ import (
"github.com/getsentry/sentry-go"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/nats-io/nats.go"
"github.com/sirupsen/logrus"
@@ -43,7 +44,7 @@ type RoomserverInternalAPI struct {
DB storage.Database
Cfg *config.Dendrite
Cache caching.RoomServerCaches
- ServerName gomatrixserverlib.ServerName
+ ServerName spec.ServerName
KeyRing gomatrixserverlib.JSONVerifier
ServerACLs *acls.ServerACLs
fsAPI fsAPI.RoomserverFederationAPI
@@ -53,7 +54,7 @@ type RoomserverInternalAPI struct {
Durable string
InputRoomEventTopic string // JetStream topic for new input room events
OutputProducer *producers.RoomEventProducer
- PerspectiveServerNames []gomatrixserverlib.ServerName
+ PerspectiveServerNames []spec.ServerName
enableMetrics bool
}
@@ -61,7 +62,7 @@ func NewRoomserverAPI(
processContext *process.ProcessContext, dendriteCfg *config.Dendrite, roomserverDB storage.Database,
js nats.JetStreamContext, nc *nats.Conn, caches caching.RoomServerCaches, enableMetrics bool,
) *RoomserverInternalAPI {
- var perspectiveServerNames []gomatrixserverlib.ServerName
+ var perspectiveServerNames []spec.ServerName
for _, kp := range dendriteCfg.FederationAPI.KeyPerspectives {
perspectiveServerNames = append(perspectiveServerNames, kp.ServerName)
}
diff --git a/roomserver/internal/helpers/auth.go b/roomserver/internal/helpers/auth.go
index 9defe794..4ef6e248 100644
--- a/roomserver/internal/helpers/auth.go
+++ b/roomserver/internal/helpers/auth.go
@@ -20,6 +20,7 @@ import (
"sort"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/roomserver/state"
"github.com/matrix-org/dendrite/roomserver/storage"
@@ -59,7 +60,7 @@ func CheckForSoftFail(
// state because we haven't received a m.room.create event yet.
// If we're now processing the first create event then never
// soft-fail it.
- if len(authStateEntries) == 0 && event.Type() == gomatrixserverlib.MRoomCreate {
+ if len(authStateEntries) == 0 && event.Type() == spec.MRoomCreate {
return false, nil
}
diff --git a/roomserver/internal/helpers/helpers.go b/roomserver/internal/helpers/helpers.go
index 9a70bcc9..959f5cf7 100644
--- a/roomserver/internal/helpers/helpers.go
+++ b/roomserver/internal/helpers/helpers.go
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/matrix-org/dendrite/roomserver/api"
@@ -54,7 +55,7 @@ func UpdateToInviteMembership(
Type: api.OutputTypeRetireInviteEvent,
RetireInviteEvent: &api.OutputRetireInviteEvent{
EventID: eventID,
- Membership: gomatrixserverlib.Join,
+ Membership: spec.Join,
RetiredByEventID: add.EventID(),
TargetUserID: *add.StateKey(),
},
@@ -67,7 +68,7 @@ func UpdateToInviteMembership(
// memberships. If the servername is not supplied then the local server will be
// checked instead using a faster code path.
// TODO: This should probably be replaced by an API call.
-func IsServerCurrentlyInRoom(ctx context.Context, db storage.Database, serverName gomatrixserverlib.ServerName, roomID string) (bool, error) {
+func IsServerCurrentlyInRoom(ctx context.Context, db storage.Database, serverName spec.ServerName, roomID string) (bool, error) {
info, err := db.RoomInfo(ctx, roomID)
if err != nil {
return false, err
@@ -93,7 +94,7 @@ func IsServerCurrentlyInRoom(ctx context.Context, db storage.Database, serverNam
for i := range events {
gmslEvents[i] = events[i].Event
}
- return auth.IsAnyUserOnServerWithMembership(serverName, gmslEvents, gomatrixserverlib.Join), nil
+ return auth.IsAnyUserOnServerWithMembership(serverName, gmslEvents, spec.Join), nil
}
func IsInvitePending(
@@ -194,7 +195,7 @@ func GetMembershipsAtState(
return nil, err
}
- if membership == gomatrixserverlib.Join {
+ if membership == spec.Join {
events = append(events, event)
}
}
@@ -252,7 +253,7 @@ func LoadStateEvents(
}
func CheckServerAllowedToSeeEvent(
- ctx context.Context, db storage.Database, info *types.RoomInfo, eventID string, serverName gomatrixserverlib.ServerName, isServerInRoom bool,
+ ctx context.Context, db storage.Database, info *types.RoomInfo, eventID string, serverName spec.ServerName, isServerInRoom bool,
) (bool, error) {
stateAtEvent, err := db.GetHistoryVisibilityState(ctx, info, eventID, string(serverName))
switch err {
@@ -280,7 +281,7 @@ func CheckServerAllowedToSeeEvent(
}
func slowGetHistoryVisibilityState(
- ctx context.Context, db storage.Database, info *types.RoomInfo, eventID string, serverName gomatrixserverlib.ServerName,
+ ctx context.Context, db storage.Database, info *types.RoomInfo, eventID string, serverName spec.ServerName,
) ([]*gomatrixserverlib.Event, error) {
roomState := state.NewStateResolution(db, info)
stateEntries, err := roomState.LoadStateAtEvent(ctx, eventID)
@@ -332,7 +333,7 @@ func slowGetHistoryVisibilityState(
// TODO: Remove this when we have tests to assert correctness of this function
func ScanEventTree(
ctx context.Context, db storage.Database, info *types.RoomInfo, front []string, visited map[string]bool, limit int,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
) ([]types.EventNID, map[string]struct{}, error) {
var resultNIDs []types.EventNID
var err error
diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go
index 83aa9e90..3e7ff7f7 100644
--- a/roomserver/internal/input/input.go
+++ b/roomserver/internal/input/input.go
@@ -25,6 +25,7 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/Arceliar/phony"
"github.com/getsentry/sentry-go"
@@ -79,7 +80,7 @@ type Inputer struct {
NATSClient *nats.Conn
JetStream nats.JetStreamContext
Durable nats.SubOpt
- ServerName gomatrixserverlib.ServerName
+ ServerName spec.ServerName
SigningIdentity *fclient.SigningIdentity
FSAPI fedapi.RoomserverFederationAPI
KeyRing gomatrixserverlib.JSONVerifier
@@ -284,7 +285,7 @@ func (w *worker) _next() {
var errString string
if err = w.r.processRoomEvent(
w.r.ProcessContext.Context(),
- gomatrixserverlib.ServerName(msg.Header.Get("virtual_host")),
+ spec.ServerName(msg.Header.Get("virtual_host")),
&inputRoomEvent,
); err != nil {
switch err.(type) {
diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go
index 971befa0..334e68b9 100644
--- a/roomserver/internal/input/input_events.go
+++ b/roomserver/internal/input/input_events.go
@@ -28,6 +28,7 @@ import (
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
@@ -73,7 +74,7 @@ var processRoomEventDuration = prometheus.NewHistogramVec(
// nolint:gocyclo
func (r *Inputer) processRoomEvent(
ctx context.Context,
- virtualHost gomatrixserverlib.ServerName,
+ virtualHost spec.ServerName,
input *api.InputRoomEvent,
) error {
select {
@@ -123,7 +124,7 @@ func (r *Inputer) processRoomEvent(
if rerr != nil {
return fmt.Errorf("r.DB.RoomInfo: %w", rerr)
}
- isCreateEvent := event.Type() == gomatrixserverlib.MRoomCreate && event.StateKeyEquals("")
+ isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
if roomInfo == nil && !isCreateEvent {
return fmt.Errorf("room %s does not exist for event %s", event.RoomID(), event.EventID())
}
@@ -180,7 +181,7 @@ func (r *Inputer) processRoomEvent(
// Sort all of the servers into a map so that we can randomise
// their order. Then make sure that the input origin and the
// event origin are first on the list.
- servers := map[gomatrixserverlib.ServerName]struct{}{}
+ servers := map[spec.ServerName]struct{}{}
for _, server := range serverRes.ServerNames {
servers[server] = struct{}{}
}
@@ -476,7 +477,7 @@ func (r *Inputer) processRoomEvent(
}
// If guest_access changed and is not can_join, kick all guest users.
- if event.Type() == gomatrixserverlib.MRoomGuestAccess && gjson.GetBytes(event.Content(), "guest_access").Str != "can_join" {
+ if event.Type() == spec.MRoomGuestAccess && gjson.GetBytes(event.Content(), "guest_access").Str != "can_join" {
if err = r.kickGuests(ctx, event, roomInfo); err != nil {
logrus.WithError(err).Error("failed to kick guest users on m.room.guest_access revocation")
}
@@ -509,7 +510,7 @@ func (r *Inputer) processStateBefore(
) (historyVisibility gomatrixserverlib.HistoryVisibility, rejectionErr error, err error) {
historyVisibility = gomatrixserverlib.HistoryVisibilityShared // Default to shared.
event := input.Event.Unwrap()
- isCreateEvent := event.Type() == gomatrixserverlib.MRoomCreate && event.StateKeyEquals("")
+ isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
var stateBeforeEvent []*gomatrixserverlib.Event
switch {
case isCreateEvent:
@@ -546,7 +547,7 @@ func (r *Inputer) processStateBefore(
// output events.
tuplesNeeded := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{event}).Tuples()
tuplesNeeded = append(tuplesNeeded, gomatrixserverlib.StateKeyTuple{
- EventType: gomatrixserverlib.MRoomHistoryVisibility,
+ EventType: spec.MRoomHistoryVisibility,
StateKey: "",
})
stateBeforeReq := &api.QueryStateAfterEventsRequest{
@@ -579,7 +580,7 @@ func (r *Inputer) processStateBefore(
// Work out what the history visibility was at the time of the
// event.
for _, event := range stateBeforeEvent {
- if event.Type() != gomatrixserverlib.MRoomHistoryVisibility || !event.StateKeyEquals("") {
+ if event.Type() != spec.MRoomHistoryVisibility || !event.StateKeyEquals("") {
continue
}
if hisVis, err := event.HistoryVisibility(); err == nil {
@@ -602,11 +603,11 @@ func (r *Inputer) fetchAuthEvents(
ctx context.Context,
logger *logrus.Entry,
roomInfo *types.RoomInfo,
- virtualHost gomatrixserverlib.ServerName,
+ virtualHost spec.ServerName,
event *gomatrixserverlib.HeaderedEvent,
auth *gomatrixserverlib.AuthEvents,
known map[string]*types.Event,
- servers []gomatrixserverlib.ServerName,
+ servers []spec.ServerName,
) error {
trace, ctx := internal.StartRegion(ctx, "fetchAuthEvents")
defer trace.EndRegion()
@@ -842,12 +843,12 @@ func (r *Inputer) kickGuests(ctx context.Context, event *gomatrixserverlib.Event
if err = json.Unmarshal(memberEvent.Content(), &memberContent); err != nil {
return err
}
- memberContent.Membership = gomatrixserverlib.Leave
+ memberContent.Membership = spec.Leave
stateKey := *memberEvent.StateKey()
fledglingEvent := &gomatrixserverlib.EventBuilder{
RoomID: event.RoomID(),
- Type: gomatrixserverlib.MRoomMember,
+ Type: spec.MRoomMember,
StateKey: &stateKey,
Sender: stateKey,
PrevEvents: prevEvents,
diff --git a/roomserver/internal/input/input_events_test.go b/roomserver/internal/input/input_events_test.go
index 818e7715..9acc435b 100644
--- a/roomserver/internal/input/input_events_test.go
+++ b/roomserver/internal/input/input_events_test.go
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/test"
)
@@ -21,15 +22,15 @@ func Test_EventAuth(t *testing.T) {
// Add the legal auth events from room2
for _, x := range room2.Events() {
- if x.Type() == gomatrixserverlib.MRoomCreate {
+ if x.Type() == spec.MRoomCreate {
authEventIDs = append(authEventIDs, x.EventID())
authEvents = append(authEvents, x.Event)
}
- if x.Type() == gomatrixserverlib.MRoomPowerLevels {
+ if x.Type() == spec.MRoomPowerLevels {
authEventIDs = append(authEventIDs, x.EventID())
authEvents = append(authEvents, x.Event)
}
- if x.Type() == gomatrixserverlib.MRoomJoinRules {
+ if x.Type() == spec.MRoomJoinRules {
authEventIDs = append(authEventIDs, x.EventID())
authEvents = append(authEvents, x.Event)
}
@@ -37,7 +38,7 @@ func Test_EventAuth(t *testing.T) {
// Add the illegal auth event from room1 (rooms are different)
for _, x := range room1.Events() {
- if x.Type() == gomatrixserverlib.MRoomMember {
+ if x.Type() == spec.MRoomMember {
authEventIDs = append(authEventIDs, x.EventID())
authEvents = append(authEvents, x.Event)
}
diff --git a/roomserver/internal/input/input_membership.go b/roomserver/internal/input/input_membership.go
index 4028f0b5..947f6c15 100644
--- a/roomserver/internal/input/input_membership.go
+++ b/roomserver/internal/input/input_membership.go
@@ -19,6 +19,7 @@ import (
"fmt"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/roomserver/api"
@@ -86,7 +87,7 @@ func (r *Inputer) updateMembership(
) ([]api.OutputEvent, error) {
var err error
// Default the membership to Leave if no event was added or removed.
- newMembership := gomatrixserverlib.Leave
+ newMembership := spec.Leave
if add != nil {
newMembership, err = add.Membership()
if err != nil {
@@ -120,13 +121,13 @@ func (r *Inputer) updateMembership(
}
switch newMembership {
- case gomatrixserverlib.Invite:
+ case spec.Invite:
return helpers.UpdateToInviteMembership(mu, add, updates, updater.RoomVersion())
- case gomatrixserverlib.Join:
+ case spec.Join:
return updateToJoinMembership(mu, add, updates)
- case gomatrixserverlib.Leave, gomatrixserverlib.Ban:
+ case spec.Leave, spec.Ban:
return updateToLeaveMembership(mu, add, newMembership, updates)
- case gomatrixserverlib.Knock:
+ case spec.Knock:
return updateToKnockMembership(mu, add, updates)
default:
panic(fmt.Errorf(
@@ -160,7 +161,7 @@ func updateToJoinMembership(
Type: api.OutputTypeRetireInviteEvent,
RetireInviteEvent: &api.OutputRetireInviteEvent{
EventID: eventID,
- Membership: gomatrixserverlib.Join,
+ Membership: spec.Join,
RetiredByEventID: add.EventID(),
TargetUserID: *add.StateKey(),
},
diff --git a/roomserver/internal/input/input_missing.go b/roomserver/internal/input/input_missing.go
index 16bc18d8..c7b64797 100644
--- a/roomserver/internal/input/input_missing.go
+++ b/roomserver/internal/input/input_missing.go
@@ -9,6 +9,7 @@ import (
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
@@ -42,15 +43,15 @@ func (p *parsedRespState) Events() []*gomatrixserverlib.Event {
type missingStateReq struct {
log *logrus.Entry
- virtualHost gomatrixserverlib.ServerName
- origin gomatrixserverlib.ServerName
+ virtualHost spec.ServerName
+ origin spec.ServerName
db storage.RoomDatabase
roomInfo *types.RoomInfo
inputer *Inputer
keys gomatrixserverlib.JSONVerifier
federation fedapi.RoomserverFederationAPI
roomsMu *internal.MutexByRoom
- servers []gomatrixserverlib.ServerName
+ servers []spec.ServerName
hadEvents map[string]bool
hadEventsMutex sync.Mutex
haveEvents map[string]*gomatrixserverlib.Event
@@ -279,7 +280,7 @@ func (t *missingStateReq) lookupResolvedStateBeforeEvent(ctx context.Context, e
resolvedState := &parsedRespState{}
switch len(states) {
case 0:
- extremityIsCreate := e.Type() == gomatrixserverlib.MRoomCreate && e.StateKeyEquals("")
+ extremityIsCreate := e.Type() == spec.MRoomCreate && e.StateKeyEquals("")
if !extremityIsCreate {
// There are no previous states and this isn't the beginning of the
// room - this is an error condition!
@@ -291,7 +292,7 @@ func (t *missingStateReq) lookupResolvedStateBeforeEvent(ctx context.Context, e
// use it as-is. There's no point in resolving it again. Only trust a
// trustworthy state snapshot if it actually contains some state for all
// non-create events, otherwise we need to resolve what came from federation.
- isCreate := e.Type() == gomatrixserverlib.MRoomCreate && e.StateKeyEquals("")
+ isCreate := e.Type() == spec.MRoomCreate && e.StateKeyEquals("")
if states[0].trustworthy && (isCreate || len(states[0].StateEvents) > 0) {
resolvedState = states[0].parsedRespState
break
@@ -597,7 +598,7 @@ Event:
// If we retrieved back to the beginning of the room then there's nothing else
// to do - we closed the gap.
- if len(earliestNewEvent.PrevEventIDs()) == 0 && earliestNewEvent.Type() == gomatrixserverlib.MRoomCreate && earliestNewEvent.StateKeyEquals("") {
+ if len(earliestNewEvent.PrevEventIDs()) == 0 && earliestNewEvent.Type() == spec.MRoomCreate && earliestNewEvent.StateKeyEquals("") {
return newEvents, true, t.isPrevStateKnown(ctx, e), nil
}
diff --git a/roomserver/internal/perform/perform_admin.go b/roomserver/internal/perform/perform_admin.go
index f35e40bc..e7b9db1f 100644
--- a/roomserver/internal/perform/perform_admin.go
+++ b/roomserver/internal/perform/perform_admin.go
@@ -28,6 +28,7 @@ import (
"github.com/matrix-org/dendrite/roomserver/storage"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/sirupsen/logrus"
)
@@ -107,12 +108,12 @@ func (r *Admin) PerformAdminEvacuateRoom(
}
return nil
}
- memberContent.Membership = gomatrixserverlib.Leave
+ memberContent.Membership = spec.Leave
stateKey := *memberEvent.StateKey()
fledglingEvent := &gomatrixserverlib.EventBuilder{
RoomID: req.RoomID,
- Type: gomatrixserverlib.MRoomMember,
+ Type: spec.MRoomMember,
StateKey: &stateKey,
Sender: stateKey,
PrevEvents: prevEvents,
@@ -195,7 +196,7 @@ func (r *Admin) PerformAdminEvacuateUser(
return nil
}
- roomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Join)
+ roomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, spec.Join)
if err != nil && err != sql.ErrNoRows {
res.Error = &api.PerformError{
Code: api.PerformErrorBadRequest,
@@ -204,7 +205,7 @@ func (r *Admin) PerformAdminEvacuateUser(
return nil
}
- inviteRoomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, gomatrixserverlib.Invite)
+ inviteRoomIDs, err := r.DB.GetRoomsByMembership(ctx, req.UserID, spec.Invite)
if err != nil && err != sql.ErrNoRows {
res.Error = &api.PerformError{
Code: api.PerformErrorBadRequest,
@@ -361,7 +362,7 @@ func (r *Admin) PerformAdminDownloadState(
Type: "org.matrix.dendrite.state_download",
Sender: req.UserID,
RoomID: req.RoomID,
- Content: gomatrixserverlib.RawJSON("{}"),
+ Content: spec.RawJSON("{}"),
}
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder)
diff --git a/roomserver/internal/perform/perform_backfill.go b/roomserver/internal/perform/perform_backfill.go
index 23862b24..d9a2394a 100644
--- a/roomserver/internal/perform/perform_backfill.go
+++ b/roomserver/internal/perform/perform_backfill.go
@@ -19,6 +19,7 @@ import (
"fmt"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
@@ -37,13 +38,13 @@ import (
const maxBackfillServers = 5
type Backfiller struct {
- IsLocalServerName func(gomatrixserverlib.ServerName) bool
+ IsLocalServerName func(spec.ServerName) bool
DB storage.Database
FSAPI federationAPI.RoomserverFederationAPI
KeyRing gomatrixserverlib.JSONVerifier
// The servers which should be preferred above other servers when backfilling
- PreferServers []gomatrixserverlib.ServerName
+ PreferServers []spec.ServerName
}
// PerformBackfill implements api.RoomServerQueryAPI
@@ -175,7 +176,7 @@ func (r *Backfiller) backfillViaFederation(ctx context.Context, req *api.Perform
// fetchAndStoreMissingEvents does a best-effort fetch and store of missing events specified in stateIDs. Returns no error as it is just
// best effort.
func (r *Backfiller) fetchAndStoreMissingEvents(ctx context.Context, roomVer gomatrixserverlib.RoomVersion,
- backfillRequester *backfillRequester, stateIDs []string, virtualHost gomatrixserverlib.ServerName) {
+ backfillRequester *backfillRequester, stateIDs []string, virtualHost spec.ServerName) {
servers := backfillRequester.servers
@@ -245,13 +246,13 @@ func (r *Backfiller) fetchAndStoreMissingEvents(ctx context.Context, roomVer gom
type backfillRequester struct {
db storage.Database
fsAPI federationAPI.RoomserverFederationAPI
- virtualHost gomatrixserverlib.ServerName
- isLocalServerName func(gomatrixserverlib.ServerName) bool
- preferServer map[gomatrixserverlib.ServerName]bool
+ virtualHost spec.ServerName
+ isLocalServerName func(spec.ServerName) bool
+ preferServer map[spec.ServerName]bool
bwExtrems map[string][]string
// per-request state
- servers []gomatrixserverlib.ServerName
+ servers []spec.ServerName
eventIDToBeforeStateIDs map[string][]string
eventIDMap map[string]*gomatrixserverlib.Event
historyVisiblity gomatrixserverlib.HistoryVisibility
@@ -260,11 +261,11 @@ type backfillRequester struct {
func newBackfillRequester(
db storage.Database, fsAPI federationAPI.RoomserverFederationAPI,
- virtualHost gomatrixserverlib.ServerName,
- isLocalServerName func(gomatrixserverlib.ServerName) bool,
- bwExtrems map[string][]string, preferServers []gomatrixserverlib.ServerName,
+ virtualHost spec.ServerName,
+ isLocalServerName func(spec.ServerName) bool,
+ bwExtrems map[string][]string, preferServers []spec.ServerName,
) *backfillRequester {
- preferServer := make(map[gomatrixserverlib.ServerName]bool)
+ preferServer := make(map[spec.ServerName]bool)
for _, p := range preferServers {
preferServer[p] = true
}
@@ -415,7 +416,7 @@ func (b *backfillRequester) StateBeforeEvent(ctx context.Context, roomVer gomatr
// It returns a list of servers which can be queried for backfill requests. These servers
// will be servers that are in the room already. The entries at the beginning are preferred servers
// and will be tried first. An empty list will fail the request.
-func (b *backfillRequester) ServersAtEvent(ctx context.Context, roomID, eventID string) []gomatrixserverlib.ServerName {
+func (b *backfillRequester) ServersAtEvent(ctx context.Context, roomID, eventID string) []spec.ServerName {
// eventID will be a prev_event ID of a backwards extremity, meaning we will not have a database entry for it. Instead, use
// its successor, so look it up.
successor := ""
@@ -478,19 +479,19 @@ FindSuccessor:
memberEvents = append(memberEvents, memberEventsFromVis...)
// Store the server names in a temporary map to avoid duplicates.
- serverSet := make(map[gomatrixserverlib.ServerName]bool)
+ serverSet := make(map[spec.ServerName]bool)
for _, event := range memberEvents {
if _, senderDomain, err := gomatrixserverlib.SplitID('@', event.Sender()); err == nil {
serverSet[senderDomain] = true
}
}
- var servers []gomatrixserverlib.ServerName
+ var servers []spec.ServerName
for server := range serverSet {
if b.isLocalServerName(server) {
continue
}
if b.preferServer[server] { // insert at the front
- servers = append([]gomatrixserverlib.ServerName{server}, servers...)
+ servers = append([]spec.ServerName{server}, servers...)
} else { // insert at the back
servers = append(servers, server)
}
@@ -505,7 +506,7 @@ FindSuccessor:
// Backfill performs a backfill request to the given server.
// https://matrix.org/docs/spec/server_server/latest#get-matrix-federation-v1-backfill-roomid
-func (b *backfillRequester) Backfill(ctx context.Context, origin, server gomatrixserverlib.ServerName, roomID string,
+func (b *backfillRequester) Backfill(ctx context.Context, origin, server spec.ServerName, roomID string,
limit int, fromEventIDs []string) (gomatrixserverlib.Transaction, error) {
tx, err := b.fsAPI.Backfill(ctx, origin, server, roomID, limit, fromEventIDs)
@@ -547,7 +548,7 @@ func (b *backfillRequester) ProvideEvents(roomVer gomatrixserverlib.RoomVersion,
// pull all events and then filter by that table.
func joinEventsFromHistoryVisibility(
ctx context.Context, db storage.RoomDatabase, roomInfo *types.RoomInfo, stateEntries []types.StateEntry,
- thisServer gomatrixserverlib.ServerName) ([]types.Event, gomatrixserverlib.HistoryVisibility, error) {
+ thisServer spec.ServerName) ([]types.Event, gomatrixserverlib.HistoryVisibility, error) {
var eventNIDs []types.EventNID
for _, entry := range stateEntries {
diff --git a/roomserver/internal/perform/perform_invite.go b/roomserver/internal/perform/perform_invite.go
index 13d13f7b..a23cdea1 100644
--- a/roomserver/internal/perform/perform_invite.go
+++ b/roomserver/internal/perform/perform_invite.go
@@ -28,6 +28,8 @@ import (
"github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/fclient"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
log "github.com/sirupsen/logrus"
)
@@ -95,7 +97,7 @@ func (r *Inviter) PerformInvite(
inviteState := req.InviteRoomState
if len(inviteState) == 0 && info != nil {
- var is []gomatrixserverlib.InviteV2StrippedState
+ var is []fclient.InviteV2StrippedState
if is, err = buildInviteStrippedState(ctx, r.DB, info, req); err == nil {
inviteState = is
}
@@ -266,14 +268,14 @@ func buildInviteStrippedState(
db storage.Database,
info *types.RoomInfo,
input *api.PerformInviteRequest,
-) ([]gomatrixserverlib.InviteV2StrippedState, error) {
+) ([]fclient.InviteV2StrippedState, error) {
stateWanted := []gomatrixserverlib.StateKeyTuple{}
// "If they are set on the room, at least the state for m.room.avatar, m.room.canonical_alias, m.room.join_rules, and m.room.name SHOULD be included."
// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-member
for _, t := range []string{
- gomatrixserverlib.MRoomName, gomatrixserverlib.MRoomCanonicalAlias,
- gomatrixserverlib.MRoomJoinRules, gomatrixserverlib.MRoomAvatar,
- gomatrixserverlib.MRoomEncryption, gomatrixserverlib.MRoomCreate,
+ spec.MRoomName, spec.MRoomCanonicalAlias,
+ spec.MRoomJoinRules, spec.MRoomAvatar,
+ spec.MRoomEncryption, spec.MRoomCreate,
} {
stateWanted = append(stateWanted, gomatrixserverlib.StateKeyTuple{
EventType: t,
@@ -295,12 +297,12 @@ func buildInviteStrippedState(
if err != nil {
return nil, err
}
- inviteState := []gomatrixserverlib.InviteV2StrippedState{
- gomatrixserverlib.NewInviteV2StrippedState(input.Event.Event),
+ inviteState := []fclient.InviteV2StrippedState{
+ fclient.NewInviteV2StrippedState(input.Event.Event),
}
stateEvents = append(stateEvents, types.Event{Event: input.Event.Unwrap()})
for _, event := range stateEvents {
- inviteState = append(inviteState, gomatrixserverlib.NewInviteV2StrippedState(event.Event))
+ inviteState = append(inviteState, fclient.NewInviteV2StrippedState(event.Event))
}
return inviteState, nil
}
diff --git a/roomserver/internal/perform/perform_join.go b/roomserver/internal/perform/perform_join.go
index 02383a45..9b0895e9 100644
--- a/roomserver/internal/perform/perform_join.go
+++ b/roomserver/internal/perform/perform_join.go
@@ -24,6 +24,7 @@ import (
"github.com/getsentry/sentry-go"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
@@ -83,7 +84,7 @@ func (r *Joiner) PerformJoin(
func (r *Joiner) performJoin(
ctx context.Context,
req *rsAPI.PerformJoinRequest,
-) (string, gomatrixserverlib.ServerName, error) {
+) (string, spec.ServerName, error) {
_, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
if err != nil {
return "", "", &rsAPI.PerformError{
@@ -112,7 +113,7 @@ func (r *Joiner) performJoin(
func (r *Joiner) performJoinRoomByAlias(
ctx context.Context,
req *rsAPI.PerformJoinRequest,
-) (string, gomatrixserverlib.ServerName, error) {
+) (string, spec.ServerName, error) {
// Get the domain part of the room alias.
_, domain, err := gomatrixserverlib.SplitID('#', req.RoomIDOrAlias)
if err != nil {
@@ -167,7 +168,7 @@ func (r *Joiner) performJoinRoomByAlias(
func (r *Joiner) performJoinRoomByID(
ctx context.Context,
req *rsAPI.PerformJoinRequest,
-) (string, gomatrixserverlib.ServerName, error) {
+) (string, spec.ServerName, error) {
// The original client request ?server_name=... may include this HS so filter that out so we
// don't attempt to make_join with ourselves
for i := 0; i < len(req.ServerNames); i++ {
@@ -204,7 +205,7 @@ func (r *Joiner) performJoinRoomByID(
}
}
eb := gomatrixserverlib.EventBuilder{
- Type: gomatrixserverlib.MRoomMember,
+ Type: spec.MRoomMember,
Sender: userID,
StateKey: &userID,
RoomID: req.RoomIDOrAlias,
@@ -220,7 +221,7 @@ func (r *Joiner) performJoinRoomByID(
if req.Content == nil {
req.Content = map[string]interface{}{}
}
- req.Content["membership"] = gomatrixserverlib.Join
+ req.Content["membership"] = spec.Join
if authorisedVia, aerr := r.populateAuthorisedViaUserForRestrictedJoin(ctx, req); aerr != nil {
return "", "", aerr
} else if authorisedVia != "" {
@@ -274,7 +275,7 @@ func (r *Joiner) performJoinRoomByID(
if req.IsGuest {
var guestAccessEvent *gomatrixserverlib.HeaderedEvent
guestAccess := "forbidden"
- guestAccessEvent, err = r.DB.GetStateEvent(ctx, req.RoomIDOrAlias, gomatrixserverlib.MRoomGuestAccess, "")
+ guestAccessEvent, err = r.DB.GetStateEvent(ctx, req.RoomIDOrAlias, spec.MRoomGuestAccess, "")
if (err != nil && !errors.Is(err, sql.ErrNoRows)) || guestAccessEvent == nil {
logrus.WithError(err).Warn("unable to get m.room.guest_access event, defaulting to 'forbidden'")
}
@@ -293,7 +294,7 @@ func (r *Joiner) performJoinRoomByID(
}
// If we should do a forced federated join then do that.
- var joinedVia gomatrixserverlib.ServerName
+ var joinedVia spec.ServerName
if forceFederatedJoin {
joinedVia, err = r.performFederatedJoinRoomByID(ctx, req)
return req.RoomIDOrAlias, joinedVia, err
@@ -388,7 +389,7 @@ func (r *Joiner) performJoinRoomByID(
func (r *Joiner) performFederatedJoinRoomByID(
ctx context.Context,
req *rsAPI.PerformJoinRequest,
-) (gomatrixserverlib.ServerName, error) {
+) (spec.ServerName, error) {
// Try joining by all of the supplied server names.
fedReq := fsAPI.PerformJoinRequest{
RoomID: req.RoomIDOrAlias, // the room ID to try and join
diff --git a/roomserver/internal/perform/perform_leave.go b/roomserver/internal/perform/perform_leave.go
index 00b6c50c..4dfb522a 100644
--- a/roomserver/internal/perform/perform_leave.go
+++ b/roomserver/internal/perform/perform_leave.go
@@ -25,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
@@ -126,7 +127,7 @@ func (r *Leaver) performLeaveRoomByID(
RoomID: req.RoomID,
StateToFetch: []gomatrixserverlib.StateKeyTuple{
{
- EventType: gomatrixserverlib.MRoomMember,
+ EventType: spec.MRoomMember,
StateKey: req.UserID,
},
},
@@ -147,14 +148,14 @@ func (r *Leaver) performLeaveRoomByID(
if err != nil {
return nil, fmt.Errorf("error getting membership: %w", err)
}
- if membership != gomatrixserverlib.Join && membership != gomatrixserverlib.Invite {
+ if membership != spec.Join && membership != spec.Invite {
return nil, fmt.Errorf("user %q is not joined to the room (membership is %q)", req.UserID, membership)
}
// Prepare the template for the leave event.
userID := req.UserID
eb := gomatrixserverlib.EventBuilder{
- Type: gomatrixserverlib.MRoomMember,
+ Type: spec.MRoomMember,
Sender: userID,
StateKey: &userID,
RoomID: req.RoomID,
@@ -227,7 +228,7 @@ func (r *Leaver) performFederatedRejectInvite(
leaveReq := fsAPI.PerformLeaveRequest{
RoomID: req.RoomID,
UserID: req.UserID,
- ServerNames: []gomatrixserverlib.ServerName{domain},
+ ServerNames: []spec.ServerName{domain},
}
leaveRes := fsAPI.PerformLeaveResponse{}
if err = r.FSAPI.PerformLeave(ctx, &leaveReq, &leaveRes); err != nil {
diff --git a/roomserver/internal/perform/perform_peek.go b/roomserver/internal/perform/perform_peek.go
index 436d137f..2f39050d 100644
--- a/roomserver/internal/perform/perform_peek.go
+++ b/roomserver/internal/perform/perform_peek.go
@@ -26,12 +26,13 @@ import (
"github.com/matrix-org/dendrite/roomserver/storage"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
)
type Peeker struct {
- ServerName gomatrixserverlib.ServerName
+ ServerName spec.ServerName
Cfg *config.RoomServer
FSAPI fsAPI.RoomserverFederationAPI
DB storage.Database
diff --git a/roomserver/internal/perform/perform_unpeek.go b/roomserver/internal/perform/perform_unpeek.go
index 4d714be6..28486fa1 100644
--- a/roomserver/internal/perform/perform_unpeek.go
+++ b/roomserver/internal/perform/perform_unpeek.go
@@ -24,10 +24,11 @@ import (
"github.com/matrix-org/dendrite/roomserver/internal/input"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type Unpeeker struct {
- ServerName gomatrixserverlib.ServerName
+ ServerName spec.ServerName
Cfg *config.RoomServer
FSAPI fsAPI.RoomserverFederationAPI
Inputer *input.Inputer
diff --git a/roomserver/internal/perform/perform_upgrade.go b/roomserver/internal/perform/perform_upgrade.go
index b739b067..ed57abf2 100644
--- a/roomserver/internal/perform/perform_upgrade.go
+++ b/roomserver/internal/perform/perform_upgrade.go
@@ -24,6 +24,7 @@ import (
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
)
@@ -148,7 +149,7 @@ func (r *Upgrader) performRoomUpgrade(
func (r *Upgrader) getRoomPowerLevels(ctx context.Context, roomID string) (*gomatrixserverlib.PowerLevelContent, *api.PerformError) {
oldPowerLevelsEvent := api.GetStateEvent(ctx, r.URSAPI, roomID, gomatrixserverlib.StateKeyTuple{
- EventType: gomatrixserverlib.MRoomPowerLevels,
+ EventType: spec.MRoomPowerLevels,
StateKey: "",
})
powerLevelContent, err := oldPowerLevelsEvent.PowerLevels()
@@ -161,7 +162,7 @@ func (r *Upgrader) getRoomPowerLevels(ctx context.Context, roomID string) (*goma
return powerLevelContent, nil
}
-func (r *Upgrader) restrictOldRoomPowerLevels(ctx context.Context, evTime time.Time, userID string, userDomain gomatrixserverlib.ServerName, roomID string) *api.PerformError {
+func (r *Upgrader) restrictOldRoomPowerLevels(ctx context.Context, evTime time.Time, userID string, userDomain spec.ServerName, roomID string) *api.PerformError {
restrictedPowerLevelContent, pErr := r.getRoomPowerLevels(ctx, roomID)
if pErr != nil {
return pErr
@@ -179,7 +180,7 @@ func (r *Upgrader) restrictOldRoomPowerLevels(ctx context.Context, evTime time.T
restrictedPowerLevelContent.Invite = restrictedDefaultPowerLevel
restrictedPowerLevelsHeadered, resErr := r.makeHeaderedEvent(ctx, evTime, userID, roomID, fledglingEvent{
- Type: gomatrixserverlib.MRoomPowerLevels,
+ Type: spec.MRoomPowerLevels,
StateKey: "",
Content: restrictedPowerLevelContent,
})
@@ -230,9 +231,9 @@ func moveLocalAliases(ctx context.Context,
return nil
}
-func (r *Upgrader) clearOldCanonicalAliasEvent(ctx context.Context, oldRoom *api.QueryLatestEventsAndStateResponse, evTime time.Time, userID string, userDomain gomatrixserverlib.ServerName, roomID string) *api.PerformError {
+func (r *Upgrader) clearOldCanonicalAliasEvent(ctx context.Context, oldRoom *api.QueryLatestEventsAndStateResponse, evTime time.Time, userID string, userDomain spec.ServerName, roomID string) *api.PerformError {
for _, event := range oldRoom.StateEvents {
- if event.Type() != gomatrixserverlib.MRoomCanonicalAlias || !event.StateKeyEquals("") {
+ if event.Type() != spec.MRoomCanonicalAlias || !event.StateKeyEquals("") {
continue
}
var aliasContent struct {
@@ -251,7 +252,7 @@ func (r *Upgrader) clearOldCanonicalAliasEvent(ctx context.Context, oldRoom *api
}
emptyCanonicalAliasEvent, resErr := r.makeHeaderedEvent(ctx, evTime, userID, roomID, fledglingEvent{
- Type: gomatrixserverlib.MRoomCanonicalAlias,
+ Type: spec.MRoomCanonicalAlias,
Content: map[string]interface{}{},
})
if resErr != nil {
@@ -332,7 +333,7 @@ func (r *Upgrader) validateRoomExists(ctx context.Context, roomID string) error
func (r *Upgrader) userIsAuthorized(ctx context.Context, userID, roomID string,
) bool {
plEvent := api.GetStateEvent(ctx, r.URSAPI, roomID, gomatrixserverlib.StateKeyTuple{
- EventType: gomatrixserverlib.MRoomPowerLevels,
+ EventType: spec.MRoomPowerLevels,
StateKey: "",
})
if plEvent == nil {
@@ -355,7 +356,7 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
// This shouldn't ever happen, but better to be safe than sorry.
continue
}
- if event.Type() == gomatrixserverlib.MRoomMember && !event.StateKeyEquals(userID) {
+ if event.Type() == spec.MRoomMember && !event.StateKeyEquals(userID) {
// With the exception of bans and invites which we do want to copy, we
// should ignore membership events that aren't our own, as event auth will
// prevent us from being able to create membership events on behalf of other
@@ -365,8 +366,8 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
continue
}
switch membership {
- case gomatrixserverlib.Ban:
- case gomatrixserverlib.Invite:
+ case spec.Ban:
+ case spec.Invite:
default:
continue
}
@@ -377,10 +378,10 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
// The following events are ones that we are going to override manually
// in the following section.
override := map[gomatrixserverlib.StateKeyTuple]struct{}{
- {EventType: gomatrixserverlib.MRoomCreate, StateKey: ""}: {},
- {EventType: gomatrixserverlib.MRoomMember, StateKey: userID}: {},
- {EventType: gomatrixserverlib.MRoomPowerLevels, StateKey: ""}: {},
- {EventType: gomatrixserverlib.MRoomJoinRules, StateKey: ""}: {},
+ {EventType: spec.MRoomCreate, StateKey: ""}: {},
+ {EventType: spec.MRoomMember, StateKey: userID}: {},
+ {EventType: spec.MRoomPowerLevels, StateKey: ""}: {},
+ {EventType: spec.MRoomJoinRules, StateKey: ""}: {},
}
// The overridden events are essential events that must be present in the
@@ -393,10 +394,10 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
}
}
- oldCreateEvent := state[gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCreate, StateKey: ""}]
- oldMembershipEvent := state[gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomMember, StateKey: userID}]
- oldPowerLevelsEvent := state[gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomPowerLevels, StateKey: ""}]
- oldJoinRulesEvent := state[gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomJoinRules, StateKey: ""}]
+ oldCreateEvent := state[gomatrixserverlib.StateKeyTuple{EventType: spec.MRoomCreate, StateKey: ""}]
+ oldMembershipEvent := state[gomatrixserverlib.StateKeyTuple{EventType: spec.MRoomMember, StateKey: userID}]
+ oldPowerLevelsEvent := state[gomatrixserverlib.StateKeyTuple{EventType: spec.MRoomPowerLevels, StateKey: ""}]
+ oldJoinRulesEvent := state[gomatrixserverlib.StateKeyTuple{EventType: spec.MRoomJoinRules, StateKey: ""}]
// Create the new room create event. Using a map here instead of CreateContent
// means that we preserve any other interesting fields that might be present
@@ -410,7 +411,7 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
RoomID: roomID,
}
newCreateEvent := fledglingEvent{
- Type: gomatrixserverlib.MRoomCreate,
+ Type: spec.MRoomCreate,
StateKey: "",
Content: newCreateContent,
}
@@ -421,9 +422,9 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
// the events after it.
newMembershipContent := map[string]interface{}{}
_ = json.Unmarshal(oldMembershipEvent.Content(), &newMembershipContent)
- newMembershipContent["membership"] = gomatrixserverlib.Join
+ newMembershipContent["membership"] = spec.Join
newMembershipEvent := fledglingEvent{
- Type: gomatrixserverlib.MRoomMember,
+ Type: spec.MRoomMember,
StateKey: userID,
Content: newMembershipContent,
}
@@ -447,11 +448,11 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
// existing join rules contains garbage, the room can still be
// upgraded.
newJoinRulesContent := map[string]interface{}{
- "join_rule": gomatrixserverlib.Invite, // sane default
+ "join_rule": spec.Invite, // sane default
}
_ = json.Unmarshal(oldJoinRulesEvent.Content(), &newJoinRulesContent)
newJoinRulesEvent := fledglingEvent{
- Type: gomatrixserverlib.MRoomJoinRules,
+ Type: spec.MRoomJoinRules,
StateKey: "",
Content: newJoinRulesContent,
}
@@ -464,9 +465,9 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
// For some reason Sytest expects there to be a guest access event.
// Create one if it doesn't exist.
- if _, ok := state[gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomGuestAccess, StateKey: ""}]; !ok {
+ if _, ok := state[gomatrixserverlib.StateKeyTuple{EventType: spec.MRoomGuestAccess, StateKey: ""}]; !ok {
eventsToMake = append(eventsToMake, fledglingEvent{
- Type: gomatrixserverlib.MRoomGuestAccess,
+ Type: spec.MRoomGuestAccess,
Content: map[string]string{
"guest_access": "forbidden",
},
@@ -495,14 +496,14 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
// override that now by restoring the original power levels.
if powerLevelsOverridden {
eventsToMake = append(eventsToMake, fledglingEvent{
- Type: gomatrixserverlib.MRoomPowerLevels,
+ Type: spec.MRoomPowerLevels,
Content: powerLevelContent,
})
}
return eventsToMake, nil
}
-func (r *Upgrader) sendInitialEvents(ctx context.Context, evTime time.Time, userID string, userDomain gomatrixserverlib.ServerName, newRoomID, newVersion string, eventsToMake []fledglingEvent) *api.PerformError {
+func (r *Upgrader) sendInitialEvents(ctx context.Context, evTime time.Time, userID string, userDomain spec.ServerName, newRoomID, newVersion string, eventsToMake []fledglingEvent) *api.PerformError {
var err error
var builtEvents []*gomatrixserverlib.HeaderedEvent
authEvents := gomatrixserverlib.NewAuthEvents(nil)
@@ -681,14 +682,14 @@ func createTemporaryPowerLevels(powerLevelContent *gomatrixserverlib.PowerLevelC
// Then return the temporary power levels event.
return fledglingEvent{
- Type: gomatrixserverlib.MRoomPowerLevels,
+ Type: spec.MRoomPowerLevels,
Content: tempPowerLevelContent,
}, powerLevelsOverridden
}
func (r *Upgrader) sendHeaderedEvent(
ctx context.Context,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
headeredEvent *gomatrixserverlib.HeaderedEvent,
sendAsServer string,
) *api.PerformError {
diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go
index cac8d995..2c85d3eb 100644
--- a/roomserver/internal/query/query.go
+++ b/roomserver/internal/query/query.go
@@ -22,6 +22,7 @@ import (
"fmt"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
@@ -41,7 +42,7 @@ import (
type Queryer struct {
DB storage.Database
Cache caching.RoomServerCaches
- IsLocalServerName func(gomatrixserverlib.ServerName) bool
+ IsLocalServerName func(spec.ServerName) bool
ServerACLs *acls.ServerACLs
}
@@ -305,7 +306,7 @@ func (r *Queryer) QueryMembershipAtEvent(
// a given event, overwrite any other existing membership events.
for i := range memberships {
ev := memberships[i]
- if ev.Type() == gomatrixserverlib.MRoomMember && ev.StateKeyEquals(request.UserID) {
+ if ev.Type() == spec.MRoomMember && ev.StateKeyEquals(request.UserID) {
response.Membership[eventID] = ev.Event.Headered(info.RoomVersion)
}
}
@@ -435,7 +436,7 @@ func (r *Queryer) QueryServerJoinedToRoom(
// QueryServerAllowedToSeeEvent implements api.RoomserverInternalAPI
func (r *Queryer) QueryServerAllowedToSeeEvent(
ctx context.Context,
- serverName gomatrixserverlib.ServerName,
+ serverName spec.ServerName,
eventID string,
) (allowed bool, err error) {
events, err := r.DB.EventNIDs(ctx, []string{eventID})
@@ -896,7 +897,7 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
// the flag.
res.Resident = true
// Get the join rules to work out if the join rule is "restricted".
- joinRulesEvent, err := r.DB.GetStateEvent(ctx, req.RoomID, gomatrixserverlib.MRoomJoinRules, "")
+ joinRulesEvent, err := r.DB.GetStateEvent(ctx, req.RoomID, spec.MRoomJoinRules, "")
if err != nil {
return fmt.Errorf("r.DB.GetStateEvent: %w", err)
}
@@ -908,7 +909,7 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
return fmt.Errorf("json.Unmarshal: %w", err)
}
// If the join rule isn't "restricted" then there's nothing more to do.
- res.Restricted = joinRules.JoinRule == gomatrixserverlib.Restricted
+ res.Restricted = joinRules.JoinRule == spec.Restricted
if !res.Restricted {
return nil
}
@@ -925,7 +926,7 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
// We need to get the power levels content so that we can determine which
// users in the room are entitled to issue invites. We need to use one of
// these users as the authorising user.
- powerLevelsEvent, err := r.DB.GetStateEvent(ctx, req.RoomID, gomatrixserverlib.MRoomPowerLevels, "")
+ powerLevelsEvent, err := r.DB.GetStateEvent(ctx, req.RoomID, spec.MRoomPowerLevels, "")
if err != nil {
return fmt.Errorf("r.DB.GetStateEvent: %w", err)
}
@@ -937,7 +938,7 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
for _, rule := range joinRules.Allow {
// We only understand "m.room_membership" rules at this point in
// time, so skip any rule that doesn't match those.
- if rule.Type != gomatrixserverlib.MRoomMembership {
+ if rule.Type != spec.MRoomMembership {
continue
}
// See if the room exists. If it doesn't exist or if it's a stub
@@ -984,7 +985,7 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
continue
}
event := events[0]
- if event.Type() != gomatrixserverlib.MRoomMember || event.StateKey() == nil {
+ if event.Type() != spec.MRoomMember || event.StateKey() == nil {
continue // shouldn't happen
}
// Only users that have the power to invite should be chosen.
diff --git a/roomserver/roomserver_test.go b/roomserver/roomserver_test.go
index 729da15b..67d6db46 100644
--- a/roomserver/roomserver_test.go
+++ b/roomserver/roomserver_test.go
@@ -10,6 +10,7 @@ import (
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/internal/sqlutil"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/stretchr/testify/assert"
"github.com/matrix-org/dendrite/roomserver/state"
@@ -61,10 +62,10 @@ func testSharedUsers(t *testing.T, rsAPI api.RoomserverInternalAPI) {
room := test.NewRoom(t, alice, test.RoomPreset(test.PresetTrustedPrivateChat))
// Invite and join Bob
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "invite",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
@@ -102,7 +103,7 @@ func testKickUsers(t *testing.T, rsAPI api.RoomserverInternalAPI, usrAPI userAPI
room := test.NewRoom(t, alice, test.RoomPreset(test.PresetPublicChat), test.GuestsCanJoin(true))
// Join with the guest user
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
@@ -134,7 +135,7 @@ func testKickUsers(t *testing.T, rsAPI api.RoomserverInternalAPI, usrAPI userAPI
}
// revoke guest access
- revokeEvent := room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomGuestAccess, map[string]string{"guest_access": "forbidden"}, test.WithStateKey(""))
+ revokeEvent := room.CreateAndInsert(t, alice, spec.MRoomGuestAccess, map[string]string{"guest_access": "forbidden"}, test.WithStateKey(""))
if err := api.SendEvents(ctx, rsAPI, api.KindNew, []*gomatrixserverlib.HeaderedEvent{revokeEvent}, "test", "test", "test", nil, false); err != nil {
t.Errorf("failed to send events: %v", err)
}
@@ -164,10 +165,10 @@ func Test_QueryLeftUsers(t *testing.T) {
room := test.NewRoom(t, alice, test.RoomPreset(test.PresetTrustedPrivateChat))
// Invite and join Bob
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "invite",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
@@ -216,7 +217,7 @@ func TestPurgeRoom(t *testing.T) {
room := test.NewRoom(t, alice, test.RoomPreset(test.PresetTrustedPrivateChat))
// Invite Bob
- inviteEvent := room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ inviteEvent := room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "invite",
}, test.WithStateKey(bob.ID))
@@ -443,7 +444,7 @@ func TestRedaction(t *testing.T) {
redactedEvent := room.CreateAndInsert(t, alice, "m.room.message", map[string]interface{}{"body": "hello world"})
builderEv := mustCreateEvent(t, fledglingEvent{
- Type: gomatrixserverlib.MRoomRedaction,
+ Type: spec.MRoomRedaction,
Sender: alice.ID,
RoomID: room.ID,
Redacts: redactedEvent.EventID(),
@@ -460,7 +461,7 @@ func TestRedaction(t *testing.T) {
redactedEvent := room.CreateAndInsert(t, bob, "m.room.message", map[string]interface{}{"body": "hello world"})
builderEv := mustCreateEvent(t, fledglingEvent{
- Type: gomatrixserverlib.MRoomRedaction,
+ Type: spec.MRoomRedaction,
Sender: alice.ID,
RoomID: room.ID,
Redacts: redactedEvent.EventID(),
@@ -477,7 +478,7 @@ func TestRedaction(t *testing.T) {
redactedEvent := room.CreateAndInsert(t, alice, "m.room.message", map[string]interface{}{"body": "hello world"})
builderEv := mustCreateEvent(t, fledglingEvent{
- Type: gomatrixserverlib.MRoomRedaction,
+ Type: spec.MRoomRedaction,
Sender: bob.ID,
RoomID: room.ID,
Redacts: redactedEvent.EventID(),
@@ -493,7 +494,7 @@ func TestRedaction(t *testing.T) {
redactedEvent := room.CreateAndInsert(t, bob, "m.room.message", map[string]interface{}{"body": "hello world"})
builderEv := mustCreateEvent(t, fledglingEvent{
- Type: gomatrixserverlib.MRoomRedaction,
+ Type: spec.MRoomRedaction,
Sender: charlie.ID,
RoomID: room.ID,
Redacts: redactedEvent.EventID(),
@@ -523,10 +524,10 @@ func TestRedaction(t *testing.T) {
var err error
room := test.NewRoom(t, alice, test.RoomPreset(test.PresetPublicChat))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, charlie, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, charlie, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(charlie.ID))
@@ -568,7 +569,7 @@ func TestRedaction(t *testing.T) {
if redactedEvent != nil {
assert.Equal(t, ev.Redacts(), redactedEvent.EventID())
}
- if ev.Type() == gomatrixserverlib.MRoomRedaction {
+ if ev.Type() == spec.MRoomRedaction {
nids, err := db.EventNIDs(ctx, []string{ev.Redacts()})
assert.NoError(t, err)
evs, err := db.Events(ctx, roomInfo, []types.EventNID{nids[ev.Redacts()].EventNID})
diff --git a/roomserver/storage/interface.go b/roomserver/storage/interface.go
index 5b90f8b3..b80184f9 100644
--- a/roomserver/storage/interface.go
+++ b/roomserver/storage/interface.go
@@ -18,6 +18,7 @@ import (
"context"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/roomserver/state"
"github.com/matrix-org/dendrite/roomserver/storage/shared"
@@ -162,7 +163,7 @@ type Database interface {
// GetLocalServerInRoom returns true if we think we're in a given room or false otherwise.
GetLocalServerInRoom(ctx context.Context, roomNID types.RoomNID) (bool, error)
// GetServerInRoom returns true if we think a server is in a given room or false otherwise.
- GetServerInRoom(ctx context.Context, roomNID types.RoomNID, serverName gomatrixserverlib.ServerName) (bool, error)
+ GetServerInRoom(ctx context.Context, roomNID types.RoomNID, serverName spec.ServerName) (bool, error)
// GetKnownUsers searches all users that userID knows about.
GetKnownUsers(ctx context.Context, userID, searchString string, limit int) ([]string, error)
// GetKnownRooms returns a list of all rooms we know about.
diff --git a/roomserver/storage/postgres/membership_table.go b/roomserver/storage/postgres/membership_table.go
index d774b789..835a43b2 100644
--- a/roomserver/storage/postgres/membership_table.go
+++ b/roomserver/storage/postgres/membership_table.go
@@ -21,13 +21,13 @@ import (
"fmt"
"github.com/lib/pq"
- "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver/storage/postgres/deltas"
"github.com/matrix-org/dendrite/roomserver/storage/tables"
"github.com/matrix-org/dendrite/roomserver/types"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
const membershipSchema = `
@@ -450,7 +450,7 @@ func (s *membershipStatements) SelectLocalServerInRoom(
func (s *membershipStatements) SelectServerInRoom(
ctx context.Context, txn *sql.Tx,
- roomNID types.RoomNID, serverName gomatrixserverlib.ServerName,
+ roomNID types.RoomNID, serverName spec.ServerName,
) (bool, error) {
var nid types.RoomNID
stmt := sqlutil.TxStmt(txn, s.selectServerInRoomStmt)
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index 78bda95e..17095709 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -8,6 +8,7 @@ import (
"sort"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/tidwall/gjson"
@@ -905,7 +906,7 @@ func extractRoomVersionFromCreateEvent(event *gomatrixserverlib.Event) (
var err error
var roomVersion gomatrixserverlib.RoomVersion
// Look for m.room.create events.
- if event.Type() != gomatrixserverlib.MRoomCreate {
+ if event.Type() != spec.MRoomCreate {
return gomatrixserverlib.RoomVersion(""), nil
}
roomVersion = gomatrixserverlib.RoomVersionV1
@@ -949,7 +950,7 @@ func (d *EventDatabase) MaybeRedactEvent(
)
wErr := d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
- isRedactionEvent := event.Type() == gomatrixserverlib.MRoomRedaction && event.StateKey() == nil
+ isRedactionEvent := event.Type() == spec.MRoomRedaction && event.StateKey() == nil
if isRedactionEvent {
// an event which redacts itself should be ignored
if event.EventID() == event.Redacts() {
@@ -1044,7 +1045,7 @@ func (d *EventDatabase) loadRedactionPair(
var redactionEvent, redactedEvent *types.Event
var info *tables.RedactionInfo
var err error
- isRedactionEvent := event.Type() == gomatrixserverlib.MRoomRedaction && event.StateKey() == nil
+ isRedactionEvent := event.Type() == spec.MRoomRedaction && event.StateKey() == nil
var eventBeingRedacted string
if isRedactionEvent {
@@ -1469,7 +1470,7 @@ func (d *Database) GetLocalServerInRoom(ctx context.Context, roomNID types.RoomN
}
// GetServerInRoom returns true if we think a server is in a given room or false otherwise.
-func (d *Database) GetServerInRoom(ctx context.Context, roomNID types.RoomNID, serverName gomatrixserverlib.ServerName) (bool, error) {
+func (d *Database) GetServerInRoom(ctx context.Context, roomNID types.RoomNID, serverName spec.ServerName) (bool, error) {
return d.MembershipTable.SelectServerInRoom(ctx, nil, roomNID, serverName)
}
diff --git a/roomserver/storage/sqlite3/membership_table.go b/roomserver/storage/sqlite3/membership_table.go
index 8a60b359..977788d5 100644
--- a/roomserver/storage/sqlite3/membership_table.go
+++ b/roomserver/storage/sqlite3/membership_table.go
@@ -21,13 +21,12 @@ import (
"fmt"
"strings"
- "github.com/matrix-org/gomatrixserverlib"
-
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver/storage/sqlite3/deltas"
"github.com/matrix-org/dendrite/roomserver/storage/tables"
"github.com/matrix-org/dendrite/roomserver/types"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
const membershipSchema = `
@@ -398,7 +397,7 @@ func (s *membershipStatements) SelectLocalServerInRoom(ctx context.Context, txn
return found, nil
}
-func (s *membershipStatements) SelectServerInRoom(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, serverName gomatrixserverlib.ServerName) (bool, error) {
+func (s *membershipStatements) SelectServerInRoom(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, serverName spec.ServerName) (bool, error) {
var nid types.RoomNID
stmt := sqlutil.TxStmt(txn, s.selectServerInRoomStmt)
err := stmt.QueryRowContext(ctx, tables.MembershipStateJoin, roomNID, serverName).Scan(&nid)
diff --git a/roomserver/storage/tables/interface.go b/roomserver/storage/tables/interface.go
index 4ce2a9c4..45dc0fc2 100644
--- a/roomserver/storage/tables/interface.go
+++ b/roomserver/storage/tables/interface.go
@@ -6,6 +6,7 @@ import (
"errors"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/tidwall/gjson"
"github.com/matrix-org/dendrite/roomserver/types"
@@ -147,7 +148,7 @@ type Membership interface {
SelectKnownUsers(ctx context.Context, txn *sql.Tx, userID types.EventStateKeyNID, searchString string, limit int) ([]string, error)
UpdateForgetMembership(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID, forget bool) error
SelectLocalServerInRoom(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID) (bool, error)
- SelectServerInRoom(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, serverName gomatrixserverlib.ServerName) (bool, error)
+ SelectServerInRoom(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, serverName spec.ServerName) (bool, error)
DeleteMembership(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID) error
SelectJoinedUsers(ctx context.Context, txn *sql.Tx, targetUserNIDs []types.EventStateKeyNID) ([]types.EventStateKeyNID, error)
}
@@ -199,17 +200,17 @@ func ExtractContentValue(ev *gomatrixserverlib.HeaderedEvent) string {
content := ev.Content()
key := ""
switch ev.Type() {
- case gomatrixserverlib.MRoomCreate:
+ case spec.MRoomCreate:
key = "creator"
- case gomatrixserverlib.MRoomCanonicalAlias:
+ case spec.MRoomCanonicalAlias:
key = "alias"
- case gomatrixserverlib.MRoomHistoryVisibility:
+ case spec.MRoomHistoryVisibility:
key = "history_visibility"
- case gomatrixserverlib.MRoomJoinRules:
+ case spec.MRoomJoinRules:
key = "join_rule"
- case gomatrixserverlib.MRoomMember:
+ case spec.MRoomMember:
key = "membership"
- case gomatrixserverlib.MRoomName:
+ case spec.MRoomName:
key = "name"
case "m.room.avatar":
key = "url"