mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +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
11 changed files with 44 additions and 31 deletions
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -30,20 +30,22 @@ import (
|
|||
type PublicRoomsServerDatabase struct {
|
||||
db *sql.DB
|
||||
internal.PartitionOffsetStatements
|
||||
statements publicRoomsStatements
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
storage := PublicRoomsServerDatabase{
|
||||
db: db,
|
||||
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
|
||||
|
|
|
@ -32,20 +32,22 @@ import (
|
|||
type PublicRoomsServerDatabase struct {
|
||||
db *sql.DB
|
||||
internal.PartitionOffsetStatements
|
||||
statements publicRoomsStatements
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
storage := PublicRoomsServerDatabase{
|
||||
db: db,
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue