aboutsummaryrefslogtreecommitdiff
path: root/build/gobind-yggdrasil
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-09-01 17:12:27 +0100
committerNeil Alexander <neilalexander@users.noreply.github.com>2022-09-01 17:12:27 +0100
commitfea869b41fc2a9f4db70ef664442a856c095f7c7 (patch)
tree663dffc414746390ff9bb6aa9d4a4634afd5344a /build/gobind-yggdrasil
parent304acd7adc4929f64af930d0b5801e33ba101193 (diff)
Update P2P demos
Diffstat (limited to 'build/gobind-yggdrasil')
-rw-r--r--build/gobind-yggdrasil/monolith.go42
1 files changed, 39 insertions, 3 deletions
diff --git a/build/gobind-yggdrasil/monolith.go b/build/gobind-yggdrasil/monolith.go
index 896f3d14..c671ae09 100644
--- a/build/gobind-yggdrasil/monolith.go
+++ b/build/gobind-yggdrasil/monolith.go
@@ -2,10 +2,14 @@ package gobind
import (
"context"
+ "crypto/ed25519"
"crypto/tls"
+ "encoding/hex"
"fmt"
"net"
"net/http"
+ "os"
+ "path/filepath"
"time"
"github.com/gorilla/mux"
@@ -22,6 +26,7 @@ import (
"github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/setup/process"
+ "github.com/matrix-org/dendrite/test"
"github.com/matrix-org/dendrite/userapi"
"github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus"
@@ -63,19 +68,50 @@ func (m *DendriteMonolith) DisconnectMulticastPeers() {
}
func (m *DendriteMonolith) Start() {
+ var pk ed25519.PublicKey
+ var sk ed25519.PrivateKey
+
m.logger = logrus.Logger{
Out: BindLogger{},
}
m.logger.SetOutput(BindLogger{})
logrus.SetOutput(BindLogger{})
+ keyfile := filepath.Join(m.StorageDirectory, "p2p.pem")
+ if _, err := os.Stat(keyfile); os.IsNotExist(err) {
+ oldkeyfile := filepath.Join(m.StorageDirectory, "p2p.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())
+ }
+ }
+
var err error
m.listener, err = net.Listen("tcp", "localhost:65432")
if err != nil {
panic(err)
}
- ygg, err := yggconn.Setup("dendrite", m.StorageDirectory, "")
+ ygg, err := yggconn.Setup(sk, "dendrite", m.StorageDirectory, "", "")
if err != nil {
panic(err)
}
@@ -86,8 +122,8 @@ func (m *DendriteMonolith) Start() {
Generate: true,
Monolithic: true,
})
- cfg.Global.ServerName = gomatrixserverlib.ServerName(ygg.DerivedServerName())
- cfg.Global.PrivateKey = ygg.PrivateKey()
+ 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/", m.StorageDirectory))
cfg.Global.JetStream.InMemory = true