Only store our own aliases in publicroomsapi
Otherwise we just store the latest aliases submitted from a server,
which is not what we want.
MODIFY
cmd/dendrite-demo-libp2p/main.go
cmd/dendrite-demo-libp2p/main.go
@@ -166,7 +166,7 @@ func main() {
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent(&base.Base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(&base.Base, deviceDB)
- publicRoomsDB, err := storage.NewPublicRoomsServerDatabaseWithPubSub(string(base.Base.Cfg.Database.PublicRoomsAPI), base.LibP2PPubsub)
+ publicRoomsDB, err := storage.NewPublicRoomsServerDatabaseWithPubSub(string(base.Base.Cfg.Database.PublicRoomsAPI), base.LibP2PPubsub, cfg.Matrix.ServerName)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to public rooms db")
}

MODIFY
cmd/dendrite-demo-libp2p/storage/postgreswithdht/storage.go
cmd/dendrite-demo-libp2p/storage/postgreswithdht/storage.go
@@ -44,8 +44,8 @@ type PublicRoomsServerDatabase struct {
}
// NewPublicRoomsServerDatabase creates a new public rooms server database.
-func NewPublicRoomsServerDatabase(dataSourceName string, dht *dht.IpfsDHT) (*PublicRoomsServerDatabase, error) {
- pg, err := postgres.NewPublicRoomsServerDatabase(dataSourceName, nil)
+func NewPublicRoomsServerDatabase(dataSourceName string, dht *dht.IpfsDHT, localServerName gomatrixserverlib.ServerName) (*PublicRoomsServerDatabase, error) {
+ pg, err := postgres.NewPublicRoomsServerDatabase(dataSourceName, nil, localServerName)
if err != nil {
return nil, err
}

MODIFY
cmd/dendrite-demo-libp2p/storage/postgreswithpubsub/storage.go
cmd/dendrite-demo-libp2p/storage/postgreswithpubsub/storage.go
@@ -47,8 +47,8 @@ type PublicRoomsServerDatabase struct {
}
// NewPublicRoomsServerDatabase creates a new public rooms server database.
-func NewPublicRoomsServerDatabase(dataSourceName string, pubsub *pubsub.PubSub) (*PublicRoomsServerDatabase, error) {
- pg, err := postgres.NewPublicRoomsServerDatabase(dataSourceName, nil)
+func NewPublicRoomsServerDatabase(dataSourceName string, pubsub *pubsub.PubSub, localServerName gomatrixserverlib.ServerName) (*PublicRoomsServerDatabase, error) {
+ pg, err := postgres.NewPublicRoomsServerDatabase(dataSourceName, nil, localServerName)
if err != nil {
return nil, err
}

MODIFY
cmd/dendrite-demo-libp2p/storage/storage.go
cmd/dendrite-demo-libp2p/storage/storage.go
@@ -23,39 +23,40 @@ import (
"github.com/matrix-org/dendrite/cmd/dendrite-demo-libp2p/storage/postgreswithpubsub"
"github.com/matrix-org/dendrite/publicroomsapi/storage"
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
+ "github.com/matrix-org/gomatrixserverlib"
)
const schemePostgres = "postgres"
const schemeFile = "file"
// NewPublicRoomsServerDatabase opens a database connection.
-func NewPublicRoomsServerDatabaseWithDHT(dataSourceName string, dht *dht.IpfsDHT) (storage.Database, error) {
+func NewPublicRoomsServerDatabaseWithDHT(dataSourceName string, dht *dht.IpfsDHT, localServerName gomatrixserverlib.ServerName) (storage.Database, error) {
uri, err := url.Parse(dataSourceName)
if err != nil {
- return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
+ return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht, localServerName)
}
switch uri.Scheme {
case schemePostgres:
- return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
+ return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht, localServerName)
case schemeFile:
- return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
+ return sqlite3.NewPublicRoomsServerDatabase(dataSourceName, localServerName)
default:
- return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
+ return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht, localServerName)
}
}
// NewPublicRoomsServerDatabase opens a database connection.
-func NewPublicRoomsServerDatabaseWithPubSub(dataSourceName string, pubsub *pubsub.PubSub) (storage.Database, error) {
+func NewPublicRoomsServerDatabaseWithPubSub(dataSourceName string, pubsub *pubsub.PubSub, localServerName gomatrixserverlib.ServerName) (storage.Database, error) {
uri, err := url.Parse(dataSourceName)
if err != nil {
- return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
+ return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub, localServerName)
}
switch uri.Scheme {
case schemePostgres:
- return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
+ return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub, localServerName)
case schemeFile:
- return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
+ return sqlite3.NewPublicRoomsServerDatabase(dataSourceName, localServerName)
default:
- return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
+ return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub, localServerName)
}
}

MODIFY
cmd/dendrite-monolith-server/main.go
cmd/dendrite-monolith-server/main.go
@@ -120,7 +120,7 @@ func main() {
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(base, deviceDB)
- publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), base.Cfg.DbProperties())
+ publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), base.Cfg.DbProperties(), cfg.Matrix.ServerName)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to public rooms db")
}

MODIFY
cmd/dendrite-public-rooms-api-server/main.go
cmd/dendrite-public-rooms-api-server/main.go
@@ -32,7 +32,7 @@ func main() {
rsAPI := base.CreateHTTPRoomserverAPIs()
rsAPI.SetFederationSenderAPI(fsAPI)
- publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), base.Cfg.DbProperties())
+ publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), base.Cfg.DbProperties(), cfg.Matrix.ServerName)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to public rooms db")
}

