aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-08-31 10:41:32 +0100
committerGitHub <noreply@github.com>2022-08-31 10:41:32 +0100
commitba0b3adab4de7865afd467b61638437b1af39fce (patch)
tree4330451062846ebf6718ac3695ea61b59739cd0f /cmd
parent02ec00b1bbeb43f68a4f9b1f19ee6282e4a34194 (diff)
Pinecone standalone refactoring (#2685)
This refactors the `dendrite-demo-pinecone` executable so that it: 1. Converts the old `.key` file into a standard `.pem` file 2. Allows passing in the `--config` option to supply a normal Dendrite configuration file, so that you can configure PostgreSQL instead of SQLite, appservices and all the other usual stuff
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dendrite-demo-pinecone/main.go104
1 files changed, 68 insertions, 36 deletions
diff --git a/cmd/dendrite-demo-pinecone/main.go b/cmd/dendrite-demo-pinecone/main.go
index 75f29fe2..b16cfec6 100644
--- a/cmd/dendrite-demo-pinecone/main.go
+++ b/cmd/dendrite-demo-pinecone/main.go
@@ -24,6 +24,7 @@ import (
"net"
"net/http"
"os"
+ "strings"
"time"
"github.com/gorilla/mux"
@@ -42,6 +43,7 @@ import (
"github.com/matrix-org/dendrite/setup"
"github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/dendrite/test"
"github.com/matrix-org/dendrite/userapi"
"github.com/matrix-org/gomatrixserverlib"
@@ -70,31 +72,84 @@ func main() {
var pk ed25519.PublicKey
var sk ed25519.PrivateKey
- keyfile := *instanceName + ".key"
- if _, err := os.Stat(keyfile); os.IsNotExist(err) {
- if pk, sk, err = ed25519.GenerateKey(nil); err != nil {
- panic(err)
+ // iterate through the cli args and check if the config flag was set
+ configFlagSet := false
+ for _, arg := range os.Args {
+ if arg == "--config" || arg == "-config" {
+ configFlagSet = true
+ break
}
- if err = os.WriteFile(keyfile, sk, 0644); err != nil {
- panic(err)
+ }
+
+ cfg := &config.Dendrite{}
+
+ // use custom config if config flag is set
+ if configFlagSet {
+ cfg = setup.ParseFlags(true)
+ sk = cfg.Global.PrivateKey
+ } else {
+ keyfile := *instanceName + ".pem"
+ if _, err := os.Stat(keyfile); os.IsNotExist(err) {
+ oldkeyfile := *instanceName + ".key"
+ if _, err = os.Stat(oldkeyfile); os.IsNotExist(err) {
+ if err = test.NewMatrixKey(keyfile); err != nil {
+ panic("failed to generate a new PEM key: " + err.Error())
+ }
+ if _, sk, err = config.LoadMatrixKey(keyfile, os.ReadFile); err != nil {
+ panic("failed to load PEM key: " + err.Error())
+ }
+ } else {
+ if sk, err = os.ReadFile(oldkeyfile); err != nil {
+ panic("failed to read the old private key: " + err.Error())
+ }
+ if len(sk) != ed25519.PrivateKeySize {
+ panic("the private key is not long enough")
+ }
+ if err := test.SaveMatrixKey(keyfile, sk); err != nil {
+ panic("failed to convert the private key to PEM format: " + err.Error())
+ }
+ }
+ } else {
+ var err error
+ if _, sk, err = config.LoadMatrixKey(keyfile, os.ReadFile); err != nil {
+ panic("failed to load PEM key: " + err.Error())
+ }
}
- } else if err == nil {
- if sk, err = os.ReadFile(keyfile); err != nil {
+ cfg.Defaults(true)
+ cfg.Global.PrivateKey = sk
+ cfg.Global.JetStream.StoragePath = config.Path(fmt.Sprintf("%s/", *instanceName))
+ cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-account.db", *instanceName))
+ cfg.MediaAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-mediaapi.db", *instanceName))
+ cfg.SyncAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-syncapi.db", *instanceName))
+ cfg.RoomServer.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-roomserver.db", *instanceName))
+ cfg.KeyServer.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-keyserver.db", *instanceName))
+ cfg.FederationAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-federationapi.db", *instanceName))
+ cfg.AppServiceAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-appservice.db", *instanceName))
+ cfg.MSCs.MSCs = []string{"msc2836", "msc2946"}
+ cfg.MSCs.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-mscs.db", *instanceName))
+ cfg.ClientAPI.RegistrationDisabled = false
+ cfg.ClientAPI.OpenRegistrationWithoutVerificationEnabled = true
+ if err := cfg.Derive(); err != nil {
panic(err)
}
- if len(sk) != ed25519.PrivateKeySize {
- panic("the private key is not long enough")
- }
- pk = sk.Public().(ed25519.PublicKey)
}
+ pk = sk.Public().(ed25519.PublicKey)
+ cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk))
+ cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID)
+
+ base := base.NewBaseDendrite(cfg, "Monolith")
+ defer base.Close() // nolint: errcheck
+
pRouter := pineconeRouter.NewRouter(logrus.WithField("pinecone", "router"), sk, false)
pQUIC := pineconeSessions.NewSessions(logrus.WithField("pinecone", "sessions"), pRouter, []string{"matrix"})
pMulticast := pineconeMulticast.NewMulticast(logrus.WithField("pinecone", "multicast"), pRouter)
pManager := pineconeConnections.NewConnectionManager(pRouter, nil)
pMulticast.Start()
if instancePeer != nil && *instancePeer != "" {
- pManager.AddPeer(*instancePeer)
+ for _, peer := range strings.Split(*instancePeer, ",") {
+ pManager.AddPeer(strings.Trim(peer, " \t\r\n"))
+ }
}
go func() {
@@ -125,29 +180,6 @@ func main() {
}
}()
- cfg := &config.Dendrite{}
- cfg.Defaults(true)
- cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk))
- cfg.Global.PrivateKey = sk
- cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID)
- cfg.Global.JetStream.StoragePath = config.Path(fmt.Sprintf("%s/", *instanceName))
- cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-account.db", *instanceName))
- cfg.MediaAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-mediaapi.db", *instanceName))
- cfg.SyncAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-syncapi.db", *instanceName))
- cfg.RoomServer.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-roomserver.db", *instanceName))
- cfg.KeyServer.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-keyserver.db", *instanceName))
- cfg.FederationAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-federationapi.db", *instanceName))
- cfg.AppServiceAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-appservice.db", *instanceName))
- cfg.MSCs.MSCs = []string{"msc2836", "msc2946"}
- cfg.ClientAPI.RegistrationDisabled = false
- cfg.ClientAPI.OpenRegistrationWithoutVerificationEnabled = true
- if err := cfg.Derive(); err != nil {
- panic(err)
- }
-
- base := base.NewBaseDendrite(cfg, "Monolith")
- defer base.Close() // nolint: errcheck
-
federation := conn.CreateFederationClient(base, pQUIC)
serverKeyAPI := &signing.YggdrasilKeys{}