mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Move pubsub to demo cmd
This commit is contained in:
parent
68436952a9
commit
6b70d60287
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/appservice"
|
"github.com/matrix-org/dendrite/appservice"
|
||||||
"github.com/matrix-org/dendrite/clientapi"
|
"github.com/matrix-org/dendrite/clientapi"
|
||||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||||
|
"github.com/matrix-org/dendrite/cmd/dendrite-p2p-demo/storage"
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/common/config"
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
"github.com/matrix-org/dendrite/common/keydb"
|
"github.com/matrix-org/dendrite/common/keydb"
|
||||||
|
|
@ -38,7 +39,6 @@ import (
|
||||||
"github.com/matrix-org/dendrite/federationsender"
|
"github.com/matrix-org/dendrite/federationsender"
|
||||||
"github.com/matrix-org/dendrite/mediaapi"
|
"github.com/matrix-org/dendrite/mediaapi"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi"
|
"github.com/matrix-org/dendrite/publicroomsapi"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage"
|
|
||||||
"github.com/matrix-org/dendrite/roomserver"
|
"github.com/matrix-org/dendrite/roomserver"
|
||||||
"github.com/matrix-org/dendrite/syncapi"
|
"github.com/matrix-org/dendrite/syncapi"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ type P2PDendrite struct {
|
||||||
// The componentName is used for logging purposes, and should be a friendly name
|
// The componentName is used for logging purposes, and should be a friendly name
|
||||||
// of the component running, e.g. SyncAPI.
|
// of the component running, e.g. SyncAPI.
|
||||||
func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite {
|
func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite {
|
||||||
// baseDendrite :=
|
baseDendrite := basecomponent.NewBaseDendrite(cfg, componentName)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
privKey, err := crypto.UnmarshalEd25519PrivateKey(cfg.Matrix.PrivateKey[:])
|
privKey, err := crypto.UnmarshalEd25519PrivateKey(cfg.Matrix.PrivateKey[:])
|
||||||
|
|
@ -80,8 +81,6 @@ func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite {
|
||||||
|
|
||||||
cfg.Matrix.ServerName = gomatrixserverlib.ServerName(libp2p.ID().String())
|
cfg.Matrix.ServerName = gomatrixserverlib.ServerName(libp2p.ID().String())
|
||||||
|
|
||||||
baseDendrite := basecomponent.NewBaseDendrite(cfg, componentName)
|
|
||||||
|
|
||||||
return &P2PDendrite{
|
return &P2PDendrite{
|
||||||
Base: *baseDendrite,
|
Base: *baseDendrite,
|
||||||
LibP2P: libp2p,
|
LibP2P: libp2p,
|
||||||
|
|
|
||||||
29
cmd/dendrite-p2p-demo/storage/storage.go
Normal file
29
cmd/dendrite-p2p-demo/storage/storage.go
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
|
"github.com/matrix-org/dendrite/cmd/dendrite-p2p-demo/storage/postgreswithpubsub"
|
||||||
|
"github.com/matrix-org/dendrite/publicroomsapi/storage"
|
||||||
|
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
|
const schemePostgres = "postgres"
|
||||||
|
const schemeFile = "file"
|
||||||
|
|
||||||
|
// NewPublicRoomsServerDatabase opens a database connection.
|
||||||
|
func NewPublicRoomsServerDatabaseWithPubSub(dataSourceName string, pubsub *pubsub.PubSub) (storage.Database, error) {
|
||||||
|
uri, err := url.Parse(dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
||||||
|
}
|
||||||
|
switch uri.Scheme {
|
||||||
|
case schemePostgres:
|
||||||
|
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
||||||
|
case schemeFile:
|
||||||
|
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
|
||||||
|
default:
|
||||||
|
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,10 +20,8 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
dht "github.com/libp2p/go-libp2p-kad-dht"
|
dht "github.com/libp2p/go-libp2p-kad-dht"
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgres"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgres"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgreswithdht"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgreswithdht"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgreswithpubsub"
|
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -61,19 +59,3 @@ func NewPublicRoomsServerDatabaseWithDHT(dataSourceName string, dht *dht.IpfsDHT
|
||||||
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
|
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPublicRoomsServerDatabase opens a database connection.
|
|
||||||
func NewPublicRoomsServerDatabaseWithPubSub(dataSourceName string, pubsub *pubsub.PubSub) (Database, error) {
|
|
||||||
uri, err := url.Parse(dataSourceName)
|
|
||||||
if err != nil {
|
|
||||||
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
|
||||||
}
|
|
||||||
switch uri.Scheme {
|
|
||||||
case schemePostgres:
|
|
||||||
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
|
||||||
case schemeFile:
|
|
||||||
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
|
|
||||||
default:
|
|
||||||
return postgreswithpubsub.NewPublicRoomsServerDatabase(dataSourceName, pubsub)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue