Split out SetupFooComponent (#1106)

* Split out adding HTTP routes from making internal APIs for clarity

* Split out more components

* Split out more things

* Finish converting

* internal mux for internal routes
This commit is contained in:
Kegsay 2020-06-08 15:51:07 +01:00 committed by GitHub
parent cdb9a11571
commit 4f171c56a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 171 additions and 138 deletions

View File

@ -21,6 +21,7 @@ import (
"sync"
"time"
"github.com/gorilla/mux"
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
"github.com/matrix-org/dendrite/appservice/consumers"
"github.com/matrix-org/dendrite/appservice/inthttp"
@ -40,15 +41,28 @@ import (
"github.com/sirupsen/logrus"
)
// SetupAppServiceAPIComponent sets up and registers HTTP handlers for the AppServices
// component.
func SetupAppServiceAPIComponent(
// AddPublicRoutes registers HTTP handlers for CS API calls
func AddPublicRoutes(router *mux.Router, cfg *config.Dendrite, rsAPI roomserverAPI.RoomserverInternalAPI,
accountsDB accounts.Database, federation *gomatrixserverlib.FederationClient, txnCache *transactions.Cache) {
routing.Setup(
router, cfg, rsAPI,
accountsDB, federation, txnCache,
)
}
// AddInternalRoutes registers HTTP handlers for internal API calls
func AddInternalRoutes(router *mux.Router, queryAPI appserviceAPI.AppServiceQueryAPI) {
inthttp.AddRoutes(queryAPI, router)
}
// NewInternalAPI returns a concerete implementation of the internal API. Callers
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
func NewInternalAPI(
base *basecomponent.BaseDendrite,
accountsDB accounts.Database,
deviceDB devices.Database,
federation *gomatrixserverlib.FederationClient,
rsAPI roomserverAPI.RoomserverInternalAPI,
transactionsCache *transactions.Cache,
) appserviceAPI.AppServiceQueryAPI {
// Create a connection to the appservice postgres DB
appserviceDB, err := storage.NewDatabase(string(base.Cfg.Database.AppService), base.Cfg.DbProperties())
@ -85,8 +99,6 @@ func SetupAppServiceAPIComponent(
Cfg: base.Cfg,
}
inthttp.AddRoutes(appserviceQueryAPI, base.InternalAPIMux)
consumer := consumers.NewOutputRoomEventConsumer(
base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB,
rsAPI, workerStates,
@ -99,13 +111,6 @@ func SetupAppServiceAPIComponent(
if err := workers.SetupTransactionWorkers(appserviceDB, workerStates); err != nil {
logrus.WithError(err).Panicf("failed to start app service transaction workers")
}
// Set up HTTP Endpoints
routing.Setup(
base.PublicAPIMux, base.Cfg, rsAPI,
accountsDB, federation, transactionsCache,
)
return appserviceQueryAPI
}

View File

@ -15,6 +15,7 @@
package clientapi
import (
"github.com/gorilla/mux"
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
@ -30,9 +31,9 @@ import (
"github.com/sirupsen/logrus"
)
// SetupClientAPIComponent sets up and registers HTTP handlers for the ClientAPI
// component.
func SetupClientAPIComponent(
// AddPublicRoutes sets up and registers HTTP handlers for the ClientAPI component.
func AddPublicRoutes(
router *mux.Router,
base *basecomponent.BaseDendrite,
deviceDB devices.Database,
accountsDB accounts.Database,
@ -65,7 +66,7 @@ func SetupClientAPIComponent(
}
routing.Setup(
base.PublicAPIMux, base.Cfg, roomserverProducer, rsAPI, asAPI,
router, base.Cfg, roomserverProducer, rsAPI, asAPI,
accountsDB, deviceDB, federation, *keyRing, userUpdateProducer,
syncProducer, eduProducer, transactionsCache, fsAPI,
)

View File

@ -31,9 +31,9 @@ func main() {
rsAPI := base.RoomserverHTTPClient()
cache := transactions.New()
appservice.SetupAppServiceAPIComponent(
base, accountDB, deviceDB, federation, rsAPI, cache,
)
intAPI := appservice.NewInternalAPI(base, accountDB, deviceDB, rsAPI)
appservice.AddInternalRoutes(base.InternalAPIMux, intAPI)
appservice.AddPublicRoutes(base.PublicAPIMux, base.Cfg, rsAPI, accountDB, federation, cache)
base.SetupAndServeHTTP(string(base.Cfg.Bind.AppServiceAPI), string(base.Cfg.Listen.AppServiceAPI))

View File

@ -38,8 +38,8 @@ func main() {
fsAPI := base.FederationSenderHTTPClient()
eduInputAPI := base.EDUServerClient()
clientapi.SetupClientAPIComponent(
base, deviceDB, accountDB, federation, keyRing,
clientapi.AddPublicRoutes(
base.PublicAPIMux, base, deviceDB, accountDB, federation, keyRing,
rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI,
)

View File

@ -136,42 +136,41 @@ func main() {
deviceDB := base.Base.CreateDeviceDB()
federation := createFederationClient(base)
serverKeyAPI := serverkeyapi.SetupServerKeyAPIComponent(
&base.Base, federation,
serverKeyAPI := serverkeyapi.NewInternalAPI(
base.Base.Cfg, federation, base.Base.Caches,
)
keyRing := serverKeyAPI.KeyRing()
createKeyDB(
base, serverKeyAPI,
)
rsAPI := roomserver.SetupRoomServerComponent(
rsAPI := roomserver.NewInternalAPI(
&base.Base, keyRing, federation,
)
eduInputAPI := eduserver.SetupEDUServerComponent(
eduInputAPI := eduserver.NewInternalAPI(
&base.Base, cache.New(), deviceDB,
)
asAPI := appservice.SetupAppServiceAPIComponent(
&base.Base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
)
fsAPI := federationsender.SetupFederationSenderComponent(
asAPI := appservice.NewInternalAPI(&base.Base, accountDB, deviceDB, rsAPI)
appservice.AddPublicRoutes(base.Base.PublicAPIMux, &cfg, rsAPI, accountDB, federation, transactions.New())
fsAPI := federationsender.NewInternalAPI(
&base.Base, federation, rsAPI, keyRing,
)
rsAPI.SetFederationSenderAPI(fsAPI)
clientapi.SetupClientAPIComponent(
&base.Base, deviceDB, accountDB,
clientapi.AddPublicRoutes(
base.Base.PublicAPIMux, &base.Base, deviceDB, accountDB,
federation, keyRing, rsAPI,
eduInputAPI, asAPI, transactions.New(), fsAPI,
)
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent(&base.Base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(&base.Base, deviceDB)
federationapi.AddPublicRoutes(base.Base.PublicAPIMux, base.Base.Cfg, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
mediaapi.AddPublicRoutes(base.Base.PublicAPIMux, base.Base.Cfg, deviceDB)
publicRoomsDB, err := storage.NewPublicRoomsServerDatabaseWithPubSub(string(base.Base.Cfg.Database.PublicRoomsAPI), base.LibP2PPubsub, cfg.Matrix.ServerName)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to public rooms db")
}
publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
publicroomsapi.AddPublicRoutes(base.Base.PublicAPIMux, &base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
syncapi.AddPublicRoutes(base.Base.PublicAPIMux, &base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
internal.SetupHTTPAPI(
http.DefaultServeMux,

View File

@ -31,7 +31,8 @@ func main() {
}()
deviceDB := base.CreateDeviceDB()
eduserver.SetupEDUServerComponent(base, cache.New(), deviceDB)
intAPI := eduserver.NewInternalAPI(base, cache.New(), deviceDB)
eduserver.AddInternalRoutes(base.InternalAPIMux, intAPI)
base.SetupAndServeHTTP(string(base.Cfg.Bind.EDUServer), string(base.Cfg.Listen.EDUServer))

View File

@ -36,8 +36,8 @@ func main() {
// TODO: this isn't a producer
eduProducer := producers.NewEDUServerProducer(base.EDUServerClient())
federationapi.SetupFederationAPIComponent(
base, accountDB, deviceDB, federation, keyRing,
federationapi.AddPublicRoutes(
base.PublicAPIMux, base.Cfg, accountDB, deviceDB, federation, keyRing,
rsAPI, asAPI, fsAPI, eduProducer,
)

View File

@ -30,9 +30,10 @@ func main() {
keyRing := serverKeyAPI.KeyRing()
rsAPI := base.RoomserverHTTPClient()
federationsender.SetupFederationSenderComponent(
fsAPI := federationsender.NewInternalAPI(
base, federation, rsAPI, keyRing,
)
federationsender.AddInternalRoutes(base.InternalAPIMux, fsAPI)
base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender), string(base.Cfg.Listen.FederationSender))

View File

@ -27,7 +27,7 @@ func main() {
accountDB := base.CreateAccountsDB()
deviceDB := base.CreateDeviceDB()
keyserver.SetupKeyServerComponent(base, deviceDB, accountDB)
keyserver.AddPublicRoutes(base.PublicAPIMux, base.Cfg, deviceDB, accountDB)
base.SetupAndServeHTTP(string(base.Cfg.Bind.KeyServer), string(base.Cfg.Listen.KeyServer))

View File

@ -26,7 +26,7 @@ func main() {
deviceDB := base.CreateDeviceDB()
mediaapi.SetupMediaAPIComponent(base, deviceDB)
mediaapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, deviceDB)
base.SetupAndServeHTTP(string(base.Cfg.Bind.MediaAPI), string(base.Cfg.Listen.MediaAPI))

View File

@ -70,62 +70,66 @@ func main() {
deviceDB := base.CreateDeviceDB()
federation := base.CreateFederationClient()
serverKeyAPI := serverkeyapi.SetupServerKeyAPIComponent(
base, federation,
serverKeyAPI := serverkeyapi.NewInternalAPI(
base.Cfg, federation, base.Caches,
)
if base.UseHTTPAPIs {
serverkeyapi.AddInternalRoutes(base.InternalAPIMux, serverKeyAPI, base.Caches)
serverKeyAPI = base.ServerKeyAPIClient()
}
keyRing := serverKeyAPI.KeyRing()
rsComponent := roomserver.SetupRoomServerComponent(
rsComponent := roomserver.NewInternalAPI(
base, keyRing, federation,
)
rsAPI := rsComponent
if base.UseHTTPAPIs {
roomserver.AddInternalRoutes(base.InternalAPIMux, rsAPI)
rsAPI = base.RoomserverHTTPClient()
}
eduInputAPI := eduserver.SetupEDUServerComponent(
eduInputAPI := eduserver.NewInternalAPI(
base, cache.New(), deviceDB,
)
if base.UseHTTPAPIs {
eduserver.AddInternalRoutes(base.InternalAPIMux, eduInputAPI)
eduInputAPI = base.EDUServerClient()
}
asAPI := appservice.SetupAppServiceAPIComponent(
base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
)
asAPI := appservice.NewInternalAPI(base, accountDB, deviceDB, rsAPI)
appservice.AddPublicRoutes(base.PublicAPIMux, cfg, rsAPI, accountDB, federation, transactions.New())
if base.UseHTTPAPIs {
appservice.AddInternalRoutes(base.InternalAPIMux, asAPI)
asAPI = base.AppserviceHTTPClient()
}
fsAPI := federationsender.SetupFederationSenderComponent(
fsAPI := federationsender.NewInternalAPI(
base, federation, rsAPI, keyRing,
)
if base.UseHTTPAPIs {
federationsender.AddInternalRoutes(base.InternalAPIMux, fsAPI)
fsAPI = base.FederationSenderHTTPClient()
}
rsComponent.SetFederationSenderAPI(fsAPI)
clientapi.SetupClientAPIComponent(
base, deviceDB, accountDB,
clientapi.AddPublicRoutes(
base.PublicAPIMux, base, deviceDB, accountDB,
federation, keyRing, rsAPI,
eduInputAPI, asAPI, transactions.New(), fsAPI,
)
keyserver.SetupKeyServerComponent(
base, deviceDB, accountDB,
keyserver.AddPublicRoutes(
base.PublicAPIMux, base.Cfg, deviceDB, accountDB,
)
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(base, deviceDB)
federationapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
mediaapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, deviceDB)
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")
}
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
publicroomsapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
syncapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, accountDB, rsAPI, federation, cfg)
internal.SetupHTTPAPI(
http.DefaultServeMux,

View File

@ -34,7 +34,7 @@ func main() {
if err != nil {
logrus.WithError(err).Panicf("failed to connect to public rooms db")
}
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, nil, nil)
publicroomsapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, publicRoomsDB, rsAPI, nil, nil)
base.SetupAndServeHTTP(string(base.Cfg.Bind.PublicRoomsAPI), string(base.Cfg.Listen.PublicRoomsAPI))

View File

@ -29,8 +29,9 @@ func main() {
keyRing := serverKeyAPI.KeyRing()
fsAPI := base.FederationSenderHTTPClient()
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
rsAPI := roomserver.NewInternalAPI(base, keyRing, federation)
rsAPI.SetFederationSenderAPI(fsAPI)
roomserver.AddInternalRoutes(base.InternalAPIMux, rsAPI)
base.SetupAndServeHTTP(string(base.Cfg.Bind.RoomServer), string(base.Cfg.Listen.RoomServer))

View File

@ -26,7 +26,8 @@ func main() {
federation := base.CreateFederationClient()
serverkeyapi.SetupServerKeyAPIComponent(base, federation)
intAPI := serverkeyapi.NewInternalAPI(base.Cfg, federation, base.Caches)
serverkeyapi.AddInternalRoutes(base.InternalAPIMux, intAPI, base.Caches)
base.SetupAndServeHTTP(string(base.Cfg.Bind.ServerKeyAPI), string(base.Cfg.Listen.ServerKeyAPI))
}

View File

@ -30,7 +30,7 @@ func main() {
rsAPI := base.RoomserverHTTPClient()
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
syncapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, accountDB, rsAPI, federation, cfg)
base.SetupAndServeHTTP(string(base.Cfg.Bind.SyncAPI), string(base.Cfg.Listen.SyncAPI))

View File

@ -206,29 +206,29 @@ func main() {
KeyDatabase: fetcher,
}
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New(), deviceDB)
asQuery := appservice.SetupAppServiceAPIComponent(
base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
rsAPI := roomserver.NewInternalAPI(base, keyRing, federation)
eduInputAPI := eduserver.NewInternalAPI(base, cache.New(), deviceDB)
asQuery := appservice.NewInternalAPI(
base, accountDB, deviceDB, rsAPI,
)
fedSenderAPI := federationsender.SetupFederationSenderComponent(base, federation, rsAPI, &keyRing)
fedSenderAPI := federationsender.NewInternalAPI(base, federation, rsAPI, &keyRing)
rsAPI.SetFederationSenderAPI(fedSenderAPI)
p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node, fedSenderAPI)
clientapi.SetupClientAPIComponent(
base, deviceDB, accountDB,
clientapi.AddPublicRoutes(
base.PublicAPIMux, base, deviceDB, accountDB,
federation, &keyRing, rsAPI,
eduInputAPI, asQuery, transactions.New(), fedSenderAPI,
)
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asQuery, fedSenderAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(base, deviceDB)
federationapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, accountDB, deviceDB, federation, &keyRing, rsAPI, asQuery, fedSenderAPI, eduProducer)
mediaapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, deviceDB)
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), cfg.Matrix.ServerName)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to public rooms db")
}
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
publicroomsapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
syncapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, accountDB, rsAPI, federation, cfg)
internal.SetupHTTPAPI(
http.DefaultServeMux,

View File

@ -17,6 +17,7 @@
package eduserver
import (
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/eduserver/api"
"github.com/matrix-org/dendrite/eduserver/cache"
@ -25,16 +26,20 @@ import (
"github.com/matrix-org/dendrite/internal/basecomponent"
)
// SetupEDUServerComponent sets up and registers HTTP handlers for the
// EDUServer component. Returns instances of the various roomserver APIs,
// allowing other components running in the same process to hit the query the
// APIs directly instead of having to use HTTP.
func SetupEDUServerComponent(
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
// on the given input API.
func AddInternalRoutes(internalMux *mux.Router, inputAPI api.EDUServerInputAPI) {
inthttp.AddRoutes(inputAPI, internalMux)
}
// NewInternalAPI returns a concerete implementation of the internal API. Callers
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
func NewInternalAPI(
base *basecomponent.BaseDendrite,
eduCache *cache.EDUCache,
deviceDB devices.Database,
) api.EDUServerInputAPI {
inputAPI := &input.EDUServerInputAPI{
return &input.EDUServerInputAPI{
Cache: eduCache,
DeviceDB: deviceDB,
Producer: base.KafkaProducer,
@ -42,8 +47,4 @@ func SetupEDUServerComponent(
OutputSendToDeviceEventTopic: string(base.Cfg.Kafka.Topics.OutputSendToDeviceEvent),
ServerName: base.Cfg.Matrix.ServerName,
}
inthttp.AddRoutes(inputAPI, base.InternalAPIMux)
return inputAPI
}

View File

@ -15,11 +15,12 @@
package federationapi
import (
"github.com/gorilla/mux"
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/basecomponent"
"github.com/matrix-org/dendrite/internal/config"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
// TODO: Are we really wanting to pull in the producer from clientapi
@ -28,10 +29,10 @@ import (
"github.com/matrix-org/gomatrixserverlib"
)
// SetupFederationAPIComponent sets up and registers HTTP handlers for the
// FederationAPI component.
func SetupFederationAPIComponent(
base *basecomponent.BaseDendrite,
// AddPublicRoutes sets up and registers HTTP handlers on the base API muxes for the FederationAPI component.
func AddPublicRoutes(
router *mux.Router,
cfg *config.Dendrite,
accountsDB accounts.Database,
deviceDB devices.Database,
federation *gomatrixserverlib.FederationClient,
@ -44,7 +45,7 @@ func SetupFederationAPIComponent(
roomserverProducer := producers.NewRoomserverProducer(rsAPI)
routing.Setup(
base.PublicAPIMux, base.Cfg, rsAPI, asAPI, roomserverProducer,
router, cfg, rsAPI, asAPI, roomserverProducer,
eduProducer, federationSenderAPI, *keyRing,
federation, accountsDB, deviceDB,
)

View File

@ -15,6 +15,7 @@
package federationsender
import (
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/federationsender/consumers"
"github.com/matrix-org/dendrite/federationsender/internal"
@ -29,9 +30,15 @@ import (
"github.com/sirupsen/logrus"
)
// SetupFederationSenderComponent sets up and registers HTTP handlers for the
// FederationSender component.
func SetupFederationSenderComponent(
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
// on the given input API.
func AddInternalRoutes(router *mux.Router, intAPI api.FederationSenderInternalAPI) {
inthttp.AddRoutes(intAPI, router)
}
// NewInternalAPI returns a concerete implementation of the internal API. Callers
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
func NewInternalAPI(
base *basecomponent.BaseDendrite,
federation *gomatrixserverlib.FederationClient,
rsAPI roomserverAPI.RoomserverInternalAPI,
@ -66,8 +73,5 @@ func SetupFederationSenderComponent(
logrus.WithError(err).Panic("failed to start typing server consumer")
}
queryAPI := internal.NewFederationSenderInternalAPI(federationSenderDB, base.Cfg, roomserverProducer, federation, keyRing, statistics, queues)
inthttp.AddRoutes(queryAPI, base.InternalAPIMux)
return queryAPI
return internal.NewFederationSenderInternalAPI(federationSenderDB, base.Cfg, roomserverProducer, federation, keyRing, statistics, queues)
}

View File

@ -15,18 +15,18 @@
package keyserver
import (
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/internal/basecomponent"
"github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/keyserver/routing"
)
// SetupFederationSenderComponent sets up and registers HTTP handlers for the
// FederationSender component.
func SetupKeyServerComponent(
base *basecomponent.BaseDendrite,
// AddPublicRoutes registers HTTP handlers for CS API calls
func AddPublicRoutes(
router *mux.Router, cfg *config.Dendrite,
deviceDB devices.Database,
accountsDB accounts.Database,
) {
routing.Setup(base.PublicAPIMux, base.Cfg, accountsDB, deviceDB)
routing.Setup(router, cfg, accountsDB, deviceDB)
}

View File

@ -15,26 +15,26 @@
package mediaapi
import (
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/internal/basecomponent"
"github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/mediaapi/routing"
"github.com/matrix-org/dendrite/mediaapi/storage"
"github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus"
)
// SetupMediaAPIComponent sets up and registers HTTP handlers for the MediaAPI
// component.
func SetupMediaAPIComponent(
base *basecomponent.BaseDendrite,
// AddPublicRoutes sets up and registers HTTP handlers for the MediaAPI component.
func AddPublicRoutes(
router *mux.Router, cfg *config.Dendrite,
deviceDB devices.Database,
) {
mediaDB, err := storage.Open(string(base.Cfg.Database.MediaAPI), base.Cfg.DbProperties())
mediaDB, err := storage.Open(string(cfg.Database.MediaAPI), cfg.DbProperties())
if err != nil {
logrus.WithError(err).Panicf("failed to connect to media db")
}
routing.Setup(
base.PublicAPIMux, base.Cfg, mediaDB, deviceDB, gomatrixserverlib.NewClient(),
router, cfg, mediaDB, deviceDB, gomatrixserverlib.NewClient(),
)
}

View File

@ -15,6 +15,7 @@
package publicroomsapi
import (
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/internal/basecomponent"
"github.com/matrix-org/dendrite/publicroomsapi/consumers"
@ -26,9 +27,10 @@ import (
"github.com/sirupsen/logrus"
)
// SetupPublicRoomsAPIComponent sets up and registers HTTP handlers for the PublicRoomsAPI
// AddPublicRoutes sets up and registers HTTP handlers for the PublicRoomsAPI
// component.
func SetupPublicRoomsAPIComponent(
func AddPublicRoutes(
router *mux.Router,
base *basecomponent.BaseDendrite,
deviceDB devices.Database,
publicRoomsDB storage.Database,
@ -43,5 +45,5 @@ func SetupPublicRoomsAPIComponent(
logrus.WithError(err).Panic("failed to start public rooms server consumer")
}
routing.Setup(base.PublicAPIMux, deviceDB, publicRoomsDB, rsAPI, fedClient, extRoomsProvider)
routing.Setup(router, deviceDB, publicRoomsDB, rsAPI, fedClient, extRoomsProvider)
}

View File

@ -15,6 +15,7 @@
package roomserver
import (
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/inthttp"
"github.com/matrix-org/gomatrixserverlib"
@ -25,11 +26,15 @@ import (
"github.com/sirupsen/logrus"
)
// SetupRoomServerComponent sets up and registers HTTP handlers for the
// RoomServer component. Returns instances of the various roomserver APIs,
// allowing other components running in the same process to hit the query the
// APIs directly instead of having to use HTTP.
func SetupRoomServerComponent(
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
// on the given input API.
func AddInternalRoutes(router *mux.Router, intAPI api.RoomserverInternalAPI) {
inthttp.AddRoutes(intAPI, router)
}
// NewInternalAPI returns a concerete implementation of the internal API. Callers
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
func NewInternalAPI(
base *basecomponent.BaseDendrite,
keyRing gomatrixserverlib.JSONVerifier,
fedClient *gomatrixserverlib.FederationClient,
@ -39,7 +44,7 @@ func SetupRoomServerComponent(
logrus.WithError(err).Panicf("failed to connect to room server db")
}
internalAPI := &internal.RoomserverInternalAPI{
return &internal.RoomserverInternalAPI{
DB: roomserverDB,
Cfg: base.Cfg,
Producer: base.KafkaProducer,
@ -49,8 +54,4 @@ func SetupRoomServerComponent(
FedClient: fedClient,
KeyRing: keyRing,
}
inthttp.AddRoutes(internalAPI, base.InternalAPIMux)
return internalAPI
}

View File

@ -4,7 +4,9 @@ import (
"crypto/ed25519"
"encoding/base64"
"github.com/matrix-org/dendrite/internal/basecomponent"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/serverkeyapi/api"
"github.com/matrix-org/dendrite/serverkeyapi/internal"
"github.com/matrix-org/dendrite/serverkeyapi/inthttp"
@ -14,22 +16,31 @@ import (
"github.com/sirupsen/logrus"
)
func SetupServerKeyAPIComponent(
base *basecomponent.BaseDendrite,
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
// on the given input API.
func AddInternalRoutes(router *mux.Router, intAPI api.ServerKeyInternalAPI, caches *caching.Caches) {
inthttp.AddRoutes(intAPI, router, caches)
}
// NewInternalAPI returns a concerete implementation of the internal API. Callers
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
func NewInternalAPI(
cfg *config.Dendrite,
fedClient *gomatrixserverlib.FederationClient,
caches *caching.Caches,
) api.ServerKeyInternalAPI {
innerDB, err := storage.NewDatabase(
string(base.Cfg.Database.ServerKey),
base.Cfg.DbProperties(),
base.Cfg.Matrix.ServerName,
base.Cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey),
base.Cfg.Matrix.KeyID,
string(cfg.Database.ServerKey),
cfg.DbProperties(),
cfg.Matrix.ServerName,
cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey),
cfg.Matrix.KeyID,
)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to server key database")
}
serverKeyDB, err := cache.NewKeyDatabase(innerDB, base.Caches)
serverKeyDB, err := cache.NewKeyDatabase(innerDB, caches)
if err != nil {
logrus.WithError(err).Panicf("failed to set up caching wrapper for server key database")
}
@ -47,7 +58,7 @@ func SetupServerKeyAPIComponent(
}
var b64e = base64.StdEncoding.WithPadding(base64.NoPadding)
for _, ps := range base.Cfg.Matrix.KeyPerspectives {
for _, ps := range cfg.Matrix.KeyPerspectives {
perspective := &gomatrixserverlib.PerspectiveKeyFetcher{
PerspectiveServerName: ps.ServerName,
PerspectiveServerKeys: map[gomatrixserverlib.KeyID]ed25519.PublicKey{},
@ -77,7 +88,5 @@ func SetupServerKeyAPIComponent(
}).Info("Enabled perspective key fetcher")
}
inthttp.AddRoutes(&internalAPI, base.InternalAPIMux, base.Caches)
return &internalAPI
}

View File

@ -17,6 +17,7 @@ package syncapi
import (
"context"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
@ -32,9 +33,10 @@ import (
"github.com/matrix-org/dendrite/syncapi/sync"
)
// SetupSyncAPIComponent sets up and registers HTTP handlers for the SyncAPI
// AddPublicRoutes sets up and registers HTTP handlers for the SyncAPI
// component.
func SetupSyncAPIComponent(
func AddPublicRoutes(
router *mux.Router,
base *basecomponent.BaseDendrite,
deviceDB devices.Database,
accountsDB accounts.Database,
@ -88,5 +90,5 @@ func SetupSyncAPIComponent(
logrus.WithError(err).Panicf("failed to start send-to-device consumer")
}
routing.Setup(base.PublicAPIMux, requestPool, syncDB, deviceDB, federation, rsAPI, cfg)
routing.Setup(router, requestPool, syncDB, deviceDB, federation, rsAPI, cfg)
}