aboutsummaryrefslogtreecommitdiff
path: root/build/gobind-yggdrasil
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-03-22 09:21:32 +0100
committerGitHub <noreply@github.com>2023-03-22 09:21:32 +0100
commit5e85a00cb36c3d343cd5b6f6a18435989724a135 (patch)
treeb22c34dd0a6cdc04025b90086843f9084a876412 /build/gobind-yggdrasil
parentec6879e5ae2919c903707475ce8d72244b2a6847 (diff)
Remove `BaseDendrite` (#3023)
Removes `BaseDendrite` to, hopefully, make testing and composing of components easier in the future.
Diffstat (limited to 'build/gobind-yggdrasil')
-rw-r--r--build/gobind-yggdrasil/monolith.go89
1 files changed, 69 insertions, 20 deletions
diff --git a/build/gobind-yggdrasil/monolith.go b/build/gobind-yggdrasil/monolith.go
index 8faad1d0..7ce1892c 100644
--- a/build/gobind-yggdrasil/monolith.go
+++ b/build/gobind-yggdrasil/monolith.go
@@ -12,6 +12,7 @@ import (
"path/filepath"
"time"
+ "github.com/getsentry/sentry-go"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/appservice"
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
@@ -19,12 +20,15 @@ import (
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/yggrooms"
"github.com/matrix-org/dendrite/federationapi"
"github.com/matrix-org/dendrite/federationapi/api"
+ "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/httputil"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/setup"
- "github.com/matrix-org/dendrite/setup/base"
+ basepkg "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/dendrite/setup/process"
"github.com/matrix-org/dendrite/test"
"github.com/matrix-org/dendrite/userapi"
@@ -149,26 +153,71 @@ func (m *DendriteMonolith) Start() {
panic(err)
}
- base := base.NewBaseDendrite(cfg)
- base.ConfigureAdminEndpoints()
- m.processContext = base.ProcessContext
- defer base.Close() // nolint: errcheck
+ configErrors := &config.ConfigErrors{}
+ cfg.Verify(configErrors)
+ if len(*configErrors) > 0 {
+ for _, err := range *configErrors {
+ logrus.Errorf("Configuration error: %s", err)
+ }
+ logrus.Fatalf("Failed to start due to configuration errors")
+ }
+
+ internal.SetupStdLogging()
+ internal.SetupHookLogging(cfg.Logging)
+ internal.SetupPprof()
+
+ logrus.Infof("Dendrite version %s", internal.VersionString())
+
+ if !cfg.ClientAPI.RegistrationDisabled && cfg.ClientAPI.OpenRegistrationWithoutVerificationEnabled {
+ logrus.Warn("Open registration is enabled")
+ }
- federation := ygg.CreateFederationClient(base)
+ closer, err := cfg.SetupTracing()
+ if err != nil {
+ logrus.WithError(err).Panicf("failed to start opentracing")
+ }
+ defer closer.Close()
+
+ if cfg.Global.Sentry.Enabled {
+ logrus.Info("Setting up Sentry for debugging...")
+ err = sentry.Init(sentry.ClientOptions{
+ Dsn: cfg.Global.Sentry.DSN,
+ Environment: cfg.Global.Sentry.Environment,
+ Debug: true,
+ ServerName: string(cfg.Global.ServerName),
+ Release: "dendrite@" + internal.VersionString(),
+ AttachStacktrace: true,
+ })
+ if err != nil {
+ logrus.WithError(err).Panic("failed to start Sentry")
+ }
+ }
+ processCtx := process.NewProcessContext()
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ routers := httputil.NewRouters()
+ basepkg.ConfigureAdminEndpoints(processCtx, routers)
+ m.processContext = processCtx
+ defer func() {
+ processCtx.ShutdownDendrite()
+ processCtx.WaitForShutdown()
+ }() // nolint: errcheck
+
+ federation := ygg.CreateFederationClient(cfg)
serverKeyAPI := &signing.YggdrasilKeys{}
keyRing := serverKeyAPI.KeyRing()
- caches := caching.NewRistrettoCache(cfg.Global.Cache.EstimatedMaxSize, cfg.Global.Cache.MaxAge, caching.DisableMetrics)
- rsAPI := roomserver.NewInternalAPI(base, caches)
+ caches := caching.NewRistrettoCache(cfg.Global.Cache.EstimatedMaxSize, cfg.Global.Cache.MaxAge, caching.EnableMetrics)
+ natsInstance := jetstream.NATSInstance{}
+ rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.EnableMetrics)
fsAPI := federationapi.NewInternalAPI(
- base, federation, rsAPI, caches, keyRing, true,
+ processCtx, cfg, cm, &natsInstance, federation, rsAPI, caches, keyRing, true,
)
- userAPI := userapi.NewInternalAPI(base, rsAPI, federation)
+ userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, federation)
- asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
+ asAPI := appservice.NewInternalAPI(processCtx, cfg, &natsInstance, userAPI, rsAPI)
rsAPI.SetAppserviceAPI(asAPI)
// The underlying roomserver implementation needs to be able to call the fedsender.
@@ -176,8 +225,8 @@ func (m *DendriteMonolith) Start() {
rsAPI.SetFederationAPI(fsAPI, keyRing)
monolith := setup.Monolith{
- Config: base.Cfg,
- Client: ygg.CreateClient(base),
+ Config: cfg,
+ Client: ygg.CreateClient(),
FedClient: federation,
KeyRing: keyRing,
@@ -189,17 +238,17 @@ func (m *DendriteMonolith) Start() {
ygg, fsAPI, federation,
),
}
- monolith.AddAllPublicRoutes(base, caches)
+ monolith.AddAllPublicRoutes(processCtx, cfg, routers, cm, &natsInstance, caches, caching.EnableMetrics)
httpRouter := mux.NewRouter()
- httpRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(base.Routers.Client)
- httpRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.Routers.Media)
- httpRouter.PathPrefix(httputil.DendriteAdminPathPrefix).Handler(base.Routers.DendriteAdmin)
- httpRouter.PathPrefix(httputil.SynapseAdminPathPrefix).Handler(base.Routers.SynapseAdmin)
+ httpRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(routers.Client)
+ httpRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(routers.Media)
+ httpRouter.PathPrefix(httputil.DendriteAdminPathPrefix).Handler(routers.DendriteAdmin)
+ httpRouter.PathPrefix(httputil.SynapseAdminPathPrefix).Handler(routers.SynapseAdmin)
yggRouter := mux.NewRouter()
- yggRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(base.Routers.Federation)
- yggRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.Routers.Media)
+ yggRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(routers.Federation)
+ yggRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(routers.Media)
// Build both ends of a HTTP multiplex.
m.httpServer = &http.Server{