aboutsummaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-06-19 13:29:27 +0100
committerGitHub <noreply@github.com>2020-06-19 13:29:27 +0100
commit7f26b0cd13534ba235c2bf0a7220d3462ca8e9da (patch)
tree5e7728365d7cbb7d5366b704717397639ea92ad8 /build
parent72444e4a4f31b70dfb7ddd875ef874f637699dce (diff)
Bind build support, further Yggdrasil demo updates (#1152)
* Add gobind builds for Yggdrasil demo * Massage client API a bit * Fix build * Fix gobind build * Fix gobind client API setup * Tweaks * Tweaks * Update sytest-whitelist, add comment * Default to sending push rules on initial sync
Diffstat (limited to 'build')
-rw-r--r--build/gobind/build.sh6
-rw-r--r--build/gobind/monolith.go161
-rw-r--r--build/gobind/platform_ios.go25
-rw-r--r--build/gobind/platform_other.go12
4 files changed, 204 insertions, 0 deletions
diff --git a/build/gobind/build.sh b/build/gobind/build.sh
new file mode 100644
index 00000000..3a80d374
--- /dev/null
+++ b/build/gobind/build.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+gomobile bind -v \
+ -ldflags "-X $github.com/yggdrasil-network/yggdrasil-go/src/version.buildName=riot-ios-p2p" \
+ -target ios \
+ github.com/matrix-org/dendrite/build/gobind \ No newline at end of file
diff --git a/build/gobind/monolith.go b/build/gobind/monolith.go
new file mode 100644
index 00000000..750babad
--- /dev/null
+++ b/build/gobind/monolith.go
@@ -0,0 +1,161 @@
+package gobind
+
+import (
+ "context"
+ "crypto/tls"
+ "fmt"
+ "net"
+ "net/http"
+ "time"
+
+ "github.com/matrix-org/dendrite/appservice"
+ "github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
+ "github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/yggconn"
+ "github.com/matrix-org/dendrite/eduserver"
+ "github.com/matrix-org/dendrite/eduserver/cache"
+ "github.com/matrix-org/dendrite/federationsender"
+ "github.com/matrix-org/dendrite/internal/config"
+ "github.com/matrix-org/dendrite/internal/httputil"
+ "github.com/matrix-org/dendrite/internal/setup"
+ "github.com/matrix-org/dendrite/publicroomsapi/storage"
+ "github.com/matrix-org/dendrite/roomserver"
+ "github.com/matrix-org/dendrite/userapi"
+ "github.com/matrix-org/gomatrixserverlib"
+ "github.com/sirupsen/logrus"
+)
+
+type DendriteMonolith struct {
+ StorageDirectory string
+ listener net.Listener
+}
+
+func (m *DendriteMonolith) BaseURL() string {
+ return fmt.Sprintf("http://%s", m.listener.Addr().String())
+}
+
+func (m *DendriteMonolith) Start() {
+ logger := logrus.Logger{
+ Out: BindLogger{},
+ }
+ logrus.SetOutput(BindLogger{})
+
+ var err error
+ m.listener, err = net.Listen("tcp", "localhost:65432")
+ if err != nil {
+ panic(err)
+ }
+
+ ygg, err := yggconn.Setup("dendrite", "", m.StorageDirectory)
+ if err != nil {
+ panic(err)
+ }
+
+ cfg := &config.Dendrite{}
+ cfg.SetDefaults()
+ cfg.Matrix.ServerName = gomatrixserverlib.ServerName(ygg.DerivedServerName())
+ cfg.Matrix.PrivateKey = ygg.SigningPrivateKey()
+ cfg.Matrix.KeyID = gomatrixserverlib.KeyID(signing.KeyID)
+ cfg.Kafka.UseNaffka = true
+ cfg.Kafka.Topics.OutputRoomEvent = "roomserverOutput"
+ cfg.Kafka.Topics.OutputClientData = "clientapiOutput"
+ cfg.Kafka.Topics.OutputTypingEvent = "typingServerOutput"
+ cfg.Kafka.Topics.OutputSendToDeviceEvent = "sendToDeviceOutput"
+ cfg.Database.Account = config.DataSource(fmt.Sprintf("file:%s/dendrite-account.db", m.StorageDirectory))
+ cfg.Database.Device = config.DataSource(fmt.Sprintf("file:%s/dendrite-device.db", m.StorageDirectory))
+ cfg.Database.MediaAPI = config.DataSource(fmt.Sprintf("file:%s/dendrite-mediaapi.db", m.StorageDirectory))
+ cfg.Database.SyncAPI = config.DataSource(fmt.Sprintf("file:%s/dendrite-syncapi.db", m.StorageDirectory))
+ cfg.Database.RoomServer = config.DataSource(fmt.Sprintf("file:%s/dendrite-roomserver.db", m.StorageDirectory))
+ cfg.Database.ServerKey = config.DataSource(fmt.Sprintf("file:%s/dendrite-serverkey.db", m.StorageDirectory))
+ cfg.Database.FederationSender = config.DataSource(fmt.Sprintf("file:%s/dendrite-federationsender.db", m.StorageDirectory))
+ cfg.Database.AppService = config.DataSource(fmt.Sprintf("file:%s/dendrite-appservice.db", m.StorageDirectory))
+ cfg.Database.PublicRoomsAPI = config.DataSource(fmt.Sprintf("file:%s/dendrite-publicroomsa.db", m.StorageDirectory))
+ cfg.Database.Naffka = config.DataSource(fmt.Sprintf("file:%s/dendrite-naffka.db", m.StorageDirectory))
+ if err = cfg.Derive(); err != nil {
+ panic(err)
+ }
+
+ base := setup.NewBaseDendrite(cfg, "Monolith", false)
+ defer base.Close() // nolint: errcheck
+
+ accountDB := base.CreateAccountsDB()
+ deviceDB := base.CreateDeviceDB()
+ federation := ygg.CreateFederationClient(base)
+
+ serverKeyAPI := &signing.YggdrasilKeys{}
+ keyRing := serverKeyAPI.KeyRing()
+ userAPI := userapi.NewInternalAPI(accountDB, deviceDB, cfg.Matrix.ServerName, cfg.Derived.ApplicationServices)
+
+ rsAPI := roomserver.NewInternalAPI(
+ base, keyRing, federation,
+ )
+
+ eduInputAPI := eduserver.NewInternalAPI(
+ base, cache.New(), userAPI,
+ )
+
+ asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
+
+ fsAPI := federationsender.NewInternalAPI(
+ base, federation, rsAPI, keyRing,
+ )
+
+ // The underlying roomserver implementation needs to be able to call the fedsender.
+ // This is different to rsAPI which can be the http client which doesn't need this dependency
+ rsAPI.SetFederationSenderAPI(fsAPI)
+
+ 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")
+ }
+
+ monolith := setup.Monolith{
+ Config: base.Cfg,
+ AccountDB: accountDB,
+ DeviceDB: deviceDB,
+ Client: ygg.CreateClient(base),
+ FedClient: federation,
+ KeyRing: keyRing,
+ KafkaConsumer: base.KafkaConsumer,
+ KafkaProducer: base.KafkaProducer,
+
+ AppserviceAPI: asAPI,
+ EDUInternalAPI: eduInputAPI,
+ FederationSenderAPI: fsAPI,
+ RoomserverAPI: rsAPI,
+ UserAPI: userAPI,
+ //ServerKeyAPI: serverKeyAPI,
+
+ PublicRoomsDB: publicRoomsDB,
+ }
+ monolith.AddAllPublicRoutes(base.PublicAPIMux)
+
+ httputil.SetupHTTPAPI(
+ base.BaseMux,
+ base.PublicAPIMux,
+ base.InternalAPIMux,
+ cfg,
+ base.UseHTTPAPIs,
+ )
+
+ // Build both ends of a HTTP multiplex.
+ httpServer := &http.Server{
+ Addr: ":0",
+ TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){},
+ ReadTimeout: 15 * time.Second,
+ WriteTimeout: 45 * time.Second,
+ IdleTimeout: 60 * time.Second,
+ BaseContext: func(_ net.Listener) context.Context {
+ return context.Background()
+ },
+ Handler: base.BaseMux,
+ }
+
+ go func() {
+ logger.Info("Listening on ", ygg.DerivedServerName())
+ logger.Fatal(httpServer.Serve(ygg))
+ }()
+ go func() {
+ logger.Info("Listening on ", m.BaseURL())
+ logger.Fatal(httpServer.Serve(m.listener))
+ }()
+}
diff --git a/build/gobind/platform_ios.go b/build/gobind/platform_ios.go
new file mode 100644
index 00000000..01f8a6a0
--- /dev/null
+++ b/build/gobind/platform_ios.go
@@ -0,0 +1,25 @@
+// +build ios
+
+package gobind
+
+/*
+#cgo CFLAGS: -x objective-c
+#cgo LDFLAGS: -framework Foundation
+#import <Foundation/Foundation.h>
+void Log(const char *text) {
+ NSString *nss = [NSString stringWithUTF8String:text];
+ NSLog(@"%@", nss);
+}
+*/
+import "C"
+import "unsafe"
+
+type BindLogger struct {
+}
+
+func (nsl BindLogger) Write(p []byte) (n int, err error) {
+ p = append(p, 0)
+ cstr := (*C.char)(unsafe.Pointer(&p[0]))
+ C.Log(cstr)
+ return len(p), nil
+}
diff --git a/build/gobind/platform_other.go b/build/gobind/platform_other.go
new file mode 100644
index 00000000..fdfb13bc
--- /dev/null
+++ b/build/gobind/platform_other.go
@@ -0,0 +1,12 @@
+// +build !ios
+
+package gobind
+
+import "log"
+
+type BindLogger struct{}
+
+func (nsl BindLogger) Write(p []byte) (n int, err error) {
+ log.Println(string(p))
+ return len(p), nil
+}