@@ -23,7 +23,7 @@ import (
23
23
"strings"
24
24
"sync"
25
25
26
- "github.com/matrix-org/dendrite/roomserver/types "
26
+ "github.com/matrix-org/dendrite/roomserver/storage/tables "
27
27
"github.com/matrix-org/gomatrixserverlib"
28
28
"github.com/matrix-org/gomatrixserverlib/spec"
29
29
"github.com/sirupsen/logrus"
@@ -34,10 +34,10 @@ const MRoomServerACL = "m.room.server_acl"
34
34
type ServerACLDatabase interface {
35
35
// GetKnownRooms returns a list of all rooms we know about.
36
36
GetKnownRooms (ctx context.Context ) ([]string , error )
37
- // GetStateEvent returns the state event of a given type for a given room with a given state key
38
- // If no event could be found, returns nil
39
- // If there was an issue during the retrieval, returns an error
40
- GetStateEvent (ctx context.Context , roomID , evType , stateKey string ) (* types. HeaderedEvent , error )
37
+
38
+ // GetBulkStateContent returns all state events which match a given room ID and a given state key tuple. Both must be satisfied for a match.
39
+ // If a tuple has the StateKey of '*' and allowWildcards=true then all state events with the EventType should be returned.
40
+ GetBulkStateContent (ctx context.Context , roomIDs [] string , tuples []gomatrixserverlib. StateKeyTuple , allowWildcards bool ) ([]tables. StrippedEvent , error )
41
41
}
42
42
43
43
type ServerACLs struct {
@@ -58,15 +58,14 @@ func NewServerACLs(db ServerACLDatabase) *ServerACLs {
58
58
// For each room, let's see if we have a server ACL state event. If we
59
59
// do then we'll process it into memory so that we have the regexes to
60
60
// hand.
61
- for _ , room := range rooms {
62
- state , err := db .GetStateEvent (ctx , room , MRoomServerACL , "" )
63
- if err != nil {
64
- logrus .WithError (err ).Errorf ("Failed to get server ACLs for room %q" , room )
65
- continue
66
- }
67
- if state != nil {
68
- acls .OnServerACLUpdate (state .PDU )
69
- }
61
+
62
+ events , err := db .GetBulkStateContent (ctx , rooms , []gomatrixserverlib.StateKeyTuple {{EventType : MRoomServerACL , StateKey : "" }}, false )
63
+ if err != nil {
64
+ logrus .WithError (err ).Errorf ("Failed to get server ACLs for all rooms: %q" , err )
65
+ }
66
+
67
+ for _ , event := range events {
68
+ acls .OnServerACLUpdate (event )
70
69
}
71
70
return acls
72
71
}
@@ -90,9 +89,9 @@ func compileACLRegex(orig string) (*regexp.Regexp, error) {
90
89
return regexp .Compile (escaped )
91
90
}
92
91
93
- func (s * ServerACLs ) OnServerACLUpdate (state gomatrixserverlib. PDU ) {
92
+ func (s * ServerACLs ) OnServerACLUpdate (strippedEvent tables. StrippedEvent ) {
94
93
acls := & serverACL {}
95
- if err := json .Unmarshal (state . Content ( ), & acls .ServerACL ); err != nil {
94
+ if err := json .Unmarshal ([] byte ( strippedEvent . ContentValue ), & acls .ServerACL ); err != nil {
96
95
logrus .WithError (err ).Errorf ("Failed to unmarshal state content for server ACLs" )
97
96
return
98
97
}
@@ -118,10 +117,10 @@ func (s *ServerACLs) OnServerACLUpdate(state gomatrixserverlib.PDU) {
118
117
"allow_ip_literals" : acls .AllowIPLiterals ,
119
118
"num_allowed" : len (acls .allowedRegexes ),
120
119
"num_denied" : len (acls .deniedRegexes ),
121
- }).Debugf ("Updating server ACLs for %q" , state .RoomID () )
120
+ }).Debugf ("Updating server ACLs for %q" , strippedEvent .RoomID )
122
121
s .aclsMutex .Lock ()
123
122
defer s .aclsMutex .Unlock ()
124
- s .acls [state .RoomID (). String () ] = acls
123
+ s .acls [strippedEvent .RoomID ] = acls
125
124
}
126
125
127
126
func (s * ServerACLs ) IsServerBannedFromRoom (serverName spec.ServerName , roomID string ) bool {
0 commit comments