aboutsummaryrefslogtreecommitdiff
path: root/setup
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 /setup
parentec6879e5ae2919c903707475ce8d72244b2a6847 (diff)
Remove `BaseDendrite` (#3023)
Removes `BaseDendrite` to, hopefully, make testing and composing of components easier in the future.
Diffstat (limited to 'setup')
-rw-r--r--setup/base/base.go242
-rw-r--r--setup/base/base_test.go20
-rw-r--r--setup/base/sanity_other.go2
-rw-r--r--setup/base/sanity_unix.go2
-rw-r--r--setup/jetstream/nats.go4
-rw-r--r--setup/monolith.go27
-rw-r--r--setup/mscs/msc2836/msc2836.go13
-rw-r--r--setup/mscs/msc2836/msc2836_test.go15
-rw-r--r--setup/mscs/msc2946/msc2946.go18
-rw-r--r--setup/mscs/mscs.go16
10 files changed, 116 insertions, 243 deletions
diff --git a/setup/base/base.go b/setup/base/base.go
index 8c9b06d0..e5fd6fed 100644
--- a/setup/base/base.go
+++ b/setup/base/base.go
@@ -22,30 +22,24 @@ import (
"errors"
"fmt"
"html/template"
- "io"
"io/fs"
"net"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
- "sync"
"syscall"
"time"
- "github.com/getsentry/sentry-go"
sentryhttp "github.com/getsentry/sentry-go/http"
- "github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/gomatrixserverlib"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/atomic"
- "github.com/matrix-org/dendrite/internal"
- "github.com/matrix-org/dendrite/internal/httputil"
- "github.com/matrix-org/dendrite/internal/sqlutil"
-
"github.com/gorilla/mux"
"github.com/kardianos/minwinsvc"
+ "github.com/matrix-org/dendrite/internal"
+ "github.com/matrix-org/dendrite/internal/httputil"
"github.com/sirupsen/logrus"
@@ -56,154 +50,22 @@ import (
//go:embed static/*.gotmpl
var staticContent embed.FS
-// BaseDendrite is a base for creating new instances of dendrite. It parses
-// command line flags and config, and exposes methods for creating various
-// resources. All errors are handled by logging then exiting, so all methods
-// should only be used during start up.
-// Must be closed when shutting down.
-type BaseDendrite struct {
- *process.ProcessContext
- tracerCloser io.Closer
- Routers httputil.Routers
- NATS *jetstream.NATSInstance
- Cfg *config.Dendrite
- DNSCache *gomatrixserverlib.DNSCache
- ConnectionManager sqlutil.Connections
- EnableMetrics bool
- startupLock sync.Mutex
-}
-
const HTTPServerTimeout = time.Minute * 5
-type BaseDendriteOptions int
-
-const (
- DisableMetrics BaseDendriteOptions = iota
-)
-
-// NewBaseDendrite creates a new instance to be used by a component.
-func NewBaseDendrite(cfg *config.Dendrite, options ...BaseDendriteOptions) *BaseDendrite {
- platformSanityChecks()
- enableMetrics := true
- for _, opt := range options {
- switch opt {
- case DisableMetrics:
- enableMetrics = false
- }
- }
-
- 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")
- }
-
- closer, err := cfg.SetupTracing()
- if err != nil {
- logrus.WithError(err).Panicf("failed to start opentracing")
- }
-
- 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")
- }
- }
-
- var dnsCache *gomatrixserverlib.DNSCache
- if cfg.Global.DNSCache.Enabled {
- dnsCache = gomatrixserverlib.NewDNSCache(
- cfg.Global.DNSCache.CacheSize,
- cfg.Global.DNSCache.CacheLifetime,
- )
- logrus.Infof(
- "DNS cache enabled (size %d, lifetime %s)",
- cfg.Global.DNSCache.CacheSize,
- cfg.Global.DNSCache.CacheLifetime,
- )
- }
-
- // If we're in monolith mode, we'll set up a global pool of database
- // connections. A component is welcome to use this pool if they don't
- // have a separate database config of their own.
- cm := sqlutil.NewConnectionManager()
- if cfg.Global.DatabaseOptions.ConnectionString != "" {
- if cfg.Global.DatabaseOptions.ConnectionString.IsSQLite() {
- logrus.Panic("Using a global database connection pool is not supported with SQLite databases")
- }
- _, _, err := cm.Connection(&cfg.Global.DatabaseOptions)
- if err != nil {
- logrus.WithError(err).Panic("Failed to set up global database connections")
- }
- logrus.Debug("Using global database connection pool")
- }
-
- // Ideally we would only use SkipClean on routes which we know can allow '/' but due to
- // https://github.com/gorilla/mux/issues/460 we have to attach this at the top router.
- // When used in conjunction with UseEncodedPath() we get the behaviour we want when parsing
- // path parameters:
- // /foo/bar%2Fbaz == [foo, bar%2Fbaz] (from UseEncodedPath)
- // /foo/bar%2F%2Fbaz == [foo, bar%2F%2Fbaz] (from SkipClean)
- // In particular, rooms v3 event IDs are not urlsafe and can include '/' and because they
- // are randomly generated it results in flakey tests.
- // We need to be careful with media APIs if they read from a filesystem to make sure they
- // are not inadvertently reading paths without cleaning, else this could introduce a
- // directory traversal attack e.g /../../../etc/passwd
-
- return &BaseDendrite{
- ProcessContext: process.NewProcessContext(),
- tracerCloser: closer,
- Cfg: cfg,
- DNSCache: dnsCache,
- Routers: httputil.NewRouters(),
- NATS: &jetstream.NATSInstance{},
- ConnectionManager: cm,
- EnableMetrics: enableMetrics,
- }
-}
-
-// Close implements io.Closer
-func (b *BaseDendrite) Close() error {
- b.ProcessContext.ShutdownDendrite()
- b.ProcessContext.WaitForShutdown()
- return b.tracerCloser.Close()
-}
-
// CreateClient creates a new client (normally used for media fetch requests).
// Should only be called once per component.
-func (b *BaseDendrite) CreateClient() *gomatrixserverlib.Client {
- if b.Cfg.Global.DisableFederation {
+func CreateClient(cfg *config.Dendrite, dnsCache *gomatrixserverlib.DNSCache) *gomatrixserverlib.Client {
+ if cfg.Global.DisableFederation {
return gomatrixserverlib.NewClient(
gomatrixserverlib.WithTransport(noOpHTTPTransport),
)
}
opts := []gomatrixserverlib.ClientOption{
- gomatrixserverlib.WithSkipVerify(b.Cfg.FederationAPI.DisableTLSValidation),
+ gomatrixserverlib.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
gomatrixserverlib.WithWellKnownSRVLookups(true),
}
- if b.Cfg.Global.DNSCache.Enabled {
- opts = append(opts, gomatrixserverlib.WithDNSCache(b.DNSCache))
+ if cfg.Global.DNSCache.Enabled && dnsCache != nil {
+ opts = append(opts, gomatrixserverlib.WithDNSCache(dnsCache))
}
client := gomatrixserverlib.NewClient(opts...)
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
@@ -212,20 +74,20 @@ func (b *BaseDendrite) CreateClient() *gomatrixserverlib.Client {
// CreateFederationClient creates a new federation client. Should only be called
// once per component.
-func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationClient {
- identities := b.Cfg.Global.SigningIdentities()
- if b.Cfg.Global.DisableFederation {
+func CreateFederationClient(cfg *config.Dendrite, dnsCache *gomatrixserverlib.DNSCache) *gomatrixserverlib.FederationClient {
+ identities := cfg.Global.SigningIdentities()
+ if cfg.Global.DisableFederation {
return gomatrixserverlib.NewFederationClient(
identities, gomatrixserverlib.WithTransport(noOpHTTPTransport),
)
}
opts := []gomatrixserverlib.ClientOption{
gomatrixserverlib.WithTimeout(time.Minute * 5),
- gomatrixserverlib.WithSkipVerify(b.Cfg.FederationAPI.DisableTLSValidation),
- gomatrixserverlib.WithKeepAlives(!b.Cfg.FederationAPI.DisableHTTPKeepalives),
+ gomatrixserverlib.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
+ gomatrixserverlib.WithKeepAlives(!cfg.FederationAPI.DisableHTTPKeepalives),
}
- if b.Cfg.Global.DNSCache.Enabled {
- opts = append(opts, gomatrixserverlib.WithDNSCache(b.DNSCache))
+ if cfg.Global.DNSCache.Enabled {
+ opts = append(opts, gomatrixserverlib.WithDNSCache(dnsCache))
}
client := gomatrixserverlib.NewFederationClient(
identities, opts...,
@@ -234,12 +96,12 @@ func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationCli
return client
}
-func (b *BaseDendrite) ConfigureAdminEndpoints() {
- b.Routers.DendriteAdmin.HandleFunc("/monitor/up", func(w http.ResponseWriter, r *http.Request) {
+func ConfigureAdminEndpoints(processContext *process.ProcessContext, routers httputil.Routers) {
+ routers.DendriteAdmin.HandleFunc("/monitor/up", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
})
- b.Routers.DendriteAdmin.HandleFunc("/monitor/health", func(w http.ResponseWriter, r *http.Request) {
- if isDegraded, reasons := b.ProcessContext.IsDegraded(); isDegraded {
+ routers.DendriteAdmin.HandleFunc("/monitor/health", func(w http.ResponseWriter, r *http.Request) {
+ if isDegraded, reasons := processContext.IsDegraded(); isDegraded {
w.WriteHeader(503)
_ = json.NewEncoder(w).Encode(struct {
Warnings []string `json:"warnings"`
@@ -254,14 +116,13 @@ func (b *BaseDendrite) ConfigureAdminEndpoints() {
// SetupAndServeHTTP sets up the HTTP server to serve client & federation APIs
// and adds a prometheus handler under /_dendrite/metrics.
-func (b *BaseDendrite) SetupAndServeHTTP(
+func SetupAndServeHTTP(
+ processContext *process.ProcessContext,
+ cfg *config.Dendrite,
+ routers httputil.Routers,
externalHTTPAddr config.ServerAddress,
certFile, keyFile *string,
) {
- // Manually unlocked right before actually serving requests,
- // as we don't return from this method (defer doesn't work).
- b.startupLock.Lock()
-
externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
externalServ := &http.Server{
@@ -269,7 +130,7 @@ func (b *BaseDendrite) SetupAndServeHTTP(
WriteTimeout: HTTPServerTimeout,
Handler: externalRouter,
BaseContext: func(_ net.Listener) context.Context {
- return b.ProcessContext.Context()
+ return processContext.Context()
},
}
@@ -278,11 +139,11 @@ func (b *BaseDendrite) SetupAndServeHTTP(
http.Redirect(w, r, httputil.PublicStaticPath, http.StatusFound)
})
- if b.Cfg.Global.Metrics.Enabled {
- externalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), b.Cfg.Global.Metrics.BasicAuth))
+ if cfg.Global.Metrics.Enabled {
+ externalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Global.Metrics.BasicAuth))
}
- b.ConfigureAdminEndpoints()
+ ConfigureAdminEndpoints(processContext, routers)
// Parse and execute the landing page template
tmpl := template.Must(template.ParseFS(staticContent, "static/*.gotmpl"))
@@ -293,38 +154,36 @@ func (b *BaseDendrite) SetupAndServeHTTP(
logrus.WithError(err).Fatal("failed to execute landing page template")
}
- b.Routers.Static.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ routers.Static.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(landingPage.Bytes())
})
var clientHandler http.Handler
- clientHandler = b.Routers.Client
- if b.Cfg.Global.Sentry.Enabled {
+ clientHandler = routers.Client
+ if cfg.Global.Sentry.Enabled {
sentryHandler := sentryhttp.New(sentryhttp.Options{
Repanic: true,
})
- clientHandler = sentryHandler.Handle(b.Routers.Client)
+ clientHandler = sentryHandler.Handle(routers.Client)
}
var federationHandler http.Handler
- federationHandler = b.Routers.Federation
- if b.Cfg.Global.Sentry.Enabled {
+ federationHandler = routers.Federation
+ if cfg.Global.Sentry.Enabled {
sentryHandler := sentryhttp.New(sentryhttp.Options{
Repanic: true,
})
- federationHandler = sentryHandler.Handle(b.Routers.Federation)
+ federationHandler = sentryHandler.Handle(routers.Federation)
}
- externalRouter.PathPrefix(httputil.DendriteAdminPathPrefix).Handler(b.Routers.DendriteAdmin)
+ externalRouter.PathPrefix(httputil.DendriteAdminPathPrefix).Handler(routers.DendriteAdmin)
externalRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(clientHandler)
- if !b.Cfg.Global.DisableFederation {
- externalRouter.PathPrefix(httputil.PublicKeyPathPrefix).Handler(b.Routers.Keys)
+ if !cfg.Global.DisableFederation {
+ externalRouter.PathPrefix(httputil.PublicKeyPathPrefix).Handler(routers.Keys)
externalRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(federationHandler)
}
- externalRouter.PathPrefix(httputil.SynapseAdminPathPrefix).Handler(b.Routers.SynapseAdmin)
- externalRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(b.Routers.Media)
- externalRouter.PathPrefix(httputil.PublicWellKnownPrefix).Handler(b.Routers.WellKnown)
- externalRouter.PathPrefix(httputil.PublicStaticPath).Handler(b.Routers.Static)
-
- b.startupLock.Unlock()
+ externalRouter.PathPrefix(httputil.SynapseAdminPathPrefix).Handler(routers.SynapseAdmin)
+ externalRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(routers.Media)
+ externalRouter.PathPrefix(httputil.PublicWellKnownPrefix).Handler(routers.WellKnown)
+ externalRouter.PathPrefix(httputil.PublicStaticPath).Handler(routers.Static)
externalRouter.NotFoundHandler = httputil.NotFoundCORSHandler
externalRouter.MethodNotAllowedHandler = httputil.NotAllowedHandler
@@ -333,10 +192,10 @@ func (b *BaseDendrite) SetupAndServeHTTP(
go func() {
var externalShutdown atomic.Bool // RegisterOnShutdown can be called more than once
logrus.Infof("Starting external listener on %s", externalServ.Addr)
- b.ProcessContext.ComponentStarted()
+ processContext.ComponentStarted()
externalServ.RegisterOnShutdown(func() {
if externalShutdown.CompareAndSwap(false, true) {
- b.ProcessContext.ComponentFinished()
+ processContext.ComponentFinished()
logrus.Infof("Stopped external HTTP listener")
}
})
@@ -378,32 +237,27 @@ func (b *BaseDendrite) SetupAndServeHTTP(
}()
}
- minwinsvc.SetOnExit(b.ProcessContext.ShutdownDendrite)
- <-b.ProcessContext.WaitForShutdown()
+ minwinsvc.SetOnExit(processContext.ShutdownDendrite)
+ <-processContext.WaitForShutdown()
logrus.Infof("Stopping HTTP listeners")
_ = externalServ.Shutdown(context.Background())
logrus.Infof("Stopped HTTP listeners")
}
-func (b *BaseDendrite) WaitForShutdown() {
+func WaitForShutdown(processCtx *process.ProcessContext) {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
select {
case <-sigs:
- case <-b.ProcessContext.WaitForShutdown():
+ case <-processCtx.WaitForShutdown():
}
signal.Reset(syscall.SIGINT, syscall.SIGTERM)
logrus.Warnf("Shutdown signal received")
- b.ProcessContext.ShutdownDendrite()
- b.ProcessContext.WaitForComponentsToFinish()
- if b.Cfg.Global.Sentry.Enabled {
- if !sentry.Flush(time.Second * 5) {
- logrus.Warnf("failed to flush all Sentry events!")
- }
- }
+ processCtx.ShutdownDendrite()
+ processCtx.WaitForComponentsToFinish()
logrus.Warnf("Dendrite is exiting now")
}
diff --git a/setup/base/base_test.go b/setup/base/base_test.go
index aa406db2..bba967b9 100644
--- a/setup/base/base_test.go
+++ b/setup/base/base_test.go
@@ -13,8 +13,10 @@ import (
"time"
"github.com/matrix-org/dendrite/internal"
+ "github.com/matrix-org/dendrite/internal/httputil"
+ basepkg "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
- "github.com/matrix-org/dendrite/test/testrig"
+ "github.com/matrix-org/dendrite/setup/process"
"github.com/stretchr/testify/assert"
)
@@ -30,8 +32,10 @@ func TestLandingPage_Tcp(t *testing.T) {
})
assert.NoError(t, err)
- b, _, _ := testrig.Base(nil)
- defer b.Close()
+ processCtx := process.NewProcessContext()
+ routers := httputil.NewRouters()
+ cfg := config.Dendrite{}
+ cfg.Defaults(config.DefaultOpts{Generate: true, SingleDatabase: true})
// hack: create a server and close it immediately, just to get a random port assigned
s := httptest.NewServer(nil)
@@ -40,7 +44,7 @@ func TestLandingPage_Tcp(t *testing.T) {
// start base with the listener and wait for it to be started
address, err := config.HTTPAddress(s.URL)
assert.NoError(t, err)
- go b.SetupAndServeHTTP(address, nil, nil)
+ go basepkg.SetupAndServeHTTP(processCtx, &cfg, routers, address, nil, nil)
time.Sleep(time.Millisecond * 10)
// When hitting /, we should be redirected to /_matrix/static, which should contain the landing page
@@ -70,15 +74,17 @@ func TestLandingPage_UnixSocket(t *testing.T) {
})
assert.NoError(t, err)
- b, _, _ := testrig.Base(nil)
- defer b.Close()
+ processCtx := process.NewProcessContext()
+ routers := httputil.NewRouters()
+ cfg := config.Dendrite{}
+ cfg.Defaults(config.DefaultOpts{Generate: true, SingleDatabase: true})
tempDir := t.TempDir()
socket := path.Join(tempDir, "socket")
// start base with the listener and wait for it to be started
address, err := config.UnixSocketAddress(socket, "755")
assert.NoError(t, err)
- go b.SetupAndServeHTTP(address, nil, nil)
+ go basepkg.SetupAndServeHTTP(processCtx, &cfg, routers, address, nil, nil)
time.Sleep(time.Millisecond * 100)
client := &http.Client{
diff --git a/setup/base/sanity_other.go b/setup/base/sanity_other.go
index 48fe6e1f..d35c2e87 100644
--- a/setup/base/sanity_other.go
+++ b/setup/base/sanity_other.go
@@ -3,6 +3,6 @@
package base
-func platformSanityChecks() {
+func PlatformSanityChecks() {
// Nothing to do yet.
}
diff --git a/setup/base/sanity_unix.go b/setup/base/sanity_unix.go
index c630d3f1..0403df1a 100644
--- a/setup/base/sanity_unix.go
+++ b/setup/base/sanity_unix.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
)
-func platformSanityChecks() {
+func PlatformSanityChecks() {
// Dendrite needs a relatively high number of file descriptors in order
// to function properly, particularly when federating with lots of servers.
// If we run out of file descriptors, we might run into problems accessing
diff --git a/setup/jetstream/nats.go b/setup/jetstream/nats.go
index 48683789..06a58d54 100644
--- a/setup/jetstream/nats.go
+++ b/setup/jetstream/nats.go
@@ -56,7 +56,9 @@ func (s *NATSInstance) Prepare(process *process.ProcessContext, cfg *config.JetS
if err != nil {
panic(err)
}
- s.SetLogger(NewLogAdapter(), opts.Debug, opts.Trace)
+ if !cfg.NoLog {
+ s.SetLogger(NewLogAdapter(), opts.Debug, opts.Trace)
+ }
go func() {
process.ComponentStarted()
s.Start()
diff --git a/setup/monolith.go b/setup/monolith.go
index 174eba68..51e40070 100644
--- a/setup/monolith.go
+++ b/setup/monolith.go
@@ -21,13 +21,16 @@ import (
"github.com/matrix-org/dendrite/federationapi"
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
"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/internal/transactions"
"github.com/matrix-org/dendrite/mediaapi"
"github.com/matrix-org/dendrite/relayapi"
relayAPI "github.com/matrix-org/dendrite/relayapi/api"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
- "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/syncapi"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
@@ -53,23 +56,31 @@ type Monolith struct {
}
// AddAllPublicRoutes attaches all public paths to the given router
-func (m *Monolith) AddAllPublicRoutes(base *base.BaseDendrite, caches *caching.Caches) {
+func (m *Monolith) AddAllPublicRoutes(
+ processCtx *process.ProcessContext,
+ cfg *config.Dendrite,
+ routers httputil.Routers,
+ cm sqlutil.Connections,
+ natsInstance *jetstream.NATSInstance,
+ caches *caching.Caches,
+ enableMetrics bool,
+) {
userDirectoryProvider := m.ExtUserDirectoryProvider
if userDirectoryProvider == nil {
userDirectoryProvider = m.UserAPI
}
clientapi.AddPublicRoutes(
- base, m.FedClient, m.RoomserverAPI, m.AppserviceAPI, transactions.New(),
+ processCtx, routers, cfg, natsInstance, m.FedClient, m.RoomserverAPI, m.AppserviceAPI, transactions.New(),
m.FederationAPI, m.UserAPI, userDirectoryProvider,
- m.ExtPublicRoomsProvider,
+ m.ExtPublicRoomsProvider, enableMetrics,
)
federationapi.AddPublicRoutes(
- base, m.UserAPI, m.FedClient, m.KeyRing, m.RoomserverAPI, m.FederationAPI, nil,
+ processCtx, routers, cfg, natsInstance, m.UserAPI, m.FedClient, m.KeyRing, m.RoomserverAPI, m.FederationAPI, nil, enableMetrics,
)
- mediaapi.AddPublicRoutes(base, m.UserAPI, m.Client)
- syncapi.AddPublicRoutes(base, m.UserAPI, m.RoomserverAPI, caches)
+ mediaapi.AddPublicRoutes(routers.Media, cm, cfg, m.UserAPI, m.Client)
+ syncapi.AddPublicRoutes(processCtx, routers, cfg, cm, natsInstance, m.UserAPI, m.RoomserverAPI, caches, enableMetrics)
if m.RelayAPI != nil {
- relayapi.AddPublicRoutes(base, m.KeyRing, m.RelayAPI)
+ relayapi.AddPublicRoutes(routers, cfg, m.KeyRing, m.RelayAPI)
}
}
diff --git a/setup/mscs/msc2836/msc2836.go b/setup/mscs/msc2836/msc2836.go
index 7c1e0fc6..92248bc1 100644
--- a/setup/mscs/msc2836/msc2836.go
+++ b/setup/mscs/msc2836/msc2836.go
@@ -31,8 +31,9 @@ import (
fs "github.com/matrix-org/dendrite/federationapi/api"
"github.com/matrix-org/dendrite/internal/hooks"
"github.com/matrix-org/dendrite/internal/httputil"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
roomserver "github.com/matrix-org/dendrite/roomserver/api"
- "github.com/matrix-org/dendrite/setup/base"
+ "github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
@@ -99,10 +100,10 @@ func toClientResponse(res *MSC2836EventRelationshipsResponse) *EventRelationship
// Enable this MSC
func Enable(
- base *base.BaseDendrite, rsAPI roomserver.RoomserverInternalAPI, fsAPI fs.FederationInternalAPI,
+ cfg *config.Dendrite, cm sqlutil.Connections, routers httputil.Routers, rsAPI roomserver.RoomserverInternalAPI, fsAPI fs.FederationInternalAPI,
userAPI userapi.UserInternalAPI, keyRing gomatrixserverlib.JSONVerifier,
) error {
- db, err := NewDatabase(base.ConnectionManager, &base.Cfg.MSCs.Database)
+ db, err := NewDatabase(cm, &cfg.MSCs.Database)
if err != nil {
return fmt.Errorf("cannot enable MSC2836: %w", err)
}
@@ -125,14 +126,14 @@ func Enable(
}
})
- base.Routers.Client.Handle("/unstable/event_relationships",
+ routers.Client.Handle("/unstable/event_relationships",
httputil.MakeAuthAPI("eventRelationships", userAPI, eventRelationshipHandler(db, rsAPI, fsAPI)),
).Methods(http.MethodPost, http.MethodOptions)
- base.Routers.Federation.Handle("/unstable/event_relationships", httputil.MakeExternalAPI(
+ routers.Federation.Handle("/unstable/event_relationships", httputil.MakeExternalAPI(
"msc2836_event_relationships", func(req *http.Request) util.JSONResponse {
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
- req, time.Now(), base.Cfg.Global.ServerName, base.Cfg.Global.IsLocalServerName, keyRing,
+ req, time.Now(), cfg.Global.ServerName, cfg.Global.IsLocalServerName, keyRing,
)
if fedReq == nil {
return errResp
diff --git a/setup/mscs/msc2836/msc2836_test.go b/setup/mscs/msc2836/msc2836_test.go
index 24e96f93..bfcabef6 100644
--- a/setup/mscs/msc2836/msc2836_test.go
+++ b/setup/mscs/msc2836/msc2836_test.go
@@ -15,13 +15,13 @@ import (
"time"
"github.com/gorilla/mux"
+ "github.com/matrix-org/dendrite/setup/process"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/dendrite/internal/hooks"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/internal/sqlutil"
roomserver "github.com/matrix-org/dendrite/roomserver/api"
- "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/setup/mscs/msc2836"
userapi "github.com/matrix-org/dendrite/userapi/api"
@@ -555,21 +555,18 @@ func injectEvents(t *testing.T, userAPI userapi.UserInternalAPI, rsAPI roomserve
cfg.Global.ServerName = "localhost"
cfg.MSCs.Database.ConnectionString = "file:msc2836_test.db"
cfg.MSCs.MSCs = []string{"msc2836"}
- cm := sqlutil.NewConnectionManager()
- base := &base.BaseDendrite{
- Cfg: cfg,
- Routers: httputil.NewRouters(),
- ConnectionManager: cm,
- }
- err := msc2836.Enable(base, rsAPI, nil, userAPI, nil)
+ processCtx := process.NewProcessContext()
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ routers := httputil.NewRouters()
+ err := msc2836.Enable(cfg, cm, routers, rsAPI, nil, userAPI, nil)
if err != nil {
t.Fatalf("failed to enable MSC2836: %s", err)
}
for _, ev := range events {
hooks.Run(hooks.KindNewEventPersisted, ev)
}
- return base.Routers.Client
+ return routers.Client
}
type fledglingEvent struct {
diff --git a/setup/mscs/msc2946/msc2946.go b/setup/mscs/msc2946/msc2946.go
index b4b93ff3..d33897b9 100644
--- a/setup/mscs/msc2946/msc2946.go
+++ b/setup/mscs/msc2946/msc2946.go
@@ -33,7 +33,7 @@ import (
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/httputil"
roomserver "github.com/matrix-org/dendrite/roomserver/api"
- "github.com/matrix-org/dendrite/setup/base"
+ "github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
@@ -54,17 +54,17 @@ type MSC2946ClientResponse struct {
// Enable this MSC
func Enable(
- base *base.BaseDendrite, rsAPI roomserver.RoomserverInternalAPI, userAPI userapi.UserInternalAPI,
+ cfg *config.Dendrite, routers httputil.Routers, rsAPI roomserver.RoomserverInternalAPI, userAPI userapi.UserInternalAPI,
fsAPI fs.FederationInternalAPI, keyRing gomatrixserverlib.JSONVerifier, cache caching.SpaceSummaryRoomsCache,
) error {
- clientAPI := httputil.MakeAuthAPI("spaces", userAPI, spacesHandler(rsAPI, fsAPI, cache, base.Cfg.Global.ServerName), httputil.WithAllowGuests())
- base.Routers.Client.Handle("/v1/rooms/{roomID}/hierarchy", clientAPI).Methods(http.MethodGet, http.MethodOptions)
- base.Routers.Client.Handle("/unstable/org.matrix.msc2946/rooms/{roomID}/hierarchy", clientAPI).Methods(http.MethodGet, http.MethodOptions)
+ clientAPI := httputil.MakeAuthAPI("spaces", userAPI, spacesHandler(rsAPI, fsAPI, cache, cfg.Global.ServerName), httputil.WithAllowGuests())
+ routers.Client.Handle("/v1/rooms/{roomID}/hierarchy", clientAPI).Methods(http.MethodGet, http.MethodOptions)
+ routers.Client.Handle("/unstable/org.matrix.msc2946/rooms/{roomID}/hierarchy", clientAPI).Methods(http.MethodGet, http.MethodOptions)
fedAPI := httputil.MakeExternalAPI(
"msc2946_fed_spaces", func(req *http.Request) util.JSONResponse {
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
- req, time.Now(), base.Cfg.Global.ServerName, base.Cfg.Global.IsLocalServerName, keyRing,
+ req, time.Now(), cfg.Global.ServerName, cfg.Global.IsLocalServerName, keyRing,
)
if fedReq == nil {
return errResp
@@ -75,11 +75,11 @@ func Enable(
return util.ErrorResponse(err)
}
roomID := params["roomID"]
- return federatedSpacesHandler(req.Context(), fedReq, roomID, cache, rsAPI, fsAPI, base.Cfg.Global.ServerName)
+ return federatedSpacesHandler(req.Context(), fedReq, roomID, cache, rsAPI, fsAPI, cfg.Global.ServerName)
},
)
- base.Routers.Federation.Handle("/unstable/org.matrix.msc2946/hierarchy/{roomID}", fedAPI).Methods(http.MethodGet)
- base.Routers.Federation.Handle("/v1/hierarchy/{roomID}", fedAPI).Methods(http.MethodGet)
+ routers.Federation.Handle("/unstable/org.matrix.msc2946/hierarchy/{roomID}", fedAPI).Methods(http.MethodGet)
+ routers.Federation.Handle("/v1/hierarchy/{roomID}", fedAPI).Methods(http.MethodGet)
return nil
}
diff --git a/setup/mscs/mscs.go b/setup/mscs/mscs.go
index b58c800b..9cd5eed1 100644
--- a/setup/mscs/mscs.go
+++ b/setup/mscs/mscs.go
@@ -20,30 +20,32 @@ import (
"fmt"
"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/setup"
- "github.com/matrix-org/dendrite/setup/base"
+ "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/setup/mscs/msc2836"
"github.com/matrix-org/dendrite/setup/mscs/msc2946"
"github.com/matrix-org/util"
)
// Enable MSCs - returns an error on unknown MSCs
-func Enable(base *base.BaseDendrite, monolith *setup.Monolith, caches *caching.Caches) error {
- for _, msc := range base.Cfg.MSCs.MSCs {
+func Enable(cfg *config.Dendrite, cm sqlutil.Connections, routers httputil.Routers, monolith *setup.Monolith, caches *caching.Caches) error {
+ for _, msc := range cfg.MSCs.MSCs {
util.GetLogger(context.Background()).WithField("msc", msc).Info("Enabling MSC")
- if err := EnableMSC(base, monolith, msc, caches); err != nil {
+ if err := EnableMSC(cfg, cm, routers, monolith, msc, caches); err != nil {
return err
}
}
return nil
}
-func EnableMSC(base *base.BaseDendrite, monolith *setup.Monolith, msc string, caches *caching.Caches) error {
+func EnableMSC(cfg *config.Dendrite, cm sqlutil.Connections, routers httputil.Routers, monolith *setup.Monolith, msc string, caches *caching.Caches) error {
switch msc {
case "msc2836":
- return msc2836.Enable(base, monolith.RoomserverAPI, monolith.FederationAPI, monolith.UserAPI, monolith.KeyRing)
+ return msc2836.Enable(cfg, cm, routers, monolith.RoomserverAPI, monolith.FederationAPI, monolith.UserAPI, monolith.KeyRing)
case "msc2946":
- return msc2946.Enable(base, monolith.RoomserverAPI, monolith.UserAPI, monolith.FederationAPI, monolith.KeyRing, caches)
+ return msc2946.Enable(cfg, routers, monolith.RoomserverAPI, monolith.UserAPI, monolith.FederationAPI, monolith.KeyRing, caches)
case "msc2444": // enabled inside federationapi
case "msc2753": // enabled inside clientapi
default: