mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-26 05:31:32 +00:00
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.
This commit is contained in:
parent
794c63e757
commit
02b150fd13
@ -166,7 +166,7 @@ func main() {
|
|||||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||||
federationapi.SetupFederationAPIComponent(&base.Base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
federationapi.SetupFederationAPIComponent(&base.Base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
||||||
mediaapi.SetupMediaAPIComponent(&base.Base, deviceDB)
|
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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,8 @@ type PublicRoomsServerDatabase struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase creates a new public rooms server database.
|
// NewPublicRoomsServerDatabase creates a new public rooms server database.
|
||||||
func NewPublicRoomsServerDatabase(dataSourceName string, dht *dht.IpfsDHT) (*PublicRoomsServerDatabase, error) {
|
func NewPublicRoomsServerDatabase(dataSourceName string, dht *dht.IpfsDHT, localServerName gomatrixserverlib.ServerName) (*PublicRoomsServerDatabase, error) {
|
||||||
pg, err := postgres.NewPublicRoomsServerDatabase(dataSourceName, nil)
|
pg, err := postgres.NewPublicRoomsServerDatabase(dataSourceName, nil, localServerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ type PublicRoomsServerDatabase struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase creates a new public rooms server database.
|
// NewPublicRoomsServerDatabase creates a new public rooms server database.
|
||||||
func NewPublicRoomsServerDatabase(dataSourceName string, pubsub *pubsub.PubSub) (*PublicRoomsServerDatabase, error) {
|
func NewPublicRoomsServerDatabase(dataSourceName string, pubsub *pubsub.PubSub, localServerName gomatrixserverlib.ServerName) (*PublicRoomsServerDatabase, error) {
|
||||||
pg, err := postgres.NewPublicRoomsServerDatabase(dataSourceName, nil)
|
pg, err := postgres.NewPublicRoomsServerDatabase(dataSourceName, nil, localServerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -23,39 +23,40 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-libp2p/storage/postgreswithpubsub"
|
"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"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
const schemePostgres = "postgres"
|
const schemePostgres = "postgres"
|
||||||
const schemeFile = "file"
|
const schemeFile = "file"
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase opens a database connection.
|
// 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)
|
uri, err := url.Parse(dataSourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
|
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht, localServerName)
|
||||||
}
|
}
|
||||||
switch uri.Scheme {
|
switch uri.Scheme {
|
||||||
case schemePostgres:
|
case schemePostgres:
|
||||||
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
|
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht, localServerName)
|
||||||
case schemeFile:
|
case schemeFile:
|
||||||
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
|
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName, localServerName)
|
||||||
default:
|
default:
|
||||||
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
|
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht, localServerName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase opens a database connection.
|
// 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)
|
uri, err := url.Parse(dataSourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub, localServerName)
|
||||||
}
|
}
|
||||||
switch uri.Scheme {
|
switch uri.Scheme {
|
||||||
case schemePostgres:
|
case schemePostgres:
|
||||||
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub, localServerName)
|
||||||
case schemeFile:
|
case schemeFile:
|
||||||
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
|
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName, localServerName)
|
||||||
default:
|
default:
|
||||||
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub, localServerName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func main() {
|
|||||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||||
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
||||||
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func main() {
|
|||||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ func main() {
|
|||||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||||
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asQuery, fedSenderAPI, eduProducer)
|
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asQuery, fedSenderAPI, eduProducer)
|
||||||
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,13 @@ type PublicRoomsServerDatabase struct {
|
|||||||
db *sql.DB
|
db *sql.DB
|
||||||
internal.PartitionOffsetStatements
|
internal.PartitionOffsetStatements
|
||||||
statements publicRoomsStatements
|
statements publicRoomsStatements
|
||||||
|
localServerName gomatrixserverlib.ServerName
|
||||||
}
|
}
|
||||||
|
|
||||||
type attributeValue interface{}
|
type attributeValue interface{}
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase creates a new public rooms server database.
|
// 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 db *sql.DB
|
||||||
var err error
|
var err error
|
||||||
if db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil {
|
if db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil {
|
||||||
@ -44,6 +45,7 @@ func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties internal.D
|
|||||||
}
|
}
|
||||||
storage := PublicRoomsServerDatabase{
|
storage := PublicRoomsServerDatabase{
|
||||||
db: db,
|
db: db,
|
||||||
|
localServerName: localServerName,
|
||||||
}
|
}
|
||||||
if err = storage.PartitionOffsetStatements.Prepare(db, "publicroomsapi"); err != nil {
|
if err = storage.PartitionOffsetStatements.Prepare(db, "publicroomsapi"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -243,6 +245,9 @@ func (d *PublicRoomsServerDatabase) updateBooleanAttribute(
|
|||||||
func (d *PublicRoomsServerDatabase) updateRoomAliases(
|
func (d *PublicRoomsServerDatabase) updateRoomAliases(
|
||||||
ctx context.Context, aliasesEvent gomatrixserverlib.Event,
|
ctx context.Context, aliasesEvent gomatrixserverlib.Event,
|
||||||
) error {
|
) error {
|
||||||
|
if aliasesEvent.StateKey() == nil || *aliasesEvent.StateKey() != string(d.localServerName) {
|
||||||
|
return nil // only store our own aliases
|
||||||
|
}
|
||||||
var content internal.AliasesContent
|
var content internal.AliasesContent
|
||||||
if err := json.Unmarshal(aliasesEvent.Content(), &content); err != nil {
|
if err := json.Unmarshal(aliasesEvent.Content(), &content); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -33,12 +33,13 @@ type PublicRoomsServerDatabase struct {
|
|||||||
db *sql.DB
|
db *sql.DB
|
||||||
internal.PartitionOffsetStatements
|
internal.PartitionOffsetStatements
|
||||||
statements publicRoomsStatements
|
statements publicRoomsStatements
|
||||||
|
localServerName gomatrixserverlib.ServerName
|
||||||
}
|
}
|
||||||
|
|
||||||
type attributeValue interface{}
|
type attributeValue interface{}
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase creates a new public rooms server database.
|
// 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 db *sql.DB
|
||||||
var err error
|
var err error
|
||||||
if db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil {
|
if db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil {
|
||||||
@ -46,6 +47,7 @@ func NewPublicRoomsServerDatabase(dataSourceName string) (*PublicRoomsServerData
|
|||||||
}
|
}
|
||||||
storage := PublicRoomsServerDatabase{
|
storage := PublicRoomsServerDatabase{
|
||||||
db: db,
|
db: db,
|
||||||
|
localServerName: localServerName,
|
||||||
}
|
}
|
||||||
if err = storage.PartitionOffsetStatements.Prepare(db, "publicroomsapi"); err != nil {
|
if err = storage.PartitionOffsetStatements.Prepare(db, "publicroomsapi"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -245,6 +247,9 @@ func (d *PublicRoomsServerDatabase) updateBooleanAttribute(
|
|||||||
func (d *PublicRoomsServerDatabase) updateRoomAliases(
|
func (d *PublicRoomsServerDatabase) updateRoomAliases(
|
||||||
ctx context.Context, aliasesEvent gomatrixserverlib.Event,
|
ctx context.Context, aliasesEvent gomatrixserverlib.Event,
|
||||||
) error {
|
) error {
|
||||||
|
if aliasesEvent.StateKey() == nil || *aliasesEvent.StateKey() != string(d.localServerName) {
|
||||||
|
return nil // only store our own aliases
|
||||||
|
}
|
||||||
var content internal.AliasesContent
|
var content internal.AliasesContent
|
||||||
if err := json.Unmarshal(aliasesEvent.Content(), &content); err != nil {
|
if err := json.Unmarshal(aliasesEvent.Content(), &content); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -22,23 +22,24 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgres"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgres"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
const schemePostgres = "postgres"
|
const schemePostgres = "postgres"
|
||||||
const schemeFile = "file"
|
const schemeFile = "file"
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase opens a database connection.
|
// 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)
|
uri, err := url.Parse(dataSourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties)
|
return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties, localServerName)
|
||||||
}
|
}
|
||||||
switch uri.Scheme {
|
switch uri.Scheme {
|
||||||
case schemePostgres:
|
case schemePostgres:
|
||||||
return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties)
|
return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties, localServerName)
|
||||||
case schemeFile:
|
case schemeFile:
|
||||||
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
|
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName, localServerName)
|
||||||
default:
|
default:
|
||||||
return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties)
|
return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties, localServerName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,11 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase opens a database connection.
|
// 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)
|
uri, err := url.Parse(dataSourceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -31,7 +32,7 @@ func NewPublicRoomsServerDatabase(dataSourceName string) (Database, error) {
|
|||||||
case "postgres":
|
case "postgres":
|
||||||
return nil, fmt.Errorf("Cannot use postgres implementation")
|
return nil, fmt.Errorf("Cannot use postgres implementation")
|
||||||
case "file":
|
case "file":
|
||||||
return sqlite3.NewPublicRoomsServerDatabase(uri.Path)
|
return sqlite3.NewPublicRoomsServerDatabase(uri.Path, localServerName)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Cannot use postgres implementation")
|
return nil, fmt.Errorf("Cannot use postgres implementation")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user