From fbdcfdd25674eb73c4804be42031397e415797a9 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 22 May 2020 12:28:36 +0100 Subject: [PATCH] Use HTTP APIs when -api specified (#1057) --- cmd/dendrite-monolith-server/main.go | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index 0042a9b9c..ded0934ae 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -27,6 +27,7 @@ import ( "github.com/matrix-org/dendrite/federationsender" "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/internal/keydb" "github.com/matrix-org/dendrite/internal/transactions" "github.com/matrix-org/dendrite/keyserver" @@ -44,11 +45,23 @@ var ( httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server") certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS") keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS") - enableHTTPAPIs = flag.Bool("api", false, "Expose internal HTTP APIs in monolith mode") + enableHTTPAPIs = flag.Bool("api", false, "Use HTTP APIs instead of short-circuiting (warning: exposes API endpoints!)") ) func main() { cfg := basecomponent.ParseMonolithFlags() + if *enableHTTPAPIs { + // If the HTTP APIs are enabled then we need to update the Listen + // statements in the configuration so that we know where to find + // the API endpoints. They'll listen on the same port as the monolith + // itself. + addr := config.Address(*httpBindAddr) + cfg.Listen.RoomServer = addr + cfg.Listen.EDUServer = addr + cfg.Listen.AppServiceAPI = addr + cfg.Listen.FederationSender = addr + } + base := basecomponent.NewBaseDendrite(cfg, "Monolith", *enableHTTPAPIs) defer base.Close() // nolint: errcheck @@ -61,15 +74,30 @@ func main() { rsAPI := roomserver.SetupRoomServerComponent( base, keyRing, federation, ) + if base.EnableHTTPAPIs { + rsAPI = base.CreateHTTPRoomserverAPIs() + } + eduInputAPI := eduserver.SetupEDUServerComponent( base, cache.New(), ) + if base.EnableHTTPAPIs { + eduInputAPI = base.CreateHTTPEDUServerAPIs() + } + asAPI := appservice.SetupAppServiceAPIComponent( base, accountDB, deviceDB, federation, rsAPI, transactions.New(), ) + if base.EnableHTTPAPIs { + asAPI = base.CreateHTTPAppServiceAPIs() + } + fsAPI := federationsender.SetupFederationSenderComponent( base, federation, rsAPI, &keyRing, ) + if base.EnableHTTPAPIs { + fsAPI = base.CreateHTTPFederationSenderAPIs() + } rsAPI.SetFederationSenderAPI(fsAPI) clientapi.SetupClientAPIComponent( @@ -77,6 +105,7 @@ func main() { federation, &keyRing, rsAPI, eduInputAPI, asAPI, transactions.New(), fsAPI, ) + keyserver.SetupKeyServerComponent( base, deviceDB, accountDB, )