MODIFY
cmd/dendritejs/main.go
cmd/dendritejs/main.go
@@ -223,7 +223,7 @@ func main() {
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asQuery, fedSenderAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(base, deviceDB)
- publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI))
+ publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), cfg.Matrix.ServerName)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to public rooms db")
}

MODIFY
publicroomsapi/storage/postgres/storage.go
publicroomsapi/storage/postgres/storage.go
@@ -31,12 +31,13 @@ type PublicRoomsServerDatabase struct {
db *sql.DB
internal.PartitionOffsetStatements
statements publicRoomsStatements
+ localServerName gomatrixserverlib.ServerName
}
type attributeValue interface{}
// NewPublicRoomsServerDatabase creates a new public rooms server database.
-func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties internal.DbProperties) (*PublicRoomsServerDatabase, error) {
+func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties internal.DbProperties, localServerName gomatrixserverlib.ServerName) (*PublicRoomsServerDatabase, error) {
var db *sql.DB
var err error
if db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil {
@@ -44,6 +45,7 @@ func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties internal.D
}
storage := PublicRoomsServerDatabase{
db: db,
+ localServerName: localServerName,
}
if err = storage.PartitionOffsetStatements.Prepare(db, "publicroomsapi"); err != nil {
return nil, err
@@ -243,6 +245,9 @@ func (d *PublicRoomsServerDatabase) updateBooleanAttribute(
func (d *PublicRoomsServerDatabase) updateRoomAliases(
ctx context.Context, aliasesEvent gomatrixserverlib.Event,
) error {
+ if aliasesEvent.StateKey() == nil || *aliasesEvent.StateKey() != string(d.localServerName) {
+ return nil // only store our own aliases
+ }
var content internal.AliasesContent
if err := json.Unmarshal(aliasesEvent.Content(), &content); err != nil {
return err

MODIFY
publicroomsapi/storage/sqlite3/storage.go
publicroomsapi/storage/sqlite3/storage.go
@@ -33,12 +33,13 @@ type PublicRoomsServerDatabase struct {
db *sql.DB
internal.PartitionOffsetStatements
statements publicRoomsStatements
+ localServerName gomatrixserverlib.ServerName
}
type attributeValue interface{}
// NewPublicRoomsServerDatabase creates a new public rooms server database.
-func NewPublicRoomsServerDatabase(dataSourceName string) (*PublicRoomsServerDatabase, error) {
+func NewPublicRoomsServerDatabase(dataSourceName string, localServerName gomatrixserverlib.ServerName) (*PublicRoomsServerDatabase, error) {
var db *sql.DB
var err error
if db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil {
@@ -46,6 +47,7 @@ func NewPublicRoomsServerDatabase(dataSourceName string) (*PublicRoomsServerData
}
storage := PublicRoomsServerDatabase{
db: db,
+ localServerName: localServerName,
}
if err = storage.PartitionOffsetStatements.Prepare(db, "publicroomsapi"); err != nil {
return nil, err
@@ -245,6 +247,9 @@ func (d *PublicRoomsServerDatabase) updateBooleanAttribute(
func (d *PublicRoomsServerDatabase) updateRoomAliases(
ctx context.Context, aliasesEvent gomatrixserverlib.Event,
) error {
+ if aliasesEvent.StateKey() == nil || *aliasesEvent.StateKey() != string(d.localServerName) {
+ return nil // only store our own aliases
+ }
var content internal.AliasesContent
if err := json.Unmarshal(aliasesEvent.Content(), &content); err != nil {
return err

MODIFY
publicroomsapi/storage/storage.go
publicroomsapi/storage/storage.go
@@ -22,23 +22,24 @@ import (
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgres"
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
+ "github.com/matrix-org/gomatrixserverlib"
)
const schemePostgres = "postgres"
const schemeFile = "file"
// NewPublicRoomsServerDatabase opens a database connection.
-func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties internal.DbProperties) (Database, error) {
+func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties internal.DbProperties, localServerName gomatrixserverlib.ServerName) (Database, error) {
uri, err := url.Parse(dataSourceName)
if err != nil {
- return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties)
+ return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties, localServerName)
}
switch uri.Scheme {
case schemePostgres:
- return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties)
+ return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties, localServerName)
case schemeFile:
- return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
+ return sqlite3.NewPublicRoomsServerDatabase(dataSourceName, localServerName)
default:
- return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties)
+ return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties, localServerName)
}
}

MODIFY
publicroomsapi/storage/storage_wasm.go
publicroomsapi/storage/storage_wasm.go
@@ -19,10 +19,11 @@ import (
"net/url"
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
+ "github.com/matrix-org/gomatrixserverlib"
)
// NewPublicRoomsServerDatabase opens a database connection.
-func NewPublicRoomsServerDatabase(dataSourceName string) (Database, error) {
+func NewPublicRoomsServerDatabase(dataSourceName string, localServerName gomatrixserverlib.ServerName) (Database, error) {
uri, err := url.Parse(dataSourceName)
if err != nil {
return nil, err
@@ -31,7 +32,7 @@ func NewPublicRoomsServerDatabase(dataSourceName string) (Database, error) {
case "postgres":
return nil, fmt.Errorf("Cannot use postgres implementation")
case "file":
- return sqlite3.NewPublicRoomsServerDatabase(uri.Path)
+ return sqlite3.NewPublicRoomsServerDatabase(uri.Path, localServerName)
default:
return nil, fmt.Errorf("Cannot use postgres implementation")
}

Only store our own aliases in publicroomsapi (#1081)

Otherwise we just store the latest aliases submitted from a server,
which is not what we want.