Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions eventversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ type IRoomVersion interface {
DomainlessRoomIDs() bool
PrivilegedCreators() bool
StateDAGs() bool
// returns true if this room version requires a "creator" field
// in the m.room.create event content (room versions 1–10). The field
// was removed in room version 11, where the creator is instead derived from
// the event sender.
CreatorInCreateEvent() bool
Comment thread
FrenchGithubUser marked this conversation as resolved.
// StrictEventByteLimits returns true if this room version enforces field
// length limits in bytes rather than Unicode codepoints (introduced in v11 for synapse).
StrictEventByteLimits() bool
}

type KnownRoomVersionFunc func(RoomVersion) bool
Expand Down Expand Up @@ -110,6 +118,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: disallowKnocking,
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of these should be false, if I understand it right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is false from room v11 and above

newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV1,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV1,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV1,
Expand All @@ -130,6 +139,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: disallowKnocking,
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV1,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV1,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV1,
Expand All @@ -150,6 +160,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: disallowKnocking,
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -170,6 +181,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: disallowKnocking,
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -190,6 +202,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: disallowKnocking,
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -210,6 +223,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: disallowKnocking,
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -230,6 +244,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -250,6 +265,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -270,6 +286,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -290,6 +307,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -310,6 +328,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
checkCreateEvent: checkCreateEventV2,
strictEventByteLimits: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -330,6 +349,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
checkCreateEvent: checkCreateEventV3,
strictEventByteLimits: true,
// v3 versions relax the room ID check as the room ID has no domain now.
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV3,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV3,
Expand All @@ -353,6 +373,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -373,6 +394,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: disallowRestrictedJoins,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand All @@ -392,6 +414,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
parsePowerLevelsFunc: parsePowerLevels,
checkKnockingAllowedFunc: checkKnocking,
checkCreateEvent: checkCreateEventV1,
creatorInCreateEvent: true,
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV2,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV2,
newEventFromTrustedJSONWithEventIDFunc: newEventFromTrustedJSONWithEventIDV2,
Expand Down Expand Up @@ -436,6 +459,7 @@ var roomVersionMeta = map[RoomVersion]IRoomVersion{
checkKnockingAllowedFunc: checkKnocking,
checkRestrictedJoinAllowedFunc: allowRestrictedJoins,
checkCreateEvent: checkCreateEventV3,
strictEventByteLimits: true,
// v3 versions relax the room ID check as the room ID has no domain now.
newEventFromUntrustedJSONFunc: newEventFromUntrustedJSONV3,
newEventFromTrustedJSONFunc: newEventFromTrustedJSONV3,
Expand Down Expand Up @@ -529,6 +553,13 @@ type RoomVersionImpl struct {
domainlessRoomID bool
// creators have infinite PL
privilegedCreators bool
Comment thread
FrenchGithubUser marked this conversation as resolved.
// the m.room.create content includes a "creator" field
// (room versions 1–10). This is distinct from privilegedCreators, which
// governs power-levels; this flag only controls whether the field
// must be present in the create event content.
creatorInCreateEvent bool
// field length limits are in bytes rather than Unicode codepoints
strictEventByteLimits bool
// Events form two graphs, a state DAG and an event DAG.
stateDAGs bool
checkRestrictedJoin func(ctx context.Context, localServerName spec.ServerName, roomQuerier RestrictedRoomJoinQuerier, roomID spec.RoomID, senderID spec.SenderID, privilegedCreators bool) (string, error)
Expand Down Expand Up @@ -562,6 +593,14 @@ func (v RoomVersionImpl) PrivilegedCreators() bool {
return v.privilegedCreators
}

func (v RoomVersionImpl) CreatorInCreateEvent() bool {
return v.creatorInCreateEvent
}

func (v RoomVersionImpl) StrictEventByteLimits() bool {
return v.strictEventByteLimits
}

// StateResAlgorithm returns the state resolution for the given room version.
func (v RoomVersionImpl) StateResAlgorithm() StateResAlgorithm {
return v.stateResAlgorithm
Expand Down
Loading